private void CreateObjectPropertiesNodes(object obj, TreeNode nodeObject) { foreach (PropertyInfo propInfo in obj.GetType().BaseType.GetProperties( BindingFlags.Instance | BindingFlags.Public)) // | BindingFlags.DeclaredOnly { object[] arrayOfCustomAttributes = propInfo.GetCustomAttributes(true); // object[] arrayOfCustomAttributes = propInfo.GetCustomAttributes(typeof(HLAAttributeAttribute), false); foreach (Attribute custumAttr in arrayOfCustomAttributes) { if (custumAttr is HLAAttributeAttribute) { HLAAttributeAttribute attr = custumAttr as HLAAttributeAttribute; object newValue = propInfo.GetValue(obj, null); TreeNode nodeProperty = FindNode(nodeObject.Nodes, attr.Name); if (nodeProperty != null) { object oldValue = ((HLAAttributePropertiesInformationValue)nodeProperty.Tag).ObjectValue; if (newValue != null && !newValue.Equals(oldValue)) { HLAAttributePropertiesInformationValue nodeInfo = new HLAAttributePropertiesInformationValue(attr.AttributeInfo, propInfo, newValue); // Updates the UI if the selected object is the same that the object that its properties has been changed if (this.propertyGrid.InternalPropertyGrid.SelectedObject.Equals(nodeProperty.Tag)) { this.propertyGrid.InternalPropertyGrid.SelectedObject = nodeInfo; } nodeProperty.Tag = nodeInfo; } } else { nodeProperty = new TreeNode(attr.Name); nodeProperty.ImageIndex = 1; nodeProperty.SelectedImageIndex = 1; HLAAttributePropertiesInformationValue nodeInfo = new HLAAttributePropertiesInformationValue(attr.AttributeInfo, propInfo, newValue); nodeProperty.Tag = nodeInfo; nodeObject.Nodes.Add(nodeProperty); } } } } }
public object UpdateAttributeValuesProxyObject(object instance, IDictionary <string, object> methodNameValueMap) { if (instance is HLAobjectRoot) { HLAobjectRoot obj = instance as HLAobjectRoot; ObjectClassDescriptor ocd = descriptorManager.GetObjectClassDescriptor(obj.ClassHandle); foreach (KeyValuePair <string, object> entry in methodNameValueMap) { if (log.IsDebugEnabled) { log.Debug("The method " + entry.Key + " from object " + obj.InstanceHandle + " has been called; new value:" + entry.Value + "; parameter type = " + entry.Value.GetType()); } HLAAttributeAttribute attr = obj.tableMethodInfo2Attr[entry.Key]; attr.propInfo.GetSetMethod().Invoke(obj, new object[] { entry.Value }); } } return(instance); }
public object UpdateAttributeValuesProxyObject(object instance, HLAattributeHandleValuePair[] methodNameValueMap) { if (instance is HLAobjectRoot) { HLAobjectRoot obj = instance as HLAobjectRoot; ObjectClassDescriptor ocd = descriptorManager.GetObjectClassDescriptor(obj.ClassHandle); foreach (HLAattributeHandleValuePair entry in methodNameValueMap) { if (log.IsDebugEnabled) { log.Debug("The method " + entry.AttributeHandle + " from object " + obj.InstanceHandle + " has been called; new value:" + entry.AttributeValue + "; parameter type = " + entry.AttributeValue.GetType()); } string attrName = ocd.GetAttributeDescriptor(new XRTIAttributeHandle(entry.AttributeHandle)).Name; HLAAttributeAttribute attr = obj.AttrTable[attrName]; attr.propInfo.GetSetMethod().Invoke(obj, new object[] { entry.AttributeValue }); //obj.GetType().BaseType.GetProperty(attrName).GetSetMethod().Invoke(obj, new object[] { entry.AttributeValue }); } } return(instance); }