Example #1
0
        public Match(object instance, IFieldModifier fieldModifier)
        {
            this.path          = fieldModifier.Name;
            this.instance      = instance;
            this.fieldModifier = fieldModifier;

            this.type = this.fieldModifier.Type;
        }
Example #2
0
        public MemberCommand(IFieldModifier member, object instance) : base(instance, member.Name, string.Empty)
        {
            this.member      = member;
            this.constraints = member.GetCustomAttributes(typeof(PropertyConstraintAttribute), true) as PropertyConstraintAttribute[];

            if (this.member.Type.IsClass() == true &&
                this.member.Type != typeof(string))
            {
                throw new NotSupportedMemberTypeException(this.member);
            }
        }
Example #3
0
        public MonitorArray(string path, IFieldModifier fieldInfo, Func <object> getInstance) : base(path, getInstance)
        {
            this.sizeHandler = TypeHandlersManager.GetTypeHandler(typeof(int));
            this.fieldInfo   = fieldInfo;
            this.lastSize    = this.GetSize();

            object instance = this.fieldInfo.GetValue(this.getInstance());

            if (instance != null)
            {
                this.MonitorSubData(instance.GetType(), () => this.fieldInfo.GetValue(this.getInstance()));
            }
        }
Example #4
0
        public MemberDrawer(TypeDrawer typeDrawer, IFieldModifier fieldModifier)
        {
            this.typeDrawer    = typeDrawer;
            this.fieldModifier = fieldModifier;

            if (this.fieldModifier is FieldModifier)
            {
                FieldModifier modifier = (this.fieldModifier as FieldModifier);

                this.isEditable = modifier.fieldInfo.IsLiteral == false && modifier.fieldInfo.IsInitOnly == false;
            }
            else
            {
                this.isEditable = (this.fieldModifier as PropertyModifier).propertyInfo.GetSetMethod() != null;
            }
        }
Example #5
0
        public IFieldModifier[] GetFields()
        {
            FieldInfo[]      fields     = this.GetFieldInfos();
            PropertyInfo[]   properties = this.GetPropertyInfos();
            IFieldModifier[] result     = new IFieldModifier[fields.Length + properties.Length];
            int i = 0;

            for (; i < fields.Length; ++i)
            {
                result[i] = new FieldModifier(fields[i]);
            }

            for (int j = 0; j < properties.Length; ++j, ++i)
            {
                result[i] = new PropertyModifier(properties[j]);
            }

            return(result);
        }
Example #6
0
        public static void      Serialize(ByteBuffer buffer, object instance, IFieldModifier field)
        {
            using (SafeWrapByteBuffer.Get(buffer))
            {
                buffer.AppendUnicodeString(field.Type.GetShortAssemblyType());
                buffer.AppendUnicodeString(field.Name);
                buffer.Append(field.IsPublic);

                TypeHandler handler = TypeHandlersManager.GetTypeHandler(field.Type);

                if (handler != null)
                {
                    if (field.MemberInfo.DeclaringType.IsGenericTypeDefinition == false || ((field is FieldModifier) == true && (field as FieldModifier).fieldInfo.IsLiteral == true))
                    {
                        buffer.AppendUnicodeString(handler.GetType().GetShortAssemblyType());

                        try
                        {
                            buffer.Append((byte)TypeHandlersManager.GetTypeSignature(field.Type));

                            ByteBuffer handlerBuffer = Utility.GetBBuffer();
                            handler.Serialize(handlerBuffer, field.Type, field.GetValue(instance));
                            buffer.Append(Utility.ReturnBBuffer(handlerBuffer));
                        }
                        catch (Exception ex)
                        {
                            buffer.Append((byte)TypeSignature.Null);
                            InternalNGDebug.LogException("Member \"" + field.Name + "\" failed.", ex);
                            throw;
                        }
                    }
                    else                     // Leave it unsupported.
                    {
                        buffer.Append(0);
                    }
                }
                else
                {
                    buffer.Append(0);
                }
            }
        }
