コード例 #1
0
 protected ValueNode(Node parent, string name, TypeNode typeNode)
     : base(parent)
 {
     Name = name;
     TypeNode = typeNode;
     Children = new List<ValueNode>();
 }
コード例 #2
0
 public ArrayTypeNode(TypeNode parent, Type type) : base(parent, type)
 {
     Construct();
 }
コード例 #3
0
 public ListTypeNode(TypeNode parent, Type type)
     : base(parent, type)
 {
     Construct();
 }
コード例 #4
0
 public ValueTypeNode(TypeNode parent, Type type)
     : base(parent, type)
 {
 }
コード例 #5
0
 public ObjectTypeNode(TypeNode parent, Type parentType, MemberInfo memberInfo)
     : base(parent, parentType, memberInfo)
 {
 }
コード例 #6
0
 public RootTypeNode(TypeNode parent, Type graphType)
     : base(parent, graphType)
 {
     Child = GenerateChild(graphType);
 }
コード例 #7
0
 public ValueValueNode(Node parent, string name, TypeNode typeNode)
     : base(parent, name, typeNode)
 {
 }
コード例 #8
0
 public EnumTypeNode(TypeNode parent, Type type)
     : base(parent, type)
 {
     InitializeEnumValues();
 }
コード例 #9
0
 public ArrayTypeNode(TypeNode parent, Type type)
     : base(parent, type)
 {
     Construct();
 }
コード例 #10
0
 public UnknownTypeNode(TypeNode parent, Type parentType, MemberInfo memberInfo)
     : base(parent, parentType, memberInfo)
 {
 }
コード例 #11
0
 public UnknownTypeNode(TypeNode parent, Type type)
     : base(parent, type)
 {
 }
コード例 #12
0
 public CustomTypeNode(TypeNode parent, Type parentType, MemberInfo memberInfo)
     : base(parent, parentType, memberInfo)
 {
 }
コード例 #13
0
 public CustomTypeNode(TypeNode parent, Type type)
     : base(parent, type)
 {
 }
コード例 #14
0
 protected CollectionTypeNode(TypeNode parent, Type parentType, MemberInfo memberInfo)
     : base(parent, parentType, memberInfo)
 {
     Construct();
 }
コード例 #15
0
 protected CollectionTypeNode(TypeNode parent, Type type)
     : base(parent, type)
 {
     Construct();
 }
コード例 #16
0
 protected ContainerTypeNode(TypeNode parent, Type type)
     : base(parent, type)
 {
 }
コード例 #17
0
 protected ContainerTypeNode(TypeNode parent, Type parentType, MemberInfo memberInfo)
     : base(parent, parentType, memberInfo)
 {
 }
コード例 #18
0
ファイル: TypeNode.cs プロジェクト: andyvans/BinarySerializer
 protected TypeNode(TypeNode parent)
     : base(parent)
 {
 }
コード例 #19
0
 public EnumTypeNode(TypeNode parent, Type parentType, MemberInfo memberInfo)
     : base(parent, parentType, memberInfo)
 {
     InitializeEnumValues();
 }
コード例 #20
0
ファイル: TypeNode.cs プロジェクト: andyvans/BinarySerializer
 protected TypeNode(TypeNode parent, Type type)
     : this(parent)
 {
     Type = type;
     NullableUnderlyingType = Nullable.GetUnderlyingType(Type);
 }
コード例 #21
0
 protected CollectionValueNode(Node parent, string name, TypeNode typeNode)
     : base(parent, name, typeNode)
 {
 }
