예제 #1
0
            public FieldInfo GetField(Type type, string name, bool instance)
            {
                var fullName = type.FullName + "." + name;

                if (!instance)
                {
                    fullName += "$static$";
                }
                if (!fieldMap.ContainsKey(fullName))
                {
                    var flag = BindingFlags.Public | BindingFlags.NonPublic;
                    flag |= (instance ? BindingFlags.Instance : BindingFlags.Static);
                    var field = CoreUtil.GetField(type, name, flag, true);
                    if (field != null && !field.IsLiteral && !field.IsInitOnly)
                    {
                        fieldMap.Add(fullName, field);
                    }
                    else
                    {
                        fieldMap.Add(fullName, null);
                    }
                }

                return(fieldMap[fullName]);
            }
예제 #2
0
            public PropertyInfo GetProp(Type type, string name, bool instance)
            {
                var fullName = type.FullName + "." + name;

                if (!instance)
                {
                    fullName += "$static$";
                }
                if (!propMap.ContainsKey(fullName))
                {
                    var flag = BindingFlags.Public | BindingFlags.NonPublic;
                    flag |= (instance ? BindingFlags.Instance : BindingFlags.Static);
                    var prop = CoreUtil.GetProperty(type, name, flag, true);
                    if (prop != null && prop.CanWrite)
                    {
                        propMap.Add(fullName, prop);
                    }
                    else
                    {
                        propMap.Add(fullName, null);
                    }
                }

                return(propMap[fullName]);
            }
예제 #3
0
            public FieldInfo[] GetFields(Type type, bool instance)
            {
                var fullName = type.FullName;

                if (!instance)
                {
                    fullName += "$static$";
                }
                if (!fieldsMap.ContainsKey(fullName))
                {
                    var list = new List <FieldInfo>();
                    var flag = BindingFlags.Public | BindingFlags.NonPublic;
                    flag |= instance ? BindingFlags.Instance : BindingFlags.Static;
                    CoreUtil.GetFields(list, type, flag, true);
                    var fields    = (IEnumerable <FieldInfo>)list;
                    var typeAttrs = type.GetCustomAttributes(typeof(PersistenceAttribute), false);
                    if (typeAttrs.Length > 0)
                    {
                        fields = fields.Where(f =>
                        {
                            var attributes = f.GetCustomAttributes(typeof(PersistentFieldAttribute), false);
                            return(attributes.Length > 0);
                        });
                    }

                    fields = fields.Where(f =>
                                          !f.IsLiteral && !f.IsInitOnly && CoreUtil.IsSafetyReflectionType(f.FieldType));
                    fieldsMap.Add(fullName, fields.ToArray());
                }

                return(fieldsMap[fullName]);
            }
예제 #4
0
            public PropertyInfo[] GetProps(Type type, bool instance)
            {
                var fullName = type.FullName;

                if (!instance)
                {
                    fullName += "$static$";
                }
                if (!propsMap.ContainsKey(fullName))
                {
                    var list = new List <PropertyInfo>();
                    var flag = BindingFlags.Public;
                    flag |= (instance ? BindingFlags.Instance : BindingFlags.Static);
                    CoreUtil.GetProperties(list, type, flag, true);
                    var props     = (IEnumerable <PropertyInfo>)list;
                    var typeAttrs = type.GetCustomAttributes(typeof(PersistenceAttribute), false);
                    if (typeAttrs.Length > 0)
                    {
                        props = props.Where(p =>
                        {
                            var attributes = p.GetCustomAttributes(typeof(PersistentFieldAttribute), false);
                            return(attributes.Length > 0);
                        });
                    }

                    props = props.Where(p => p.CanRead && p.CanWrite &&
                                        p.GetIndexParameters().Length == 0 &&
                                        CoreUtil.IsSafetyReflectionType(p.PropertyType));
                    propsMap.Add(fullName, props.ToArray());
                }

                return(propsMap[fullName]);
            }
예제 #5
0
 public Type FindType(string fullName)
 {
     if (!typeMap.ContainsKey(fullName))
     {
         typeMap.Add(fullName, CoreUtil.FindType(fullName));
     }
     return(typeMap[fullName]);
 }
예제 #6
0
 public UpdateMemberCommand(object obj, string name, object value)
 {
     mType        = obj is Type ? obj as Type : obj.GetType();
     mObj         = obj is Type ? null : obj;
     mMemberValue = value;
     mMemberName  = name;
     mMemberPath  = CoreUtil.FindMemberPath(mType, name);
     mMemberRaw   = CoreUtil.GetMemberValue(mMemberPath, mObj);
 }
예제 #7
0
        public object DeserializeArray(Type type, BinaryReader reader)
        {
            var length = reader.ReadInt32();
            var obj    = CoreUtil.CreateInstance(type, new object[] { length }) as Array;

            for (var i = 0; i < obj.Length; i++)
            {
                var index = i;
                Deserialize(reader, ret => obj.SetValue(ret, index));
            }

            return(obj);
        }
예제 #8
0
        private void InitCustomPersistence()
        {
            mCustomPersistenceMap        = new Dictionary <Type, CustomPersistence>();
            mCustomGenericPersistenceMap = new Dictionary <Type, CustomPersistence>();
            var customTypes = CoreUtil.FindSubTypes(typeof(CustomPersistence));

            foreach (var type in customTypes)
            {
                var instance = (CustomPersistence)CoreUtil.CreateInstance(type, new object[] { this });
                if (instance.persistentType.IsGenericTypeDefinition)
                {
                    mCustomGenericPersistenceMap.Add(instance.persistentType, instance);
                }
                else
                {
                    mCustomPersistenceMap.Add(instance.persistentType, instance);
                }
            }
        }
예제 #9
0
        public object DeserializeConstruction(Type type, bool instance, BinaryReader reader)
        {
            var obj        = instance ? CoreUtil.CreateInstance(type) : null;
            var fieldCount = reader.ReadInt32();

            for (var i = 0; i < fieldCount; i++)
            {
                var fieldName = reader.ReadString();
                var field     = mCache.GetField(type, fieldName, instance);
                Debug.Assert(field != null,
                             type.FullName + "." + fieldName + " is not exist or writable.");
                Deserialize(reader, ret =>
                {
                    if (field != null)
                    {
                        field.SetValue(obj, ret);
                    }
                });
            }

            var propertyCount = reader.ReadInt32();

            for (var i = 0; i < propertyCount; i++)
            {
                var propertyName = reader.ReadString();
                var property     = mCache.GetProp(type, propertyName, instance);
                Debug.Assert(property != null,
                             type.FullName + "." + propertyName + " is not exist or writable.");
                Deserialize(reader, ret =>
                {
                    if (property != null)
                    {
                        property.SetValue(obj, ret, null);
                    }
                });
            }

            return(obj);
        }
예제 #10
0
 public override void Undo()
 {
     CoreUtil.SetMemberValue(mMemberPath, mObj, mMemberRaw);
 }
예제 #11
0
 public override void Execute()
 {
     CoreUtil.SetMemberValue(mMemberPath, mObj, mMemberValue);
 }