Beispiel #1
0
        public override string ToXml(int storeType)
        {
            if (TypeName == null || TypeName.Equals(""))
            {
                return("");
            }

            StringBuilder str = new StringBuilder(String.Format("<{0}>", TypeName));

            try
            {
                if (IsExist("Name"))
                {
                    str.Append(String.Format("<Name>{0}</Name>", Name));
                }

                str.Append(mProperty.ToXml("Name"));

                str.Append(GetExtXmlData());
            }
            finally
            {
                str.Append(String.Format("</{0}>", TypeName));
            }

            return(str.ToString());
        }
Beispiel #2
0
 public bool Equals(ItemType other)
 {
     return(TypeValuesEqual(TypeValues, other?.TypeValues) &&
            TypeHeader.Equals(other?.TypeHeader) &&
            TypeName.Equals(other?.TypeName) &&
            SelectedItem.Equals(other?.SelectedItem));
 }
Beispiel #3
0
        /// <include file='doc\ToolboxItem.uex' path='docs/doc[@for="ToolboxItem.Equals"]/*' />
        /// <internalonly/>
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }

            if (obj == null)
            {
                return(false);
            }

            if (!(obj.GetType() == this.GetType()))
            {
                return(false);
            }

            ToolboxItem otherItem = (ToolboxItem)obj;

            if (TypeName != otherItem.TypeName)
            {
                if (TypeName == null || otherItem.TypeName == null)
                {
                    return(false);
                }

                if (!TypeName.Equals(otherItem.TypeName))
                {
                    return(false);
                }
            }

            if (AssemblyName != otherItem.AssemblyName)
            {
                if (AssemblyName == null || otherItem.AssemblyName == null)
                {
                    return(false);
                }

                if (!AssemblyName.FullName.Equals(otherItem.AssemblyName.FullName))
                {
                    return(false);
                }
            }

            if (DisplayName != otherItem.DisplayName)
            {
                if (DisplayName == null || otherItem.DisplayName == null)
                {
                    return(false);
                }

                if (!DisplayName.Equals(otherItem.DisplayName))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #4
0
        public override string ToXml(int storeType)
        {
            if (TypeName == null || TypeName.Equals(""))
            {
                return("");
            }

            lock (mConfigs.SyncRoot)
            {
                StringBuilder str = new StringBuilder("<" + TypeName + ">");
                try
                {
                    foreach (IConfig config in mConfigs.Values)
                    {
                        if (config.StoreType <= storeType)
                        {
                            str.Append(config.ToXml());
                        }
                    }
                }
                finally
                {
                    str.Append("</" + TypeName + ">");
                }
                return(str.ToString());
            }
        }
        /// <inheritdoc />
        public bool MatchesType(Type type, string typeName)
        {
            var typeToMatch = new TypeName(type.AssemblyQualifiedName.Split(','));
            var typeToCheck = new TypeName(typeName.Split(','));

            return(typeToCheck.Equals(typeToMatch));
        }
Beispiel #6
0
        /// <summary>
        /// Returns true if EquipmentAttachment instances are equal
        /// </summary>
        /// <param name="other">Instance of EquipmentAttachment to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(EquipmentAttachment other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||
                     Id.Equals(other.Id)
                     ) &&
                 (
                     Equipment == other.Equipment ||
                     Equipment != null &&
                     Equipment.Equals(other.Equipment)
                 ) &&
                 (
                     TypeName == other.TypeName ||
                     TypeName != null &&
                     TypeName.Equals(other.TypeName)
                 ) &&
                 (
                     Description == other.Description ||
                     Description != null &&
                     Description.Equals(other.Description)
                 ));
        }
Beispiel #7
0
 public override bool Equals(object obj)
 {
     if (obj as TypeReferenceDefinition == null)
     {
         return(false);
     }
     return(TypeName.Equals((obj as TypeReferenceDefinition).TypeName) && Reference.Equals((obj as TypeReferenceDefinition).Reference));
 }
Beispiel #8
0
        public bool Equals(CacheTokenPair other)
        {
            if (other != null && ReferenceEquals(this, other))
            {
                return(true);
            }

            return(TypeName.Equals(other.TypeName, StringComparison.Ordinal) && Codename.Equals(other.Codename, StringComparison.Ordinal));
        }
Beispiel #9
0
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            return(obj is ViewModelOid oid && TypeName.Equals(oid.TypeName) && Keys.SequenceEqual(oid.Keys));
        }
Beispiel #10
0
        public static void ImplementsInequalityCorrectly(string leftTypeName, string rightTypeName)
        {
            var left  = new TypeName(leftTypeName);
            var right = new TypeName(rightTypeName);

            Assert.NotEqual(left, right);
            Assert.False(left.Equals(right));
            Assert.False(left == right);
            Assert.True(left != right);
        }
Beispiel #11
0
        public bool Equals(WebhookSubjectModel other)
        {
            if (other != null && ReferenceEquals(this, other))
            {
                return(true);
            }

            return(Operation.Equals(other.Operation, StringComparison.Ordinal) &&
                   TypeName.Equals(other.TypeName, StringComparison.Ordinal) &&
                   Codename.Equals(other.Codename, StringComparison.Ordinal));
        }
        public bool MatchesType(Type type, string? typeName)
        {
            if (typeName == null)
                return false;

            var typeAssemblyQualifiedName = type.AssemblyQualifiedName ?? string.Empty;
            var typeToMatch = new TypeName(typeAssemblyQualifiedName.Split(','));
            var typeToCheck = new TypeName(typeName.Split(','));

            return typeToCheck.Equals(typeToMatch);
        }
        /// <summary>
        /// Try and open the directory entry and return an actual NtObject handle.
        /// </summary>
        /// <param name="throw_on_error">True to throw on error.</param>
        /// <returns>The object opened.</returns>
        /// <exception cref="System.ArgumentException">Thrown if invalid typename.</exception>
        public virtual NtResult <NtObject> ToObject(bool throw_on_error)
        {
            AttributeFlags flags = AttributeFlags.CaseInsensitive;

            if (TypeName.Equals("key", StringComparison.OrdinalIgnoreCase))
            {
                flags |= AttributeFlags.OpenLink;
            }
            return(NtObject.OpenWithType(TypeName, RelativePath, _root,
                                         flags, GenericAccessRights.MaximumAllowed, null, throw_on_error));
        }