Example #7
0
            private ImportNode(ImportNode parent, SettingsExporter.Node node, Type workingType, object workingInstance)
            {
                this.parent = parent;
                this.node   = node;

                // Instance is null only when the parent is an array.
                this.instanceType = workingType;
                // Look for class.
                //if (this.instanceType.FullName == node.name)
                //	this.instance = instance;
                // Look for array element.
                if (typeof(IEnumerable).IsAssignableFrom(this.instanceType) == true)
                {
                    this.arrayElementType = Type.GetType(node.name);

                    if (this.arrayElementType == null)
                    {
                        Debug.LogWarning("Type \"" + node.name + "\" was not recognized.");
                    }
                    else
                    {
                        foreach (ExportableAttribute attribute in this.arrayElementType.EachCustomAttributesIncludingBaseInterfaces <ExportableAttribute>())
                        {
                            this.arrayExportOptions = attribute.options;

                            if ((attribute.options & ExportableAttribute.ArrayOptions.Add) != 0)
                            {
                                this.arrayImportOption = ArrayImportOption.Add;
                            }
                            else if ((attribute.options & ExportableAttribute.ArrayOptions.Overwrite) != 0)
                            {
                                this.arrayImportOption = ArrayImportOption.Overwrite;
                            }
                        }
                    }

                    this.instance     = null;
                    this.instanceType = this.arrayElementType;

                    if (workingInstance != null)
                    {
                        IEnumerable array = workingInstance as IEnumerable;

                        foreach (var item in array)
                        {
                            if (item.GetType() == this.arrayElementType &&
                                ImportSettingsWizard.trackObjects.Contains(item) == false)
                            {
                                this.instance = item;
                                ImportSettingsWizard.trackObjects.Add(item);
                                break;
                            }
                        }
                    }

                    //if (this.instance == null)
                    //	this.instance = Activator.CreateInstance(this.arrayElementType);
                }
                // Look for field.
                else
                {
                    FieldInfo fieldInfo = this.instanceType.GetField(node.name, SettingsExporter.SearchFlags);

                    if (fieldInfo != null)
                    {
                        if (fieldInfo.IsDefined(typeof(HideFromExportAttribute), true) == true)
                        {
                            node.options = SettingsExporter.Node.Option.Hidden;
                        }

                        this.fieldInfo = new FieldModifier(fieldInfo);

                        if (this.fieldInfo.IsDefined(typeof(ExportableAttribute), true) == true)
                        {
                            this.arrayExportOptions = (this.fieldInfo.GetCustomAttributes(typeof(ExportableAttribute), true)[0] as ExportableAttribute).options;

                            this.instanceType = this.fieldInfo.Type;

                            if (workingInstance != null)
                            {
                                this.instance = this.fieldInfo.GetValue(workingInstance);
                            }
                        }
                    }
                    else
                    {
                        PropertyInfo propertyInfo = this.instanceType.GetProperty(node.name, SettingsExporter.SearchFlags);

                        if (propertyInfo == null)
                        {
                            Debug.LogWarning("Name \"" + node.name + "\" was not found in " + this.instanceType.FullName + ".");
                        }
                        else
                        {
                            if (propertyInfo.IsDefined(typeof(HideFromExportAttribute), true) == true)
                            {
                                node.options = SettingsExporter.Node.Option.Hidden;
                            }

                            this.fieldInfo = new PropertyModifier(propertyInfo);

                            if (this.fieldInfo.IsDefined(typeof(ExportableAttribute), true) == true)
                            {
                                this.arrayExportOptions = (this.fieldInfo.GetCustomAttributes(typeof(ExportableAttribute), true)[0] as ExportableAttribute).options;

                                this.instanceType = this.fieldInfo.Type;

                                if (workingInstance != null)
                                {
                                    this.instance = this.fieldInfo.GetValue(workingInstance);
                                }
                            }
                        }
                    }
                    //else
                    //	Debug.LogWarning("Field \"" + node.name + "\" is not decorated with the attribute \"" + typeof(ExportableAttribute) + "\" in " + this.instanceType.FullName + ".");
                }

                //if (this.instance != null)
                //{
                this.children = new ImportNode[node.children.Count];
                for (int i = 0; i < this.children.Length; i++)
                {
                    this.children[i] = new ImportNode(this, node.children[i], this.instanceType, this.instance);
                }
                //}
                //else
                //	this.children = new ImportNode[0];
            }
Example #8
0
        private void    CopyObject(StringBuilder buffer, object instance, string prefix)
        {
            if (instance != null)
            {
                Type     type = instance.GetType();
                object[] actions;

                if (this.typeDrawers.TryGetValue(type, out actions) == true)
                {
                    buffer.AppendLine((actions[1] as Func <object, string, string>)(instance, prefix));
                }
                else
                {
                    if (instance.GetType().IsArray == true)
                    {
                        IEnumerable array = instance as IEnumerable;

                        foreach (object element in array)
                        {
                            this.CopyObject(buffer, element, "  ");
                        }
                    }
                    else if (type != typeof(string) &&
                             (type.IsClass == true || type.IsStruct() == true))
                    {
                        ClassDefinition classDefinition;

                        if (this.refMembers.TryGetValue(type, out classDefinition) == false)
                        {
                            int              j          = 0;
                            FieldInfo[]      fields     = type.GetFields(BindingFlags.Public | BindingFlags.Instance);
                            PropertyInfo[]   properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
                            IFieldModifier[] members    = new IFieldModifier[fields.Length + properties.Length];

                            for (int i = 0; i < fields.Length; i++, ++j)
                            {
                                members[j] = new FieldModifier(fields[i]);
                            }

                            for (int i = 0; i < properties.Length; i++, ++j)
                            {
                                members[j] = new PropertyModifier(properties[i]);
                            }

                            classDefinition = new ClassDefinition(members);

                            this.refMembers.Add(type, classDefinition);
                        }

                        for (int i = 0; i < classDefinition.members.Length; i++)
                        {
                            this.CopyObject(buffer, classDefinition.members[i].GetValue(instance), "  " + classDefinition.nicifiedNames[i] + " : ");
                        }
                    }
                    else
                    {
                        buffer.AppendLine(prefix + instance.ToString());
                    }
                }
            }
            else
            {
                buffer.AppendLine(prefix + "NULL");
            }
        }
