示例#1
0
        public SerializedType(Type type)
        {
            this.type = type;

            addons = null;
            args   = null;

            if (type.IsSerializable)
            {
                if (type == typeof(string))
                {
                    kind = Kind.String;
                }
                else if (type.IsArray)
                {
                    kind = Kind.Array;
                }
                else if (type.GetInterface("IEnumerable") != null && type.GetInterface("ICollection") != null && type.IsGenericType)
                {
                    kind = Kind.IEnumerable;
                }
                else if (type.GetCustomAttribute <ComVisibleAttribute>() != null)
                {
                    kind = Kind.ComVisible;
                }
                else
                {
                    kind   = Kind.Serializable;
                    addons = UField.GetUFields(type, BindingFlags.Instance | BindingFlags.Public, true).Where(p => p.GetCustomAttribute <NonSerializedAttribute>() == null).ToArray();
                }
            }
            else
            {
                kind = Kind.MySerializable;

                var fields = UField.GetUFields(type, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

                addons = fields.Where(p => p.GetCustomAttribute <AddonAttribute>() != null).ToArray();
                args   = fields.Select(p => new Tuple <UField, ConstructorArgAttribute>(p, p.GetCustomAttribute <ConstructorArgAttribute>())).Where(t => t.Item2 != null).OrderBy(t => t.Item2.position).Select(t => t.Item1).ToArray();
            }
        }
示例#2
0
 static IEnumerable <UField> GetSerializedFields(Type type)
 {
     return(UField.GetUFields(type, BindingFlags.Instance | BindingFlags.Public, true)
            .Where(f => f.GetCustomAttribute <NonSerializedAttribute>() == null));
 }
示例#3
0
 static IEnumerable <UField> GetAddons(Type type)
 {
     return(UField.GetUFields(type, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
            .Where(p => p.GetCustomAttribute <AddonAttribute>() != null));
 }
示例#4
0
 static IEnumerable <UField> GetConstructorArgs(Type type)
 {
     return(UField.GetUFields(type, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
            .Where(p => p.GetCustomAttribute <ConstructorArgAttribute>() != null)
            .OrderBy(p => p.GetCustomAttribute <ConstructorArgAttribute>().position));
 }