Exemplo n.º 1
0
        static Type Bind(UField field, ref object obj)
        {
            Type binder = Bind(field);

            if (binder != field.fieldType)
            {
                return(Bind(ref obj, binder));
            }
            else
            {
                return(binder);
            }
        }
Exemplo n.º 2
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();
            }
        }
Exemplo n.º 3
0
 public FieldObject(UField field, object value)
 {
     bvalue = value;
     btype  = Bind(field, ref bvalue);
 }
Exemplo n.º 4
0
 static IEnumerable <UField> GetSerializedFields(Type type)
 {
     return(UField.GetUFields(type, BindingFlags.Instance | BindingFlags.Public, true)
            .Where(f => f.GetCustomAttribute <NonSerializedAttribute>() == null));
 }
Exemplo n.º 5
0
 static IEnumerable <UField> GetAddons(Type type)
 {
     return(UField.GetUFields(type, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
            .Where(p => p.GetCustomAttribute <AddonAttribute>() != null));
 }
Exemplo n.º 6
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));
 }
Exemplo n.º 7
0
        static Type Bind(UField field)
        {
            var attr = field.GetCustomAttribute <SerializeBinderAttribute>();

            return(attr != null ? attr.binder : Bind(field.fieldType));
        }