コード例 #22
0
ファイル: TypeNode.cs プロジェクト: andyvans/BinarySerializer
        protected TypeNode(TypeNode parent, Type parentType, MemberInfo memberInfo)
            : this(parent)
        {
            if (memberInfo == null)
                return;

            Name = memberInfo.Name;

            var propertyInfo = memberInfo as PropertyInfo;
            var fieldInfo = memberInfo as FieldInfo;

            if (propertyInfo != null)
            {
                Type = propertyInfo.PropertyType;

                ValueGetter = MagicMethods.MagicFunc(parentType, propertyInfo.GetGetMethod());

                var setMethod = propertyInfo.GetSetMethod();

                if(setMethod != null)
                    ValueSetter = MagicMethods.MagicAction(parentType, setMethod);
            }
            else if (fieldInfo != null)
            {
                Type = fieldInfo.FieldType;

                ValueGetter = fieldInfo.GetValue;
                ValueSetter = fieldInfo.SetValue;
            }
            else throw new NotSupportedException(String.Format("{0} not supported", memberInfo.GetType().Name));

            NullableUnderlyingType = Nullable.GetUnderlyingType(Type);

            var attributes = memberInfo.GetCustomAttributes(true);

            IgnoreAttribute = attributes.OfType<IgnoreAttribute>().SingleOrDefault();

            /* Don't go any further if we're ignoring this. */
            if (IsIgnored)
                return;

            var fieldOrderAttribute = attributes.OfType<FieldOrderAttribute>().SingleOrDefault();
            if (fieldOrderAttribute != null)
                _order = fieldOrderAttribute.Order;

            var serializeAsAttribute = attributes.OfType<SerializeAsAttribute>().SingleOrDefault();
            if (serializeAsAttribute != null)
            {
                _serializedType = serializeAsAttribute.SerializedType;
                Endianness = serializeAsAttribute.Endianness;

                if (!String.IsNullOrEmpty(serializeAsAttribute.Encoding))
                    Encoding = Encoding.GetEncoding(serializeAsAttribute.Encoding);
            }

            FieldLengthAttribute = attributes.OfType<FieldLengthAttribute>().SingleOrDefault();
            if (FieldLengthAttribute != null)
            {
                FieldLengthBinding = new Binding(FieldLengthAttribute, GetBindingLevel(FieldLengthAttribute.Binding));
            }

            FieldCountAttribute = attributes.OfType<FieldCountAttribute>().SingleOrDefault();
            if (FieldCountAttribute != null)
            {
                FieldCountBinding = new Binding(FieldCountAttribute, FindAncestorLevel(FieldCountAttribute.Binding));
            }

            FieldOffsetAttribute = attributes.OfType<FieldOffsetAttribute>().SingleOrDefault();
            if (FieldOffsetAttribute != null)
            {
                FieldOffsetBinding = new Binding(FieldOffsetAttribute, GetBindingLevel(FieldOffsetAttribute.Binding));
            }

            var serializeWhenAttributes = attributes.OfType<SerializeWhenAttribute>().ToArray();
            SerializeWhenAttributes = new ReadOnlyCollection<SerializeWhenAttribute>(serializeWhenAttributes);

            if (SerializeWhenAttributes.Count > 0)
            {
                SerializeWhenBindings = new ReadOnlyCollection<ConditionalBinding>(
                    serializeWhenAttributes.Select(
                        attribute => new ConditionalBinding(attribute, GetBindingLevel(attribute.Binding))).ToList());
            }

            var subtypeAttributes = attributes.OfType<SubtypeAttribute>().ToArray();
            SubtypeAttributes = new ReadOnlyCollection<SubtypeAttribute>(subtypeAttributes);

            if (SubtypeAttributes.Count > 0)
            {
                var bindingGroups =
                    SubtypeAttributes.GroupBy(subtypeAttribute => subtypeAttribute.Binding);

                if (bindingGroups.Count() > 1)
                    throw new BindingException("Subtypes must all use the same binding configuration.");

                var firstBinding = SubtypeAttributes[0];
                SubtypeBinding = new Binding(firstBinding, GetBindingLevel(firstBinding.Binding));

                var valueGroups = SubtypeAttributes.GroupBy(attribute => attribute.Value);
                if (valueGroups.Count() < SubtypeAttributes.Count)
                    throw new InvalidOperationException("Subtype values must be unique.");

                if (SubtypeBinding.BindingMode == BindingMode.TwoWay)
                {
                    var subTypeGroups = SubtypeAttributes.GroupBy(attribute => attribute.Subtype);
                    if (subTypeGroups.Count() < SubtypeAttributes.Count)
                        throw new InvalidOperationException(
                            "Subtypes must be unique for two-way subtype bindings.  Set BindingMode to OneWay to disable updates to the binding source during serialization.");
                }

                var invalidSubtype =
                    SubtypeAttributes.FirstOrDefault(attribute => !Type.IsAssignableFrom(attribute.Subtype));

                if (invalidSubtype != null)
                    throw new InvalidOperationException(String.Format("{0} is not a subtype of {1}",
                        invalidSubtype.Subtype, Type));
            }

            SerializeUntilAttribute = attributes.OfType<SerializeUntilAttribute>().SingleOrDefault();
            if (SerializeUntilAttribute != null)
            {
                SerializeUntilBinding = new Binding(SerializeUntilAttribute,
                    GetBindingLevel(SerializeUntilAttribute.Binding));
            }

            ItemLengthAttribute = attributes.OfType<ItemLengthAttribute>().SingleOrDefault();
            if (ItemLengthAttribute != null)
            {
                ItemLengthBinding = new Binding(ItemLengthAttribute, GetBindingLevel(ItemLengthAttribute.Binding));
            }

            ItemSerializeUntilAttribute = attributes.OfType<ItemSerializeUntilAttribute>().SingleOrDefault();

            if (ItemSerializeUntilAttribute != null)
            {
                ItemSerializeUntilBinding = new Binding(ItemSerializeUntilAttribute,
                    GetBindingLevel(ItemSerializeUntilAttribute.Binding));
            }
        }
コード例 #23
0
 public ObjectTypeNode(TypeNode parent, Type type)
     : base(parent, type)
 {
 }
コード例 #24
0
 public StreamTypeNode(TypeNode parent, Type type)
     : base(parent, type)
 {
 }
コード例 #25
0
 public PrimitveArrayValueNode(Node parent, string name, TypeNode typeNode)
     : base(parent, name, typeNode)
 {
 }
コード例 #26
0
 public StreamTypeNode(TypeNode parent, Type parentType, MemberInfo memberInfo)
     : base(parent, parentType, memberInfo)
 {
 }
コード例 #27
0
 public ValueTypeNode(TypeNode parent, Type parentType, MemberInfo memberInfo)
     : base(parent, parentType, memberInfo)
 {
 }
コード例 #28
0
 public PrimitiveListValueNode(Node parent, string name, TypeNode typeNode)
     : base(parent, name, typeNode)
 {
 }
コード例 #29
0
 public ListTypeNode(TypeNode parent, Type parentType, MemberInfo memberInfo)
     : base(parent, parentType, memberInfo)
 {
     Construct();
 }
コード例 #30
0
 public ArrayTypeNode(TypeNode parent, Type parentType, MemberInfo memberInfo)
     : base(parent, parentType, memberInfo)
 {
     Construct();
 }