Beispiel #14
0
 public override bool Equals(object obj)
 {
     if (obj is UaTypeMetadata typeMetadata)
     {
         return(TypeName.Equals(typeMetadata.TypeName) &&
                RepositoryGroupName.Equals(typeMetadata.RepositoryGroupName));
     }
     else
     {
         return(false);
     }
 }
Beispiel #15
0
        public override bool Equals(object other)
        {
            bool result = false;

            if (other is FieldInfo)
            {
                FieldInfo info = other as FieldInfo;
                result  = Name.Equals(info.Name);
                result &= TypeName.Equals(info.TypeName);
            }
            return(result);
        }
        public override bool Equals(object obj)
        {
            AccountType type = obj as AccountType;

            if (type != null)
            {
                return(TypeName.Equals(type.TypeName) &
                       PutWeights.Equals(type.PutWeights) &
                       WithdrawWeights.Equals(type.WithdrawWeights));
            }

            return(false);
        }
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }
            var oid = obj as EntityOid;

            if (oid != null)
            {
                return(TypeName.Equals(oid.TypeName) && Key.SequenceEqual(oid.Key));
            }
            return(false);
        }
            /// <summary>
            ///   Processes the specified type creating kernel bindings.
            ///   If the type is called typeName and implements interfaceType it will be bound to interfaceType
            /// </summary>
            /// <param name = "type">The type to process.</param>
            /// <param name = "scopeCallback">the scope callback.</param>
            /// <param name = "kernel">The kernel to configure.</param>
            public void Process(Type type, Func <IContext, object> scopeCallback, IKernel kernel)
            {
                if (type.IsInterface || type.IsAbstract)
                {
                    return;
                }

                if (TypeName.Equals(type.Name) || TypeName.Equals(type.FullName))
                {
                    if (type.GetInterface(InterfaceType.FullName) != null)
                    {
                        kernel.Rebind(InterfaceType).To(type).InScope(scopeCallback);
                    }
                }
            }
Beispiel #19
0
        public void AddName(TypeName name)
        {
            if (name.Equals(TypeName.Empty))
            {
                throw new ArgumentException("must not be TypeName.Empty", nameof(name));
            }

            if (Name.Equals(TypeName.Empty))
            {
                Name = name;
            }
            else
            {
                (nestedNames ?? (nestedNames = new List <TypeName> ())).Add(name);
            }
        }
Beispiel #20
0
        protected override bool LoadFromXmlNode(XmlNode node)
        {
            try
            {
                if (node != null && !node.Name.Equals("#comment"))
                {
                    if (TypeName.Equals(""))
                    {
                        TypeName = node.Name;
                    }

                    if (node.Name.Equals(TypeName))
                    {
                        Clear();

                        foreach (XmlNode xSubNode in node.ChildNodes)
                        {
                            if (!xSubNode.Name.Equals("#comment"))
                            {
                                if (!SetExtXmlData(xSubNode))
                                {
                                    if (xSubNode.FirstChild != null && xSubNode.FirstChild.Value != null)
                                    {
                                        this.SetValue(xSubNode.Name, xSubNode.FirstChild.Value);
                                    }
                                }
                            }
                        }

                        if (IsExist("Name"))
                        {
                            Name = StrValue("Name");
                        }

                        return(true);
                    }
                }
            }
            catch (Exception e)
            {
                System.Console.Out.WriteLine("¼ÓÔØÅäÖÃÊý¾Ýʧ°Ü£º{0}", e);
            }
            return(false);
        }
        public bool Equals(XunitTestTheoryTask other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            // Do not include base.Equals, so we don't try to compare Id or ParentId,
            // which will be different for each instance, and we're trying to act like
            // a value type
            return(ProjectId.Equals(other.ProjectId) &&
                   TypeName.Equals(other.TypeName) &&
                   MethodName.Equals(other.MethodName) &&
                   TheoryName.Equals(other.TheoryName));
        }