Example #9
0
        private object  SetValue(string path, object instance, string name, object value)
        {
            IFieldModifier field = InnerUtility.GetFieldInfo(instance.GetType(), name);

            InternalNGDebug.Assert(field != null, "Field \"" + name + "\" was not found in type \"" + instance.GetType() + "\".");
            object fieldValue = field.GetValue(instance);

            UnityObject uo = value as UnityObject;

            if (uo != null)
            {
                field.SetValue(instance, this.TryFetchFromProject(path, uo));
                return(instance);
            }

            ClientClass gc = value as ClientClass;

            if (gc != null)
            {
                if (fieldValue == null)
                {
                    fieldValue = Activator.CreateInstance(field.Type);
                }

                IncompleteGameObjectException incompleteEx = null;

                for (int j = 0; j < gc.fields.Length; j++)
                {
                    FieldInfo subField = field.Type.GetField(gc.fields[j].name);
                    InternalNGDebug.Assert(subField != null, "Field \"" + gc.fields[j].name + "\" was not found in type \"" + field.Type + "\".");

                    if (subField.IsLiteral == true)
                    {
                        continue;
                    }

                    try
                    {
                        fieldValue = this.SetValue(path + '.' + gc.fields[j].name, fieldValue, gc.fields[j].name, gc.fields[j].value);
                    }
                    catch (IncompleteGameObjectException ex)
                    {
                        if (incompleteEx == null)
                        {
                            incompleteEx = ex;
                        }
                        else
                        {
                            incompleteEx.Aggregate(ex);
                        }
                    }
                }

                if (incompleteEx != null)
                {
                    throw incompleteEx;
                }

                field.SetValue(instance, fieldValue);

                return(instance);
            }

            ArrayData a = value as ArrayData;

            if (a != null)
            {
                if (a.array != null)
                {
                    Type subType = Utility.GetArraySubType(field.Type);
                    if (fieldValue == null)
                    {
                        fieldValue = Array.CreateInstance(subType, a.array.Length);
                    }

                    if (field.Type.IsArray == true)
                    {
                        IncompleteGameObjectException incompleteEx = null;
                        Array fieldArray = fieldValue as Array;

                        if (fieldArray.Length != a.array.Length)
                        {
                            fieldValue = Array.CreateInstance(subType, a.array.Length);
                            fieldArray = fieldValue as Array;
                        }

                        for (int j = 0; j < a.array.Length; j++)
                        {
                            try
                            {
                                fieldArray.SetValue(this.ConvertValue(path + "#" + j, subType, a.array.GetValue(j)), j);
                            }
                            catch (IncompleteGameObjectException ex)
                            {
                                if (incompleteEx == null)
                                {
                                    incompleteEx = ex;
                                }
                                else
                                {
                                    incompleteEx.Aggregate(ex);
                                }
                            }
                        }

                        if (incompleteEx != null)
                        {
                            throw incompleteEx;
                        }
                    }
                    else if (typeof(IList).IsAssignableFrom(field.Type) == true)
                    {
                        IncompleteGameObjectException incompleteEx = null;
                        IList fieldArray = fieldValue as IList;

                        for (int j = 0; j < a.array.Length; j++)
                        {
                            try
                            {
                                fieldArray[j] = this.ConvertValue(path + "#" + j, subType, a.array.GetValue(j));
                            }
                            catch (IncompleteGameObjectException ex)
                            {
                                if (incompleteEx == null)
                                {
                                    incompleteEx = ex;
                                }
                                else
                                {
                                    incompleteEx.Aggregate(ex);
                                }
                            }
                        }

                        if (incompleteEx != null)
                        {
                            throw incompleteEx;
                        }
                    }
                    else
                    {
                        throw new InvalidCastException("Type \"" + field.Type + "\" is not supported as an array.");
                    }

                    field.SetValue(instance, fieldValue);
                }

                return(instance);
            }

            EnumInstance e = value as EnumInstance;

            if (e != null)
            {
                field.SetValue(instance, e.value);
            }
            else
            {
                field.SetValue(instance, value);
            }

            return(instance);
        }
 public NotSupportedMemberTypeException(IFieldModifier type)
 {
     this.member = type;
 }