/// <inheritdoc/> protected override bool CanInsertItem(IObjectNode collection, NodeIndex index, object newItem) { if (collection.Type != typeof(EntityComponentCollection)) { return(base.CanInsertItem(collection, index, newItem)); } if (newItem == null) { return(false); } var componentType = newItem.GetType(); if (!EntityComponentAttributes.Get(componentType).AllowMultipleComponents) { // Cannot insert components that disallow multiple components var components = (EntityComponentCollection)collection.Retrieve(); if (components.Any(x => x.GetType() == componentType)) { return(false); } } return(base.CanInsertItem(collection, index, newItem)); }
/// <inheritdoc/> protected override bool CanReplaceItem(IObjectNode collection, NodeIndex index, object newItem) { if (collection.Type != typeof(EntityComponentCollection)) { return(base.CanReplaceItem(collection, index, newItem)); } if (newItem == null) { return(false); } var componentType = newItem.GetType(); // Cannot replace the transform component by another type of component if (collection.IndexedTarget(index).Type == typeof(TransformComponent) && componentType != typeof(TransformComponent)) { return(false); } if (!EntityComponentAttributes.Get(componentType).AllowMultipleComponents) { // Cannot replace components that disallow multiple components, unless it is that specific component we're replacing var components = (EntityComponentCollection)collection.Retrieve(); if (components.Where((x, i) => x.GetType() == componentType && i != index.Int).Any()) { return(false); } } return(base.CanReplaceItem(collection, index, newItem)); }
public GraphicsCompositorCameraSlotsViewModel([NotNull] GraphicsCompositorEditorViewModel editor, SceneCameraSlot cameraSlot) : base(editor) { CameraSlot = cameraSlot; cameraSlotNode = editor.Session.AssetNodeContainer.GetOrCreateNode(cameraSlot); nameNodeBinding = new MemberGraphNodeBinding <string>(cameraSlotNode[nameof(CameraSlot.Name)], nameof(Name), OnPropertyChanging, OnPropertyChanged, editor.UndoRedoService); }
public void SetValue(PatchContext context, object parent, IObjectNode patch) { var instance = this.FieldInfo.GetValue(parent); this.Patcher.PatchTo(context, ref instance, patch); this.FieldInfo.SetValue(parent, instance); }
protected override void VisitChildren(IObjectNode node) { if (VisitedLinks.TryGetValue(node, out IGraphNode targetNodeParent)) { var objNode = targetNodeParent as IObjectNode; var members = node.Members; if (members is List <IMemberNode> asList) { foreach (var child in asList) { VisitedLinks.Add(child, objNode?.TryGetChild(child.Name)); } } else if (members is Dictionary <string, IMemberNode> .ValueCollection asVCol) { foreach (var child in asVCol) { VisitedLinks.Add(child, objNode?.TryGetChild(child.Name)); } } else { foreach (var child in members) { VisitedLinks.Add(child, objNode?.TryGetChild(child.Name)); } } } base.VisitChildren(node); }
public GraphicsCompositorEditorViewModel([NotNull] GraphicsCompositorViewModel graphicsCompositor) : base(graphicsCompositor) { // Create the service needed to manage observable view models ViewModelService = new GraphViewModelService(Session.AssetNodeContainer); // Update the service provider of this view model to contains the ObservableViewModelService we created. ServiceProvider = new ViewModelServiceProvider(ServiceProvider, ViewModelService.Yield()); // Get some quantum nodes graphicsCompositorNode = Session.AssetNodeContainer.GetNode(graphicsCompositor.Asset); renderStagesNode = graphicsCompositorNode[nameof(GraphicsCompositorAsset.RenderStages)].Target; renderFeaturesNode = graphicsCompositorNode[nameof(GraphicsCompositorAsset.RenderFeatures)].Target; cameraSlotsNode = graphicsCompositorNode[nameof(GraphicsCompositorAsset.Cameras)].Target; sharedRenderersNode = graphicsCompositorNode[nameof(GraphicsCompositorAsset.SharedRenderers)].Target; // Setup commands DeleteSelectionCommand = new AnonymousCommand(ServiceProvider, DeleteSelection); AddNewRenderStageCommand = new AnonymousCommand(ServiceProvider, AddNewRenderStage); RemoveSelectedRenderStagesCommand = new AnonymousCommand(ServiceProvider, RemoveSelectedRenderStages); AddNewRenderFeatureCommand = new AnonymousCommand <AbstractNodeType>(ServiceProvider, AddNewRenderFeature); RemoveSelectedRenderFeaturesCommand = new AnonymousCommand(ServiceProvider, RemoveSelectedRenderFeatures); AddNewCameraSlotCommand = new AnonymousCommand(ServiceProvider, AddNewCameraSlot); RemoveSelectedCameraSlotsCommand = new AnonymousCommand(ServiceProvider, RemoveSelectedCameraSlots); }
public AssetMemberNode([NotNull] INodeBuilder nodeBuilder, Guid guid, [NotNull] IObjectNode parent, [NotNull] IMemberDescriptor memberDescriptor, IReference reference) : base(nodeBuilder, guid, parent, memberDescriptor, reference) { ValueChanged += ContentChanged; IsNonIdentifiableCollectionContent = MemberDescriptor.GetCustomAttributes <NonIdentifiableCollectionItemsAttribute>(true)?.Any() ?? false; CanOverride = MemberDescriptor.GetCustomAttributes <NonOverridableAttribute>(true)?.Any() != true; }
public void PatchTo(PatchContext context, ref object obj, IObjectNode patch) { if (obj == null) { return; } if (patch.IsNull) { return; } if (patch.Type != NodeType.Complex) { return; } if (obj.GetType() != this.type) { return; } foreach (var node in patch.Children) { if (node.Type != NodeType.Int) { continue; } if (!propDict.TryGetValue(node.Name, out var prop)) { continue; } prop.SetValue(obj, node.Value); } }
/// <summary> /// Visits the <see cref="ReferenceEnumerable"/> contained in the given node, if any. /// </summary> /// <param name="node">The node being visited.</param> protected virtual void VisitItemTargets([NotNull] IObjectNode node) { if (node == null) { throw new ArgumentNullException(nameof(node)); } var enumerableReference = node.ItemReferences; if (enumerableReference != null) { foreach (var reference in enumerableReference) { if (reference.TargetNode == null) { continue; } if (ShouldVisitTargetItem(node, reference.Index)) { CurrentPath.PushIndex(reference.Index); VisitReference(node, reference); CurrentPath.Pop(); } } } }
/// <summary> /// Collects all assets referenced by the object in the given node. /// </summary> /// <param name="root">The root node to visit to collect assets.</param> /// <returns>A collection containing all assets found by visiting the given root.</returns> public static IReadOnlyDictionary <GraphNodePath, Asset> Collect([NotNull] IObjectNode root) { var visitor = new AssetCollector(); visitor.Visit(root); return(visitor.assets); }
public ObjectGraphNodeBinding([NotNull] IObjectNode node, string propertyName, PropertyChangeDelegate propertyChanging, PropertyChangeDelegate propertyChanged, [NotNull] Func <TTargetType, TContentType> converter, IUndoRedoService actionService, bool notifyChangesOnly = true) : base(propertyName, propertyChanging, propertyChanged, converter, actionService, notifyChangesOnly) { Node = node; node.ItemChanged += ValueChanged; node.ItemChanging += ValueChanging; }
public EntityViewModel([NotNull] EntityHierarchyEditorViewModel editor, [NotNull] EntityHierarchyViewModel asset, [NotNull] EntityDesign entityDesign) : base(editor, asset, GetOrCreateChildPartDesigns((EntityHierarchyAssetBase)asset.Asset, entityDesign), entityDesign.Entity) { if (entityDesign.Entity == null) { throw new ArgumentException(@"entity must contain a non-null asset entity.", nameof(entityDesign)); } EntityDesign = entityDesign; var assetNode = Editor.NodeContainer.GetOrCreateNode(entityDesign.Entity); nameNodeBinding = new MemberGraphNodeBinding <string>(assetNode[nameof(Entity.Name)], nameof(Name), OnPropertyChanging, OnPropertyChanged, Editor.UndoRedoService); componentsNodeBinding = new ObjectGraphNodeBinding <EntityComponentCollection>(assetNode[nameof(Entity.Components)].Target, nameof(Components), OnPropertyChanging, OnPropertyChanged, Editor.UndoRedoService, false); modelComponent = new ModelComponentViewModel(ServiceProvider, this); particleComponent = new ParticleSystemComponentViewModel(ServiceProvider, this); cameraComponent = new CameraComponentViewModel(ServiceProvider, this); transformationNode = Editor.NodeContainer.GetNode(AssetSideEntity.Transform)[nameof(TransformComponent.Children)].Target; transformationNode.ItemChanging += TransformChildrenChanging; transformationNode.ItemChanged += TransformChildrenChanged; RenameCommand = new AnonymousCommand(ServiceProvider, () => IsEditing = true); FocusOnEntityCommand = new AnonymousCommand(ServiceProvider, FocusOnEntity); UpdateSourcePrefab(); var basePrefabNode = Editor.NodeContainer.GetNode(EntityDesign)[nameof(EntityDesign.Base)]; basePrefabNode.ValueChanged += BasePrefabChanged; }
internal IObjectNode SetTarget(IObjectNode targetNode) { if (targetNode != null) { var targetValue = targetNode.Retrieve(); if (targetValue != null && !type.IsInstanceOfType(targetValue)) { throw new InvalidOperationException(@"The type of the retrieved node content does not match the type of this reference"); } if (targetValue != null && !type.IsInstanceOfType(targetValue)) { throw new InvalidOperationException("TargetNode type does not match the reference type."); } TargetNode = targetNode; TargetGuid = targetNode.Guid; } else { TargetNode = null; TargetGuid = Guid.Empty; } return(targetNode); }
public ItemNodePresenter([NotNull] INodePresenterFactoryInternal factory, IPropertyProviderViewModel propertyProvider, [NotNull] INodePresenter parent, [NotNull] IObjectNode container, Index index) : base(factory, propertyProvider, parent) { if (factory == null) { throw new ArgumentNullException(nameof(factory)); } if (parent == null) { throw new ArgumentNullException(nameof(parent)); } Container = container ?? throw new ArgumentNullException(nameof(container)); Descriptor = TypeDescriptorFactory.Default.Find(container.Descriptor.GetInnerCollectionType()); OwnerCollection = parent; Type = (container.Descriptor as CollectionDescriptor)?.ElementType ?? (container.Descriptor as DictionaryDescriptor)?.ValueType; Index = index; Name = index.ToString(); Order = index.IsInt ? (int?)index.Int : null; // So items are sorted by index instead of string CombineKey = Name; DisplayName = Index.IsInt ? "Item " + Index : Index.ToString(); container.ItemChanging += OnItemChanging; container.ItemChanged += OnItemChanged; AttachCommands(); }
/// <summary> /// Initializes a new instance of the <see cref="ItemChangeEventArgs"/> class. /// </summary> /// <param name="node">The node that has changed.</param> /// <param name="index">The index in the member where the change occurred.</param> /// <param name="changeType">The type of change that occurred.</param> /// <param name="oldValue">The old value of the item that has changed.</param> /// <param name="newValue">The new value of the item that has changed.</param> public ItemChangeEventArgs([NotNull] IObjectNode node, NodeIndex index, ContentChangeType changeType, object oldValue, object newValue) { Collection = node; Index = index; ChangeType = changeType; OldValue = oldValue; NewValue = newValue; }
protected virtual KeyFrameControlPointViewModel <TValue> CreateControlPoint([NotNull] IObjectNode node) { var keyNode = node[nameof(AnimationKeyFrame <TValue> .Key)]; var valueNode = node[nameof(AnimationKeyFrame <TValue> .Value)]; var tangentTypeNode = node[nameof(AnimationKeyFrame <TValue> .TangentType)]; return(CreateKeyFrameControlPoint(keyNode, valueNode, tangentTypeNode)); }
public RenderStageViewModel([NotNull] GraphicsCompositorEditorViewModel editor, RenderStage renderStage) : base(editor) { RenderStage = renderStage; renderStageNode = editor.Session.AssetNodeContainer.GetOrCreateNode(renderStage); nameNodeBinding = new MemberGraphNodeBinding <string>(renderStageNode[nameof(RenderStage.Name)], nameof(Name), OnPropertyChanging, OnPropertyChanged, editor.UndoRedoService); effectSlotNodeBinding = new MemberGraphNodeBinding <string>(renderStageNode[nameof(RenderStage.EffectSlotName)], nameof(EffectSlotName), OnPropertyChanging, OnPropertyChanged, editor.UndoRedoService); }
public NavigationMeshManager([NotNull] IEditorGameController controller) { referencerId = new AbsoluteId(AssetId.Empty, Guid.NewGuid()); loader = controller.Loader; var root = controller.GameSideNodeContainer.GetOrCreateNode(this); meshesNode = root[nameof(Meshes)].Target; meshesNode.ItemChanged += (sender, args) => { Changed?.Invoke(this, args); }; }
// Note: constructor needed by UIElementViewModelFactory public PanelViewModel([NotNull] UIEditorBaseViewModel editor, [NotNull] UIBaseViewModel asset, [NotNull] UIElementDesign elementDesign) : base(editor, asset, elementDesign, GetOrCreateChildPartDesigns((UIAssetBase)asset.Asset, elementDesign)) { childrenNode = editor.NodeContainer.GetOrCreateNode(AssetSidePanel)[nameof(Panel.Children)].Target; childrenNode.ItemChanged += ChildrenContentChanged; ChangeLayoutTypeCommand = new AnonymousCommand <IUIElementFactory>(ServiceProvider, ChangeLayoutType); UngroupCommand = new AnonymousCommand(ServiceProvider, Ungroup); }
public override bool IsTargetItemObjectReference(IObjectNode collection, Index itemIndex, object value) { if (value is EntityComponent) { // Check if we're in the component collection of an entity - other cases are references return(collection.Type != typeof(EntityComponentCollection)); } return(base.IsTargetItemObjectReference(collection, itemIndex, value)); }
/// <inheritdoc /> protected override bool ShouldConstructPropertyItem(IObjectNode collection, NodeIndex index) { // Don't construct properties for item referencing child parts. if (AssetHierarchyPropertyGraph.IsChildPartReference(collection, index)) { return(false); } return(base.ShouldConstructPropertyItem(collection, index)); }
protected EntityHierarchyRootViewModel([NotNull] EntityHierarchyEditorViewModel editor, [NotNull] EntityHierarchyViewModel asset, [NotNull] string name) : base(editor, asset, asset.Asset.Hierarchy.EnumerateRootPartDesigns(), null) { this.name = name ?? throw new ArgumentNullException(nameof(name)); rootEntitiesNode = Editor.Session.AssetNodeContainer.GetNode(EntityHierarchy.Hierarchy)[nameof(AssetCompositeHierarchyData <EntityDesign, Entity> .RootParts)].Target; rootEntitiesNode.ItemChanging += RootEntitiesChanging; rootEntitiesNode.ItemChanged += RootEntitiesChanged; entitiesNode = Editor.Session.AssetNodeContainer.GetNode(EntityHierarchy.Hierarchy)[nameof(AssetCompositeHierarchyData <EntityDesign, Entity> .Parts)].Target; entitiesNode.ItemChanged += EntitiesChanged; }
private RootEntry ToEntry(IObjectNode obj) { var entries = new List <ComplexEntry>(); ToEntry(entries, null, obj); return(new RootEntry { entries = entries, }); }
private static void ClearMaterialList(IObjectNode materials) { var indices = materials.Indices.ToList(); foreach (var index in indices) { var item = materials.Retrieve(index); materials.Remove(item, index); } }
/// <summary> /// Indicates whether the target node of the item corresponding to the given index in the collection contained in the given node should be visited or not. /// </summary> /// <param name="collectionNode">The node to evaluate.</param> /// <param name="index">The index of the item to evaluate.</param> /// <returns>True if the node of the item corresponding to the given index in the collection contained in the given node should be visited, false otherwise.</returns> /// <remarks>This method is invoked only when the given <see cref="IObjectNode"/> contains a collection with items being references.</remarks> protected internal virtual bool ShouldVisitTargetItem([NotNull] IObjectNode collectionNode, NodeIndex index) { if (collectionNode == null) { throw new ArgumentNullException(nameof(collectionNode)); } var target = collectionNode.IndexedTarget(index); return(!visitedNodes.Contains(target)); }
/// <summary> /// Visits the children of the given node. /// </summary> /// <param name="node">The node being visited.</param> /// <param name="currentPath">The path of the node being visited.</param> protected virtual void VisitChildren(IObjectNode node, GraphNodePath currentPath) { foreach (var child in node.Members) { var childPath = currentPath.PushMember(child.Name); if (ShouldVisitNode(child, child)) { VisitNode(child, childPath); } } }
private static void SetMaterial(IObjectNode materialNode, Index index, Material value) { if (materialNode.Indices.Contains(index)) { materialNode.Update(value, index); } else { materialNode.Add(value, index); } }
public void CreateChildren(IInitializingNodePresenter parentPresenter, IObjectNode objectNode, IPropertyProviderViewModel propertyProvider) { buildingNodes.Value = true; if (objectNode != null) { GenerateChildren(parentPresenter, objectNode, propertyProvider); } RunUpdaters(parentPresenter); buildingNodes.Value = false; FinalizeTree(parentPresenter.Root); }
private void CheckAndProcessIdentifiableItem([NotNull] IObjectNode collection, NodeIndex index) { var identifiable = collection.Retrieve(index) as IIdentifiable; if (identifiable == null) { return; } ProcessIdentifiableItems(identifiable, collection, index); }
public VisualScriptMethodEditorViewModel(VisualScriptEditorViewModel editor, VisualScriptMethodViewModel method) : base(editor.SafeArgument(nameof(editor)).ServiceProvider) { this.editor = editor; this.method = method; var methodNode = editor.Session.AssetNodeContainer.GetNode(method.Method); blocksNode = methodNode[nameof(method.Method.Blocks)].Target; linksNode = methodNode[nameof(method.Method.Links)].Target; parametersNode = methodNode[nameof(method.Method.Parameters)].Target; }
// fieldInfo - the field who's value we want // objNode - the member node corresponding to the field // out topLevelObject - the object that contains the highest level // struct. // s/b protected, stupid compiler internal static StructAccessor GetAccessorObject (IObjectNode objNode, out Object topLevelObject) { Stack structInfoStack = new Stack(); IObjectNode parentObjNode; if (TraceUtil.If(typeof(StructAccessor), TraceLevel.Info)) { TraceUtil.WriteLineInfo (typeof(StructAccessor), "GetAccessor: " + objNode.ObjectInfo.ToString() + " node: " + objNode.ToString()); } // Build up the structFields array, the fields between the // top level object and the object we want to change while (true) { parentObjNode = objNode.ParentObjectNode; if (parentObjNode == null) { throw new Exception("(bug) hit no parent when " + "looking for enclosing object " + "for a struct " + objNode); } // This is an enclosing struct, push the field // information of how to get to the child here FieldInfo fi = parentObjNode.ObjType.GetField (objNode.ObjectInfo.ObjMemberInfo.Name, ReflectionHelper.ALL_BINDINGS); if (fi == null) { throw new Exception("(bug) field " + objNode.ObjType.Name + " not found in " + parentObjNode); } structInfoStack.Push(fi); // Found the containing object, either not a value // type, or this is not a field which means it can't // be inline any more // FIXME - double check the member thing here, is this // the right level to check? if (!parentObjNode.ObjType.IsValueType || !(parentObjNode.ObjectInfo.ObjMemberInfo is FieldInfo)) break; // Go up objNode = parentObjNode; } // Ok, at this point, parent is the ObjectInfo for the // object that contains the top-level struct Type objType = parentObjNode.ObjType; topLevelObject = parentObjNode.Obj; if (TraceUtil.If(typeof(StructAccessor), TraceLevel.Info)) { TraceUtil.WriteLineInfo (typeof(StructAccessor), "GetAccessor - top level type/obj: " + objType + "/" + topLevelObject); } int count = structInfoStack.Count; FieldInfo[] structFields = new FieldInfo[structInfoStack.Count]; for (int i = 0; i < count; i++) structFields[i] = (FieldInfo)structInfoStack.Pop(); StructAccessor vtAccessor; StringBuilder keyBuilder = new StringBuilder(); String key; keyBuilder.Append(objType.FullName); keyBuilder.Append("."); foreach (FieldInfo fi in structFields) { keyBuilder.Append(fi.Name); keyBuilder.Append("."); } key = keyBuilder.ToString(); if (TraceUtil.If(typeof(StructAccessor), TraceLevel.Info)) { TraceUtil.WriteLineInfo (typeof(StructAccessor), "GetAccessor - key: " + key); } lock (typeof(StructAccessor)) { vtAccessor = (StructAccessor)_accessors[key]; if (vtAccessor != null) return vtAccessor; vtAccessor = new StructAccessor(); vtAccessor.MakeAccessorClass(key, objType, structFields); _accessors.Add(key, vtAccessor); return vtAccessor; } }
// fieldInfo - the field who's value we want // objNode - the member node corresponding to the field // out topLevelObject - the object that contains the highest level // struct. // s/b protected, stupid compiler internal static FieldInfo[] GetStructFields (IObjectNode objNode, out Object topLevelObject) { Stack structInfoStack = new Stack(); IObjectNode parentObjNode; if (TraceUtil.If(typeof(StructAccessor), TraceLevel.Info)) { TraceUtil.WriteLineInfo (typeof(StructAccessor), "GetAccessor: " + objNode.ObjectInfo.ToString() + " node: " + objNode.ToString()); } // Build up the structFields array, the fields between the // top level object and the object we want to change while (true) { parentObjNode = objNode.ParentObjectNode; if (parentObjNode == null) { throw new Exception("(bug) hit no parent when " + "looking for enclosing object " + "for a struct " + objNode); } // This is an enclosing struct, push the field // information of how to get to the child here FieldInfo fi = parentObjNode.ObjType.GetField (objNode.ObjectInfo.ObjMemberInfo.Name, ReflectionHelper.ALL_BINDINGS); if (fi == null) { throw new Exception("(bug) field " + objNode.ObjType.Name + " not found in " + parentObjNode); } structInfoStack.Push(fi); // Found the containing object, either not a value // type, or this is not a field which means it can't // be inline any more if (!parentObjNode.ObjType.IsValueType || !(parentObjNode.ObjectInfo.ObjMemberInfo is FieldInfo)) break; // Go up objNode = parentObjNode; } // Ok, at this point, parent is the ObjectInfo for the // object that contains the top-level struct topLevelObject = parentObjNode.Obj; if (TraceUtil.If(typeof(StructAccessor), TraceLevel.Info)) { TraceUtil.WriteLineInfo (typeof(StructAccessor), "GetAccessor - top level obj: " + topLevelObject); } int count = structInfoStack.Count; FieldInfo[] structFields = new FieldInfo[structInfoStack.Count]; for (int i = 0; i < count; i++) structFields[i] = (FieldInfo)structInfoStack.Pop(); return structFields; }
// // The methods below are the external interface to this class // // Gets the value for this field within the specified // object into at the specified member node. internal static Object GetValue(IObjectNode objNode) { Object obj; FieldInfo[] structFields = GetStructFields(objNode, out obj); Object value = obj; for (int i = 0; i < structFields.Length; i++) value = structFields[i].GetValue(value); if (TraceUtil.If(typeof(StructAccessor), TraceLevel.Verbose)) { Trace.WriteLine("Struct getting Field: " + objNode + " value: " + value); } return value; }
// Sets the value in the same manner as GetValue internal static void SetValue(IObjectNode objNode, Object value) { if (TraceUtil.If(typeof(StructAccessor), TraceLevel.Verbose)) { Trace.WriteLine("Struct setting Field: " + objNode + " value: " + value); } Object obj; FieldInfo[] structFields = GetStructFields(objNode, out obj); SetValue(structFields, obj, value, 0); objNode.DoDisplayValue(); }
protected void InvokeInternal(ObjectInfo parent, IObjectNode objectNode, Object[] parameterValues, Object fieldPropValue, bool setMember) { if (TraceUtil.If(this, TraceLevel.Verbose)) { Trace.WriteLine("Start invoke: " + _objMemberInfo); if (fieldPropValue != null) Trace.WriteLine(" fieldPropVal: " + fieldPropValue); if (parameterValues != null) { foreach (Object pval in parameterValues) Trace.WriteLine(" param: " + pval); } } switch (_objMemberInfo.MemberType) { case MemberTypes.Method: { MethodInfo m = (MethodInfo)_objMemberInfo; SetObject(m.Invoke(parent._obj, parameterValues)); if (TraceUtil.If(this, TraceLevel.Verbose)) { Trace.WriteLine("Called: " + m + " on " + parent._obj + " return: " + _obj); } } break; case MemberTypes.Property: { PropertyInfo p = (PropertyInfo)_objMemberInfo; if (setMember) { p.SetValue(parent._obj, fieldPropValue, parameterValues); } if (p.CanRead){ SetObject(p.GetValue(parent._obj, parameterValues)); } else { // Update the new property value, if we can't // read it from the property (on a set) if (setMember) SetObject(fieldPropValue); } // Save these in case we need to set the property, // like with the property propogation code below objectNode.CurrentPropIndexValues = parameterValues; if (TraceUtil.If(this, TraceLevel.Verbose)) { Trace.WriteLine("Property: " + p + " of " + parent._obj + " value: " + _obj); } } break; case MemberTypes.Field: { FieldInfo f = (FieldInfo)_objMemberInfo; if (parent._objType.IsValueType) { // This is a struct, its handled a little // different because of the inline value type // issue if (setMember) { StructAccessor.SetValue(objectNode, fieldPropValue); } SetObject(StructAccessor.GetValue(objectNode)); } else { if (setMember) f.SetValue(parent._obj, fieldPropValue); SetObject(f.GetValue(parent._obj)); } if (TraceUtil.If(this, TraceLevel.Verbose)) { Trace.WriteLine("Field: " + f + " of " + parent._obj + " value: " + _obj); } } break; default: break; } // Everything worked, now lets handle any changes that // superiors need. if (!setMember) return; // If the parent member is a property, we want to do // a SetProperty on it with the current value of its object // so that the SetProperty can process the most recently // changed values. We need to do this up the line. while (true) { IObjectNode parentObjNode; parentObjNode = objectNode.ParentObjectNode; if (parentObjNode == null) break; // We hit an object node that has no member, we are done if (parentObjNode.ObjectInfo.ObjMemberInfo == null) break; // Look at enclosing property members only if (!(parentObjNode.ObjectInfo.ObjMemberInfo is PropertyInfo)) break; PropertyInfo propInfo = (PropertyInfo)parentObjNode.ObjectInfo.ObjMemberInfo; // Set the property try { propInfo.SetValue(parentObjNode.ParentObjectNode.Obj, parentObjNode.Obj, parentObjNode.CurrentPropIndexValues); } catch (Exception ex) { // A parent property might not have a set method // for example. TraceUtil.WriteLineInfo (this, "Exception in SetValue in property " + "propagation for prop: " + propInfo + " ex: " + ex); break; } parentObjNode.DoDisplayValue(); objectNode = parentObjNode; } }
// Returns true if it worked internal bool Invoke(ObjectInfo parent, IObjectNode objectNode, Object[] parameterValues, Object fieldPropValue, bool setMember, bool autoInvoke, bool ignoreException) { if (parent == null) { if (TraceUtil.If(this, TraceLevel.Info)) { Trace.WriteLine("Invoke - No parent"); } return false; } if (_objMemberInfo == null || parent._obj == null) { if (TraceUtil.If(this, TraceLevel.Info)) { Trace.WriteLine(TraceLevel.Info, "Invoke - No parent object or MemberInfo"); } // Don't show this message in the auto invoke case if (!ignoreException && !autoInvoke) { ErrorDialog.Show("This method/property/field cannot " + "be invoked " + NULL_PARENT_TEXT, "Parent Object Not Present", MessageBoxIcon.Error); } return false; } try { InvokeInternal(parent, objectNode, parameterValues, fieldPropValue, setMember); } catch (Exception e) { if (TraceUtil.If(this, TraceLevel.Info)) Trace.WriteLine("Exception on invoke: " + e); if (!ignoreException) { Exception showException = e; // Remove the useless wrapper exception if (showException is TargetInvocationException) showException = e.InnerException; String errorStr = "Exception invoking " + _objMemberInfo.MemberType + " " + _objMemberInfo.Name + ". "; if (!setMember && _objMemberInfo.MemberType != MemberTypes.Method) { errorStr += "This can occur when you click on " + "an item in the object tree. "; } errorStr += "It means that the " + "underlying object raised an exception when the " + _objMemberInfo.MemberType + " was invoked."; ErrorDialog.Show (showException, errorStr, "Exception invoking " + _objMemberInfo.MemberType + " " + _objMemberInfo, MessageBoxIcon.Error); } return false; } return true; }
// Returns true if this property should be auto invoked internal static bool ShouldAutoInvokeProp(IObjectNode node) { MemberInfo[] membersType = (MemberInfo[])_autoInvokeHash[node.ObjectInfo.ObjMemberInfo]; // Not found, so its ok to auto invoke if (membersType == null) return true; for (int i = 0; i < membersType.Length; i++) { if (node == null) return true; if (i == membersType.Length - 1) { // Found a match, don't invoke the property if (((Type)membersType[i]).IsAssignableFrom(node.ObjType)) return false; } if (!ReflectionHelper.IsMemberEqual (node.ObjectInfo.ObjMemberInfo, membersType[i])) return true; node = node.ParentObjectNode; } return true; }