示例#1
0
        SerializeMetadata ConvertFrom(Type type, BinaryMemberAttribute contract)
        {
            var parent = new SerializeMetadata();

            parent.ObjectType = type;
            parent.Converter  = contract.Converter;
            parent.Options    = contract.Options;
            parent.Index      = contract.Index;
            parent.IsReverse  = contract.IsReverse;
            if (contract.Length > 0)
            {
                parent.Length = contract.Length;
            }
            else
            {
                parent.Length = base.SizeOf(parent.ObjectType);
            }
            return(parent);
        }
示例#2
0
        SerializeMetadata GetOneSerializeMetadata(object p)
        {
            BinaryMemberAttribute attr = null;
            Type type = null;

            if (p is Type)
            {
                type = (Type)p;
                attr = type.GetCustomAttribute <BinaryMemberAttribute>(true);
            }
            else if (p is PropertyInfo)
            {
                attr = ((PropertyInfo)p).GetCustomAttribute <BinaryMemberAttribute>();
                type = ((PropertyInfo)p).PropertyType;
            }
            SerializeMetadata metadata = null;

            if (attr == null)
            {
                if (this.Strict)
                {
                    return(metadata);
                }
                else
                {
                    metadata = new SerializeMetadata {
                        ObjectType = type
                    };
                }
            }
            else
            {
                metadata = ConvertFrom(type, attr);
            }
            return(metadata);
        }