Beispiel #22
0
        public override bool Equals(object obj)
        {
            EnumerationType other = obj as EnumerationType;

            if (other != null && TypeName.Equals(other.TypeName) && other._legalValues.Count == _legalValues.Count)
            {
                for (int i = 0; i < _legalValues.Count; i++)
                {
                    KeyValuePair <string, int> thisPair  = _legalValues[i];
                    KeyValuePair <string, int> otherPair = other._legalValues[i];
                    if ((thisPair.Key != otherPair.Key || thisPair.Value != otherPair.Value))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            return(false);
        }
Beispiel #23
0
 private IConfig CreateConfigInstance(XmlNode node)
 {
     if (TypeName.Equals("Actions") || TypeName.Equals("Monitors") || TypeName.Equals("Schedulers") || TypeName.Equals("Tasks") || TypeName.Equals("VideoSources"))
     {
         string type = "";
         foreach (XmlNode xSubNode in node.ChildNodes)
         {
             if (!xSubNode.Name.Equals("#comment") && xSubNode.Name.Equals("Type"))
             {
                 type = xSubNode.FirstChild.Value;
                 break;
             }
         }
         if (!type.Equals(""))
         {
             return(CreateConfigInstance(type));
         }
     }
     return(CreateConfigInstance());
 }
Beispiel #24
0
        public bool Equals(XunitTestTheoryTask other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            // Don't include base.Equals, as RemoteTask.Equals includes RemoteTask.Id
            // in the calculation, and this is a new guid generated for each new instance
            // Using RemoteTask.Id in the Equals means collapsing the return values of
            // IUnitTestElement.GetTaskSequence into a tree will fail (as no assembly,
            // or class tasks will return true from Equals)
            return(AssemblyLocation.Equals(other.AssemblyLocation) &&
                   TypeName.Equals(other.TypeName) &&
                   MethodName.Equals(other.MethodName) &&
                   TheoryName.Equals(other.TheoryName));
        }
Beispiel #25
0
        public sealed override bool Equals(object obj)
        {
            TabularType other = obj as TabularType;

            if (other != null && TypeName.Equals(other.TypeName) && _rowType.Equals(other._rowType) &&
                _indexNames.Count == other._indexNames.Count)
            {
                for (int i = 0; i < _indexNames.Count; i++)
                {
                    if (_indexNames[i] != other._indexNames[i])
                    {
                        return(false);
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #26
0
        public DocumentNode Rewrite(ISchemaInfo schema, DocumentNode document)
        {
            if (SchemaName.HasValue && !SchemaName.Value.Equals(schema.Name))
            {
                return(document);
            }

            ITypeDefinitionNode?typeDefinition = document.Definitions
                                                 .OfType <ITypeDefinitionNode>()
                                                 .FirstOrDefault(t => TypeName.Equals(t.GetOriginalName(schema.Name)));

            if (typeDefinition is null)
            {
                return(document);
            }

            var definitions = new List <IDefinitionNode>(document.Definitions);

            definitions.Remove(typeDefinition);
            return(document.WithDefinitions(definitions));
        }
Beispiel #27
0
        public override bool Equals(object obj)
        {
            CType type = (obj as CType);

            if (type == null)
            {
                return(false);
            }

            bool equ = true;

            equ = equ && TypeClass == type.TypeClass;
            equ = equ && IsConst == type.IsConst;
            equ = equ && TypeName.Equals(type.TypeName);
            equ = equ && ArraySize == type.ArraySize;
            equ = equ && ContainedType == type.ContainedType;
            equ = equ && (EnumConstants == type.EnumConstants || (EnumConstants != null && type.EnumConstants != null && Enumerable.SequenceEqual(EnumConstants, type.EnumConstants)));
            equ = equ && (StructMembers == type.StructMembers || (StructMembers != null && type.StructMembers != null && Enumerable.SequenceEqual(StructMembers, type.StructMembers)));
            equ = equ && FunctionReturnType == type.FunctionReturnType;
            equ = equ && (FunctionArgumentTypes == type.FunctionArgumentTypes || (FunctionArgumentTypes != null && type.FunctionArgumentTypes != null && Enumerable.SequenceEqual(FunctionArgumentTypes, type.FunctionArgumentTypes)));
            return(equ);
        }
Beispiel #28
0
        public sealed override bool Equals(object obj)
        {
            CompositeType other = obj as CompositeType;

            if (other != null && TypeName.Equals(other.TypeName) && other._members.Count == _members.Count)
            {
                foreach (string key in _members.Keys)
                {
                    CompositeTypeMember thisMember = _members[key];
                    CompositeTypeMember otherMember;
                    if (!other._members.TryGetValue(key, out otherMember))
                    {
                        return(false);
                    }
                    if (!thisMember.Equals(otherMember))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            return(false);
        }
Beispiel #29
0
        private Func <ColumnVal, Node> GetColumnWriter(VariableDef c)
        {
            String  TypeName;
            Boolean IsOptional;

            if (c.Type.OnTypeRef)
            {
                TypeName   = c.Type.TypeRef.Value;
                IsOptional = false;
            }
            else if (c.Type.OnOptional)
            {
                TypeName   = c.Type.Optional.Value;
                IsOptional = true;
            }
            else if (c.Type.OnList)
            {
                var ElementTypeName = c.Type.List.Value;
                if (!ElementTypeName.Equals("Byte", StringComparison.OrdinalIgnoreCase))
                {
                    throw new InvalidOperationException("InvalidColumnListType: List<{0}>".Formats(ElementTypeName));
                }

                TypeName   = "Binary";
                IsOptional = false;
            }
            else
            {
                throw new InvalidOperationException();
            }
            Dictionary <Int64, String> EnumWriter = null;

            if (EnumUnderlyingTypes.ContainsKey(TypeName))
            {
                EnumWriter = EnumWriters[TypeName];
                TypeName   = EnumUnderlyingTypes[TypeName];
            }

            Func <ColumnVal, Node> Writer;

            if (!IsOptional)
            {
                if (TypeName.Equals("Boolean", StringComparison.OrdinalIgnoreCase))
                {
                    Writer = v =>
                    {
                        if (!v.OnPrimitive)
                        {
                            throw new InvalidOperationException();
                        }
                        var vv = v.Primitive;
                        if (!vv.OnBooleanValue)
                        {
                            throw new InvalidOperationException();
                        }
                        return(Node.CreateStem(new Stem {
                            Name = c.Name, Children = new List <Node> {
                                Node.CreateLeaf(vv.BooleanValue.ToInvariantString())
                            }
                        }));
                    };
                }
                else if (TypeName.Equals("String", StringComparison.OrdinalIgnoreCase))
                {
                    Writer = v =>
                    {
                        if (!v.OnPrimitive)
                        {
                            throw new InvalidOperationException();
                        }
                        var vv = v.Primitive;
                        if (!vv.OnStringValue)
                        {
                            throw new InvalidOperationException();
                        }
                        return(Node.CreateStem(new Stem {
                            Name = c.Name, Children = new List <Node> {
                                Node.CreateLeaf(vv.StringValue)
                            }
                        }));
                    };
                }
                else if (TypeName.Equals("Int", StringComparison.OrdinalIgnoreCase))
                {
                    if (EnumWriter != null)
                    {
                        Writer = v =>
                        {
                            if (!v.OnPrimitive)
                            {
                                throw new InvalidOperationException();
                            }
                            var vv = v.Primitive;
                            if (!vv.OnIntValue)
                            {
                                throw new InvalidOperationException();
                            }
                            if (EnumWriter.ContainsKey(vv.IntValue))
                            {
                                return(Node.CreateStem(new Stem {
                                    Name = c.Name, Children = new List <Node> {
                                        Node.CreateLeaf(EnumWriter[vv.IntValue])
                                    }
                                }));
                            }
                            else
                            {
                                return(Node.CreateStem(new Stem {
                                    Name = c.Name, Children = new List <Node> {
                                        Node.CreateLeaf(vv.IntValue.ToInvariantString())
                                    }
                                }));
                            }
                        };
                    }
                    else
                    {
                        Writer = v =>
                        {
                            if (!v.OnPrimitive)
                            {
                                throw new InvalidOperationException();
                            }
                            var vv = v.Primitive;
                            if (!vv.OnIntValue)
                            {
                                throw new InvalidOperationException();
                            }
                            return(Node.CreateStem(new Stem {
                                Name = c.Name, Children = new List <Node> {
                                    Node.CreateLeaf(vv.IntValue.ToInvariantString())
                                }
                            }));
                        };
                    }
                }
                else if (TypeName.Equals("Int64", StringComparison.OrdinalIgnoreCase))
                {
                    if (EnumWriter != null)
                    {
                        Writer = v =>
                        {
                            if (!v.OnPrimitive)
                            {
                                throw new InvalidOperationException();
                            }
                            var vv = v.Primitive;
                            if (!vv.OnInt64Value)
                            {
                                throw new InvalidOperationException();
                            }
                            if (EnumWriter.ContainsKey(vv.Int64Value))
                            {
                                return(Node.CreateStem(new Stem {
                                    Name = c.Name, Children = new List <Node> {
                                        Node.CreateLeaf(EnumWriter[vv.Int64Value])
                                    }
                                }));
                            }
                            else
                            {
                                return(Node.CreateStem(new Stem {
                                    Name = c.Name, Children = new List <Node> {
                                        Node.CreateLeaf(vv.Int64Value.ToInvariantString())
                                    }
                                }));
                            }
                        };
                    }
                    else
                    {
                        Writer = v =>
                        {
                            if (!v.OnPrimitive)
                            {
                                throw new InvalidOperationException();
                            }
                            var vv = v.Primitive;
                            if (!vv.OnInt64Value)
                            {
                                throw new InvalidOperationException();
                            }
                            return(Node.CreateStem(new Stem {
                                Name = c.Name, Children = new List <Node> {
                                    Node.CreateLeaf(vv.Int64Value.ToInvariantString())
                                }
                            }));
                        };
                    }
                }
                else if (TypeName.Equals("Real", StringComparison.OrdinalIgnoreCase))
                {
                    Writer = v =>
                    {
                        if (!v.OnPrimitive)
                        {
                            throw new InvalidOperationException();
                        }
                        var vv = v.Primitive;
                        if (!vv.OnRealValue)
                        {
                            throw new InvalidOperationException();
                        }
                        return(Node.CreateStem(new Stem {
                            Name = c.Name, Children = new List <Node> {
                                Node.CreateLeaf(vv.RealValue.ToInvariantString())
                            }
                        }));
                    };
                }
                else if (TypeName.Equals("Binary", StringComparison.OrdinalIgnoreCase))
                {
                    Writer = v =>
                    {
                        if (!v.OnPrimitive)
                        {
                            throw new InvalidOperationException();
                        }
                        var vv = v.Primitive;
                        if (!vv.OnBinaryValue)
                        {
                            throw new InvalidOperationException();
                        }
                        var ByteString = String.Join(" ", vv.BinaryValue.Select(b => b.ToString("X2", System.Globalization.CultureInfo.InvariantCulture)).ToArray());
                        return(Node.CreateStem(new Stem {
                            Name = c.Name, Children = new List <Node> {
                                Node.CreateLeaf(ByteString)
                            }
                        }));
                    };
                }
                else
                {
                    throw new InvalidOperationException("InvalidType: {0}".Formats(TypeName));
                }
            }
            else
            {
                if (TypeName.Equals("Boolean", StringComparison.OrdinalIgnoreCase))
                {
                    Writer = v =>
                    {
                        if (!v.OnOptional)
                        {
                            throw new InvalidOperationException();
                        }
                        if (v.Optional.OnNone)
                        {
                            return(Node.CreateStem(new Stem {
                                Name = c.Name, Children = new List <Node> {
                                    Node.CreateEmpty()
                                }
                            }));
                        }
                        var vv = v.Optional.Some;
                        if (!vv.OnBooleanValue)
                        {
                            throw new InvalidOperationException();
                        }
                        return(Node.CreateStem(new Stem {
                            Name = c.Name, Children = new List <Node> {
                                Node.CreateLeaf(vv.BooleanValue.ToInvariantString())
                            }
                        }));
                    };
                }
                else if (TypeName.Equals("String", StringComparison.OrdinalIgnoreCase))
                {
                    Writer = v =>
                    {
                        if (!v.OnOptional)
                        {
                            throw new InvalidOperationException();
                        }
                        if (v.Optional.OnNone)
                        {
                            return(Node.CreateStem(new Stem {
                                Name = c.Name, Children = new List <Node> {
                                    Node.CreateEmpty()
                                }
                            }));
                        }
                        var vv = v.Optional.Some;
                        if (!vv.OnStringValue)
                        {
                            throw new InvalidOperationException();
                        }
                        return(Node.CreateStem(new Stem {
                            Name = c.Name, Children = new List <Node> {
                                Node.CreateLeaf(vv.StringValue)
                            }
                        }));
                    };
                }
                else if (TypeName.Equals("Int", StringComparison.OrdinalIgnoreCase))
                {
                    Writer = v =>
                    {
                        if (!v.OnOptional)
                        {
                            throw new InvalidOperationException();
                        }
                        if (v.Optional.OnNone)
                        {
                            return(Node.CreateStem(new Stem {
                                Name = c.Name, Children = new List <Node> {
                                    Node.CreateEmpty()
                                }
                            }));
                        }
                        var vv = v.Optional.Some;
                        if (!vv.OnIntValue)
                        {
                            throw new InvalidOperationException();
                        }
                        return(Node.CreateStem(new Stem {
                            Name = c.Name, Children = new List <Node> {
                                Node.CreateLeaf(vv.IntValue.ToInvariantString())
                            }
                        }));
                    };
                }
                else if (TypeName.Equals("Int64", StringComparison.OrdinalIgnoreCase))
                {
                    Writer = v =>
                    {
                        if (!v.OnOptional)
                        {
                            throw new InvalidOperationException();
                        }
                        if (v.Optional.OnNone)
                        {
                            return(Node.CreateStem(new Stem {
                                Name = c.Name, Children = new List <Node> {
                                    Node.CreateEmpty()
                                }
                            }));
                        }
                        var vv = v.Optional.Some;
                        if (!vv.OnInt64Value)
                        {
                            throw new InvalidOperationException();
                        }
                        return(Node.CreateStem(new Stem {
                            Name = c.Name, Children = new List <Node> {
                                Node.CreateLeaf(vv.Int64Value.ToInvariantString())
                            }
                        }));
                    };
                }
                else if (TypeName.Equals("Real", StringComparison.OrdinalIgnoreCase))
                {
                    Writer = v =>
                    {
                        if (!v.OnOptional)
                        {
                            throw new InvalidOperationException();
                        }
                        if (v.Optional.OnNone)
                        {
                            return(Node.CreateStem(new Stem {
                                Name = c.Name, Children = new List <Node> {
                                    Node.CreateEmpty()
                                }
                            }));
                        }
                        var vv = v.Optional.Some;
                        if (!vv.OnRealValue)
                        {
                            throw new InvalidOperationException();
                        }
                        return(Node.CreateStem(new Stem {
                            Name = c.Name, Children = new List <Node> {
                                Node.CreateLeaf(vv.RealValue.ToInvariantString())
                            }
                        }));
                    };
                }
                else if (TypeName.Equals("Binary", StringComparison.OrdinalIgnoreCase))
                {
                    Writer = v =>
                    {
                        if (!v.OnOptional)
                        {
                            throw new InvalidOperationException();
                        }
                        if (v.Optional.OnNone)
                        {
                            return(Node.CreateStem(new Stem {
                                Name = c.Name, Children = new List <Node> {
                                    Node.CreateEmpty()
                                }
                            }));
                        }
                        var vv = v.Optional.Some;
                        if (!vv.OnBinaryValue)
                        {
                            throw new InvalidOperationException();
                        }
                        var ByteString = String.Join(" ", vv.BinaryValue.Select(b => b.ToString("X2", System.Globalization.CultureInfo.InvariantCulture)).ToArray());
                        return(Node.CreateStem(new Stem {
                            Name = c.Name, Children = new List <Node> {
                                Node.CreateLeaf(ByteString)
                            }
                        }));
                    };
                }
                else
                {
                    throw new InvalidOperationException("InvalidType: {0}".Formats(TypeName));
                }
            }
            return(Writer);
        }
Beispiel #30
0
        private Func <Node, ColumnVal> GetColumnReader(EntityDef e, VariableDef c)
        {
            String  TypeName;
            Boolean IsOptional;

            if (c.Type.OnTypeRef)
            {
                TypeName   = c.Type.TypeRef.Value;
                IsOptional = false;
            }
            else if (c.Type.OnOptional)
            {
                TypeName   = c.Type.Optional.Value;
                IsOptional = true;
            }
            else if (c.Type.OnList)
            {
                var ElementTypeName = c.Type.List.Value;
                if (!ElementTypeName.Equals("Byte", StringComparison.OrdinalIgnoreCase))
                {
                    throw new InvalidOperationException("InvalidColumnListType: List<{0}>".Formats(ElementTypeName));
                }

                TypeName   = "Binary";
                IsOptional = false;
            }
            else
            {
                throw new InvalidOperationException();
            }
            Dictionary <String, Int64> EnumParser = null;

            if (EnumUnderlyingTypes.ContainsKey(TypeName))
            {
                EnumParser = EnumParsers[TypeName];
                TypeName   = EnumUnderlyingTypes[TypeName];
            }

            Func <Node, ColumnVal> Reader;

            if (!IsOptional)
            {
                if (TypeName.Equals("Boolean", StringComparison.OrdinalIgnoreCase))
                {
                    Reader = TreeRow =>
                    {
                        var cvs = TreeRow.Stem.Children.Where(col => col.OnStem && col.Stem.Name.Equals(c.Name, StringComparison.OrdinalIgnoreCase)).ToList();
                        if (cvs.Count != 1)
                        {
                            throw new InvalidOperationException(String.Format("InvalidData: {0}.{1}", e.Name, c.Name));
                        }
                        var cv = cvs.Single().Stem.Children.Single().Leaf;
                        try
                        {
                            var v = Boolean.Parse(cv);
                            return(ColumnVal.CreatePrimitive(PrimitiveVal.CreateBooleanValue(v)));
                        }
                        catch (FormatException)
                        {
                            throw new InvalidOperationException(String.Format("InvalidData: {0}.{1} '{2}'", e.Name, c.Name, cv));
                        }
                    };
                }
                else if (TypeName.Equals("String", StringComparison.OrdinalIgnoreCase))
                {
                    Reader = TreeRow =>
                    {
                        var cvs = TreeRow.Stem.Children.Where(col => col.OnStem && col.Stem.Name.Equals(c.Name, StringComparison.OrdinalIgnoreCase)).ToList();
                        if (cvs.Count != 1)
                        {
                            throw new InvalidOperationException(String.Format("InvalidData: {0}.{1}", e.Name, c.Name));
                        }
                        var cv = cvs.Single().Stem.Children.Single().Leaf;
                        var v  = cv;
                        return(ColumnVal.CreatePrimitive(PrimitiveVal.CreateStringValue(v)));
                    };
                }
                else if (TypeName.Equals("Int", StringComparison.OrdinalIgnoreCase))
                {
                    if (EnumParser != null)
                    {
                        Reader = TreeRow =>
                        {
                            var cvs = TreeRow.Stem.Children.Where(col => col.OnStem && col.Stem.Name.Equals(c.Name, StringComparison.OrdinalIgnoreCase)).ToList();
                            if (cvs.Count != 1)
                            {
                                throw new InvalidOperationException(String.Format("InvalidData: {0}.{1}", e.Name, c.Name));
                            }
                            var cv = cvs.Single().Stem.Children.Single().Leaf;
                            if (EnumParser.ContainsKey(cv))
                            {
                                var v = (int)(EnumParser[cv]);
                                return(ColumnVal.CreatePrimitive(PrimitiveVal.CreateIntValue(v)));
                            }
                            else
                            {
                                try
                                {
                                    var v = NumericStrings.InvariantParseInt32(cv);
                                    return(ColumnVal.CreatePrimitive(PrimitiveVal.CreateIntValue(v)));
                                }
                                catch (FormatException)
                                {
                                    throw new InvalidOperationException(String.Format("InvalidData: {0}.{1} '{2}'", e.Name, c.Name, cv));
                                }
                            }
                        };
                    }
                    else
                    {
                        Reader = TreeRow =>
                        {
                            var cvs = TreeRow.Stem.Children.Where(col => col.OnStem && col.Stem.Name.Equals(c.Name, StringComparison.OrdinalIgnoreCase)).ToList();
                            if (cvs.Count != 1)
                            {
                                throw new InvalidOperationException(String.Format("InvalidData: {0}.{1}", e.Name, c.Name));
                            }
                            var cv = cvs.Single().Stem.Children.Single().Leaf;
                            try
                            {
                                var v = NumericStrings.InvariantParseInt32(cv);
                                return(ColumnVal.CreatePrimitive(PrimitiveVal.CreateIntValue(v)));
                            }
                            catch (FormatException)
                            {
                                throw new InvalidOperationException(String.Format("InvalidData: {0}.{1} '{2}'", e.Name, c.Name, cv));
                            }
                        };
                    }
                }
                else if (TypeName.Equals("Int64", StringComparison.OrdinalIgnoreCase))
                {
                    if (EnumParser != null)
                    {
                        Reader = TreeRow =>
                        {
                            var cvs = TreeRow.Stem.Children.Where(col => col.OnStem && col.Stem.Name.Equals(c.Name, StringComparison.OrdinalIgnoreCase)).ToList();
                            if (cvs.Count != 1)
                            {
                                throw new InvalidOperationException(String.Format("InvalidData: {0}.{1}", e.Name, c.Name));
                            }
                            var cv = cvs.Single().Stem.Children.Single().Leaf;
                            if (EnumParser.ContainsKey(cv))
                            {
                                var v = (Int64)(EnumParser[cv]);
                                return(ColumnVal.CreatePrimitive(PrimitiveVal.CreateInt64Value(v)));
                            }
                            else
                            {
                                try
                                {
                                    var v = NumericStrings.InvariantParseInt64(cv);
                                    return(ColumnVal.CreatePrimitive(PrimitiveVal.CreateInt64Value(v)));
                                }
                                catch (FormatException)
                                {
                                    throw new InvalidOperationException(String.Format("InvalidData: {0}.{1} '{2}'", e.Name, c.Name, cv));
                                }
                            }
                        };
                    }
                    else
                    {
                        Reader = TreeRow =>
                        {
                            var cvs = TreeRow.Stem.Children.Where(col => col.OnStem && col.Stem.Name.Equals(c.Name, StringComparison.OrdinalIgnoreCase)).ToList();
                            if (cvs.Count != 1)
                            {
                                throw new InvalidOperationException(String.Format("InvalidData: {0}.{1}", e.Name, c.Name));
                            }
                            var cv = cvs.Single().Stem.Children.Single().Leaf;
                            try
                            {
                                var v = NumericStrings.InvariantParseInt64(cv);
                                return(ColumnVal.CreatePrimitive(PrimitiveVal.CreateInt64Value(v)));
                            }
                            catch (FormatException)
                            {
                                throw new InvalidOperationException(String.Format("InvalidData: {0}.{1} '{2}'", e.Name, c.Name, cv));
                            }
                        };
                    }
                }
                else if (TypeName.Equals("Real", StringComparison.OrdinalIgnoreCase))
                {
                    Reader = TreeRow =>
                    {
                        var cvs = TreeRow.Stem.Children.Where(col => col.OnStem && col.Stem.Name.Equals(c.Name, StringComparison.OrdinalIgnoreCase)).ToList();
                        if (cvs.Count != 1)
                        {
                            throw new InvalidOperationException(String.Format("InvalidData: {0}.{1}", e.Name, c.Name));
                        }
                        var cv = cvs.Single().Stem.Children.Single().Leaf;
                        try
                        {
                            var v = NumericStrings.InvariantParseFloat64(cv);
                            return(ColumnVal.CreatePrimitive(PrimitiveVal.CreateRealValue(v)));
                        }
                        catch (FormatException)
                        {
                            throw new InvalidOperationException(String.Format("InvalidData: {0}.{1} '{2}'", e.Name, c.Name, cv));
                        }
                    };
                }
                else if (TypeName.Equals("Binary", StringComparison.OrdinalIgnoreCase))
                {
                    Reader = TreeRow =>
                    {
                        var cvs = TreeRow.Stem.Children.Where(col => col.OnStem && col.Stem.Name.Equals(c.Name, StringComparison.OrdinalIgnoreCase)).ToList();
                        if (cvs.Count != 1)
                        {
                            throw new InvalidOperationException(String.Format("InvalidData: {0}.{1}", e.Name, c.Name));
                        }
                        var cv = cvs.Single().Stem.Children.Single().Leaf;
                        try
                        {
                            var v = Regex.Split(cv.Trim(" \t\r\n".ToCharArray()), "( |\t|\r|\n)+", RegexOptions.ExplicitCapture).Where(s => s != "").Select(s => Byte.Parse(s, System.Globalization.NumberStyles.HexNumber)).ToList();
                            return(ColumnVal.CreatePrimitive(PrimitiveVal.CreateBinaryValue(v)));
                        }
                        catch (FormatException)
                        {
                            throw new InvalidOperationException(String.Format("InvalidData: {0}.{1} '{2}'", e.Name, c.Name, cv));
                        }
                    };
                }
                else
                {
                    throw new InvalidOperationException("InvalidType: {0}".Formats(TypeName));
                }
            }
            else
            {
                if (TypeName.Equals("Boolean", StringComparison.OrdinalIgnoreCase))
                {
                    Reader = TreeRow =>
                    {
                        var cvs = TreeRow.Stem.Children.Where(col => col.OnStem && col.Stem.Name.Equals(c.Name, StringComparison.OrdinalIgnoreCase)).ToList();
                        if (cvs.Count != 1)
                        {
                            throw new InvalidOperationException(String.Format("InvalidData: {0}.{1}", e.Name, c.Name));
                        }
                        var cv = cvs.Single().Stem.Children.Single().Leaf;
                        if ((cv == null) || (cv == "-"))
                        {
                            return(ColumnVal.CreateOptional(Optional <PrimitiveVal> .Empty));
                        }
                        try
                        {
                            var v = Boolean.Parse(cv);
                            return(ColumnVal.CreateOptional(PrimitiveVal.CreateBooleanValue(v)));
                        }
                        catch (FormatException)
                        {
                            throw new InvalidOperationException(String.Format("InvalidData: {0}.{1} '{2}'", e.Name, c.Name, cv));
                        }
                    };
                }
                else if (TypeName.Equals("String", StringComparison.OrdinalIgnoreCase))
                {
                    Reader = TreeRow =>
                    {
                        var cvs = TreeRow.Stem.Children.Where(col => col.OnStem && col.Stem.Name.Equals(c.Name, StringComparison.OrdinalIgnoreCase)).ToList();
                        if (cvs.Count != 1)
                        {
                            throw new InvalidOperationException(String.Format("InvalidData: {0}.{1}", e.Name, c.Name));
                        }
                        var cv = cvs.Single().Stem.Children.Single().Leaf;
                        if ((cv == null) || (cv == "-"))
                        {
                            return(ColumnVal.CreateOptional(Optional <PrimitiveVal> .Empty));
                        }
                        var v = cv;
                        return(ColumnVal.CreateOptional(PrimitiveVal.CreateStringValue(v)));
                    };
                }
                else if (TypeName.Equals("Int", StringComparison.OrdinalIgnoreCase))
                {
                    if (EnumParser != null)
                    {
                        Reader = TreeRow =>
                        {
                            var cvs = TreeRow.Stem.Children.Where(col => col.OnStem && col.Stem.Name.Equals(c.Name, StringComparison.OrdinalIgnoreCase)).ToList();
                            if (cvs.Count != 1)
                            {
                                throw new InvalidOperationException(String.Format("InvalidData: {0}.{1}", e.Name, c.Name));
                            }
                            var cv = cvs.Single().Stem.Children.Single().Leaf;
                            if ((cv == null) || (cv == "-"))
                            {
                                return(ColumnVal.CreateOptional(Optional <PrimitiveVal> .Empty));
                            }
                            if (EnumParser.ContainsKey(cv))
                            {
                                var v = (int)(EnumParser[cv]);
                                return(ColumnVal.CreateOptional(PrimitiveVal.CreateIntValue(v)));
                            }
                            else
                            {
                                try
                                {
                                    var v = NumericStrings.InvariantParseInt32(cv);
                                    return(ColumnVal.CreateOptional(PrimitiveVal.CreateIntValue(v)));
                                }
                                catch (FormatException)
                                {
                                    throw new InvalidOperationException(String.Format("InvalidData: {0}.{1} '{2}'", e.Name, c.Name, cv));
                                }
                            }
                        };
                    }
                    else
                    {
                        Reader = TreeRow =>
                        {
                            var cvs = TreeRow.Stem.Children.Where(col => col.OnStem && col.Stem.Name.Equals(c.Name, StringComparison.OrdinalIgnoreCase)).ToList();
                            if (cvs.Count != 1)
                            {
                                throw new InvalidOperationException(String.Format("InvalidData: {0}.{1}", e.Name, c.Name));
                            }
                            var cv = cvs.Single().Stem.Children.Single().Leaf;
                            if ((cv == null) || (cv == "-"))
                            {
                                return(ColumnVal.CreateOptional(Optional <PrimitiveVal> .Empty));
                            }
                            try
                            {
                                var v = NumericStrings.InvariantParseInt32(cv);
                                return(ColumnVal.CreateOptional(PrimitiveVal.CreateIntValue(v)));
                            }
                            catch (FormatException)
                            {
                                throw new InvalidOperationException(String.Format("InvalidData: {0}.{1} '{2}'", e.Name, c.Name, cv));
                            }
                        };
                    }
                }
                else if (TypeName.Equals("Int64", StringComparison.OrdinalIgnoreCase))
                {
                    if (EnumParser != null)
                    {
                        Reader = TreeRow =>
                        {
                            var cvs = TreeRow.Stem.Children.Where(col => col.OnStem && col.Stem.Name.Equals(c.Name, StringComparison.OrdinalIgnoreCase)).ToList();
                            if (cvs.Count != 1)
                            {
                                throw new InvalidOperationException(String.Format("InvalidData: {0}.{1}", e.Name, c.Name));
                            }
                            var cv = cvs.Single().Stem.Children.Single().Leaf;
                            if ((cv == null) || (cv == "-"))
                            {
                                return(ColumnVal.CreateOptional(Optional <PrimitiveVal> .Empty));
                            }
                            if (EnumParser.ContainsKey(cv))
                            {
                                var v = (Int64)(EnumParser[cv]);
                                return(ColumnVal.CreateOptional(PrimitiveVal.CreateInt64Value(v)));
                            }
                            else
                            {
                                try
                                {
                                    var v = NumericStrings.InvariantParseInt64(cv);
                                    return(ColumnVal.CreateOptional(PrimitiveVal.CreateInt64Value(v)));
                                }
                                catch (FormatException)
                                {
                                    throw new InvalidOperationException(String.Format("InvalidData: {0}.{1} '{2}'", e.Name, c.Name, cv));
                                }
                            }
                        };
                    }
                    else
                    {
                        Reader = TreeRow =>
                        {
                            var cvs = TreeRow.Stem.Children.Where(col => col.OnStem && col.Stem.Name.Equals(c.Name, StringComparison.OrdinalIgnoreCase)).ToList();
                            if (cvs.Count != 1)
                            {
                                throw new InvalidOperationException(String.Format("InvalidData: {0}.{1}", e.Name, c.Name));
                            }
                            var cv = cvs.Single().Stem.Children.Single().Leaf;
                            if ((cv == null) || (cv == "-"))
                            {
                                return(ColumnVal.CreateOptional(Optional <PrimitiveVal> .Empty));
                            }
                            try
                            {
                                var v = NumericStrings.InvariantParseInt64(cv);
                                return(ColumnVal.CreateOptional(PrimitiveVal.CreateInt64Value(v)));
                            }
                            catch (FormatException)
                            {
                                throw new InvalidOperationException(String.Format("InvalidData: {0}.{1} '{2}'", e.Name, c.Name, cv));
                            }
                        };
                    }
                }
                else if (TypeName.Equals("Real", StringComparison.OrdinalIgnoreCase))
                {
                    Reader = TreeRow =>
                    {
                        var cvs = TreeRow.Stem.Children.Where(col => col.OnStem && col.Stem.Name.Equals(c.Name, StringComparison.OrdinalIgnoreCase)).ToList();
                        if (cvs.Count != 1)
                        {
                            throw new InvalidOperationException(String.Format("InvalidData: {0}.{1}", e.Name, c.Name));
                        }
                        var cv = cvs.Single().Stem.Children.Single().Leaf;
                        if ((cv == null) || (cv == "-"))
                        {
                            return(ColumnVal.CreateOptional(Optional <PrimitiveVal> .Empty));
                        }
                        try
                        {
                            var v = NumericStrings.InvariantParseFloat64(cv);
                            return(ColumnVal.CreateOptional(PrimitiveVal.CreateRealValue(v)));
                        }
                        catch (FormatException)
                        {
                            throw new InvalidOperationException(String.Format("InvalidData: {0}.{1} '{2}'", e.Name, c.Name, cv));
                        }
                    };
                }
                else if (TypeName.Equals("Binary", StringComparison.OrdinalIgnoreCase))
                {
                    Reader = TreeRow =>
                    {
                        var cvs = TreeRow.Stem.Children.Where(col => col.OnStem && col.Stem.Name.Equals(c.Name, StringComparison.OrdinalIgnoreCase)).ToList();
                        if (cvs.Count != 1)
                        {
                            throw new InvalidOperationException(String.Format("InvalidData: {0}.{1}", e.Name, c.Name));
                        }
                        var cv = cvs.Single().Stem.Children.Single().Leaf;
                        if ((cv == null) || (cv == "-"))
                        {
                            return(ColumnVal.CreateOptional(Optional <PrimitiveVal> .Empty));
                        }
                        try
                        {
                            var v = Regex.Split(cv.Trim(" \t\r\n".ToCharArray()), "( |\t|\r|\n)+", RegexOptions.ExplicitCapture).Select(s => Byte.Parse(s, System.Globalization.NumberStyles.HexNumber)).ToList();
                            return(ColumnVal.CreateOptional(PrimitiveVal.CreateBinaryValue(v)));
                        }
                        catch (FormatException)
                        {
                            throw new InvalidOperationException(String.Format("InvalidData: {0}.{1} '{2}'", e.Name, c.Name, cv));
                        }
                    };
                }
                else
                {
                    throw new InvalidOperationException("InvalidType: {0}".Formats(TypeName));
                }
            }
            return(Reader);
        }