public MySerializeInfo(SerializeAttribute attribute, MySerializeInfo keyInfo, MySerializeInfo itemInfo)
 {
     if (attribute != null)
     {
         Flags = attribute.Flags;
         PrimitiveFlags = attribute.PrimitiveFlags;
         FixedLength = attribute.FixedLength;
         if (IsDynamic)
         {
             Debug.Assert(attribute.DynamicSerializerType != null, "DynamicSerializerType must be set when serializing dynamically!");
             DynamicSerializer = ((IDynamicResolver)Activator.CreateInstance(attribute.DynamicSerializerType)).Serialize;
         }
     }
     KeyInfo = keyInfo;
     ItemInfo = itemInfo;
 }
Exemplo n.º 2
0
 public MySerializeInfo(SerializeAttribute attribute, MySerializeInfo keyInfo, MySerializeInfo itemInfo)
 {
     if (attribute != null)
     {
         Flags          = attribute.Flags;
         PrimitiveFlags = attribute.PrimitiveFlags;
         FixedLength    = attribute.FixedLength;
         if (IsDynamic)
         {
             Debug.Assert(attribute.DynamicSerializerType != null, "DynamicSerializerType must be set when serializing dynamically!");
             DynamicSerializer = ((IDynamicResolver)Activator.CreateInstance(attribute.DynamicSerializerType)).Serialize;
         }
     }
     KeyInfo  = keyInfo;
     ItemInfo = itemInfo;
 }
        public static MySerializeInfo Create(ICustomAttributeProvider reflectionInfo)
        {
            SerializeAttribute def = new SerializeAttribute();
            SerializeAttribute key = null;
            SerializeAttribute item = null;

            foreach (SerializeAttribute attr in reflectionInfo.GetCustomAttributes(typeof(SerializeAttribute), false))
            {
                if (attr.Kind == MySerializeKind.Default)
                    def = Merge(def, attr);
                else if (attr.Kind == MySerializeKind.Key)
                    key = Merge(key, attr);
                else if (attr.Kind == MySerializeKind.Item)
                    item = Merge(item, attr);
            }
            return new MySerializeInfo(def, ToInfo(key), ToInfo(item));
        }
Exemplo n.º 4
0
        static SerializeAttribute Merge(SerializeAttribute first, SerializeAttribute second)
        {
            if (first == null)
            {
                return(second);
            }
            else if (second == null)
            {
                return(first);
            }
            Debug.Assert(first.FixedLength == second.FixedLength || first.FixedLength == 0 || second.FixedLength == 0, "Two instances of SerializeAttribute sets different non-zero fixed length!");
            Debug.Assert(first.DynamicSerializerType == second.DynamicSerializerType || first.DynamicSerializerType == null || second.DynamicSerializerType == null, "Two instances of SerializeAttribute sets different non-null DynamicSerializerType");

            SerializeAttribute result = new SerializeAttribute();

            result.Flags                 = first.Flags | second.Flags;
            result.PrimitiveFlags        = first.PrimitiveFlags | second.PrimitiveFlags;
            result.FixedLength           = first.FixedLength != 0 ? first.FixedLength : second.FixedLength;
            result.DynamicSerializerType = first.DynamicSerializerType ?? second.DynamicSerializerType;
            return(result);
        }
Exemplo n.º 5
0
        public static MySerializeInfo Create(ICustomAttributeProvider reflectionInfo)
        {
            SerializeAttribute def  = new SerializeAttribute();
            SerializeAttribute key  = null;
            SerializeAttribute item = null;

            foreach (SerializeAttribute attr in reflectionInfo.GetCustomAttributes(typeof(SerializeAttribute), false))
            {
                if (attr.Kind == MySerializeKind.Default)
                {
                    def = Merge(def, attr);
                }
                else if (attr.Kind == MySerializeKind.Key)
                {
                    key = Merge(key, attr);
                }
                else if (attr.Kind == MySerializeKind.Item)
                {
                    item = Merge(item, attr);
                }
            }
            return(new MySerializeInfo(def, ToInfo(key), ToInfo(item)));
        }
Exemplo n.º 6
0
 static MySerializeInfo ToInfo(SerializeAttribute attr)
 {
     return(attr != null ? new MySerializeInfo(attr, null, null) : null);
 }
 static MySerializeInfo ToInfo(SerializeAttribute attr)
 {
     return attr != null ? new MySerializeInfo(attr, null, null) : null;
 }
        static SerializeAttribute Merge(SerializeAttribute first, SerializeAttribute second)
        {
            if (first == null) return second;
            else if (second == null) return first;
            Debug.Assert(first.FixedLength == second.FixedLength || first.FixedLength == 0 || second.FixedLength == 0, "Two instances of SerializeAttribute sets different non-zero fixed length!");
            Debug.Assert(first.DynamicSerializerType == second.DynamicSerializerType || first.DynamicSerializerType == null || second.DynamicSerializerType == null, "Two instances of SerializeAttribute sets different non-null DynamicSerializerType");

            SerializeAttribute result = new SerializeAttribute();
            result.Flags = first.Flags | second.Flags;
            result.PrimitiveFlags = first.PrimitiveFlags | second.PrimitiveFlags;
            result.FixedLength = first.FixedLength != 0 ? first.FixedLength : second.FixedLength;
            result.DynamicSerializerType = first.DynamicSerializerType ?? second.DynamicSerializerType;
            return result;
        }