/// <summary> /// Add properties to an existing EditInterface. /// </summary> /// <param name="scanner"></param> /// <param name="target"></param> /// <param name="edit"></param> private static void addProperties(MemberScanner scanner, Object target, Type startType, EditInterface edit, ReflectedEditablePropertyProvider customPropProvider) { IEnumerable <MemberWrapper> members = scanner.getMatchingMembers(startType); foreach (MemberWrapper memberWrapper in members) { if (!customPropProvider.addProperties(memberWrapper, target, edit)) { EditableAttribute editable = findEditableAttribute(memberWrapper); bool addAsProperty = (editable != null && editable.ForceAsProperty) || ReflectedVariable.canCreateVariable(memberWrapper.getWrappedType()); if (addAsProperty) { edit.addEditableProperty(editable.createEditableProperty(memberWrapper, target)); } else { Object subObject = memberWrapper.getValue(target, null); if (subObject is EditInterfaceOverride) { EditInterfaceOverride custom = (EditInterfaceOverride)subObject; edit.addSubInterface(custom.getEditInterface(memberWrapper.getWrappedName(), scanner)); } else if (subObject != null) { edit.addSubInterface(createEditInterface(subObject, scanner, memberWrapper.getWrappedName() + " - " + memberWrapper.getWrappedType(), null)); } } } } }
/// <summary> /// Save an object to a SaveInfo. /// </summary> /// <param name="source">The source object to save.</param> /// <param name="info">The info to save the object to.</param> /// <param name="scanner">The MemberScanner to use to save the object.</param> public static void SaveObject(Object source, SaveInfo info, MemberScanner scanner) { foreach (MemberWrapper wrapper in scanner.getMatchingMembers(source.GetType())) { info.AddReflectedValue(wrapper.getWrappedName(), wrapper.getValue(source, null), wrapper.getWrappedType()); } }
/// <summary> /// Restore an object from a LoadInfo. /// </summary> /// <param name="source">The object to restore values to.</param> /// <param name="info">The LoadInfo with the values to restore.</param> /// <param name="scanner">A MemberScanner to use to restore the object.</param> public static void RestoreObject(Object source, LoadInfo info, MemberScanner scanner) { foreach (MemberWrapper wrapper in scanner.getMatchingMembers(source.GetType())) { if (info.hasValue(wrapper.getWrappedName())) { wrapper.setValue(source, info.getValueObject(wrapper.getWrappedName()), null); } } }
/// <summary> /// Constructor. /// </summary> /// <param name="target">The target object.</param> /// <param name="scanner">The MemberScanner to use to learn about target.</param> public ReflectedObjectEditableProperty(Object target, MemberScanner scanner) { this.target = target; this.memberScanner = scanner; IEnumerable <MemberWrapper> matches = memberScanner.getMatchingMembers(target.GetType()); variableList = new List <ReflectedVariable>(); foreach (MemberWrapper wrapper in matches) { if (ReflectedVariable.canCreateVariable(wrapper.getWrappedType())) { variableList.Add(ReflectedVariable.createVariable(wrapper, target)); } } }
/// <summary> /// Constructor. /// </summary> /// <param name="name">A name for this interface.</param> /// <param name="collection">The collection that has the elements this interface will hold.</param> /// <param name="scanner">A MemberScanner to discover the properties of T with.</param> public ReflectedCollectionEditInterface(String name, IEnumerable <T> collection, MemberScanner scanner) { this.memberScanner = scanner; this.name = name; IEnumerable <MemberWrapper> matches = memberScanner.getMatchingMembers(typeof(T)); foreach (MemberWrapper wrapper in matches) { if (ReflectedVariable.canCreateVariable(wrapper.getWrappedType())) { propertyInfo.addColumn(new EditablePropertyColumn(wrapper.getWrappedName(), false)); } } foreach (T item in collection) { addItem(item); } }