public override bool TrySetMember(SetMemberBinder binder, object value) { MemberInfo memberInfo = ChoTypeMembersCache.GetMemberInfo(WrappedObject.GetType(), binder.Name); if (memberInfo == null) { return(false); } // Locate property by name var propertyInfo = memberInfo as PropertyInfo; // WrappedObject.GetType().GetProperty(binder.Name, BindingFlags.Instance | BindingFlags.Public | (binder.IgnoreCase ? BindingFlags.IgnoreCase : 0)); if (propertyInfo != null && !propertyInfo.CanWrite) { return(false); } RaisePropertyChanging(binder.Name); ChoType.SetMemberValue(WrappedObject, memberInfo, value); //object newValue = value; //// Check the types are compatible //Type propertyType = propertyInfo.PropertyType; //if (!propertyType.IsAssignableFrom(value.GetType())) //{ // newValue = Convert.ChangeType(value, propertyType); //} //propertyInfo.SetValue(WrappedObject, newValue, null); RaisePropertyChanged(binder.Name); return(true); }
public void BuildReferenceMap() { if (!(WrappedObject is PARAM.Row) && !(WrappedObject is MergedParamRow)) { var type = WrappedObject.GetType(); var props = type.GetProperties(BindingFlags.Instance | BindingFlags.Public); foreach (var p in props) { var att = p.GetCustomAttribute <MSBReference>(); if (att != null) { if (p.PropertyType.IsArray) { } else { var sref = (string)p.GetValue(WrappedObject); if (sref != null && sref != "") { var obj = Container.GetObjectByName(sref); if (obj != null) { References.Add(p.Name, new[] { obj }); } } } } } } }
public PropertiesChangedAction GetPropertyChangeAction(string prop, object newval) { if (WrappedObject == null) { return(null); } if (WrappedObject is PARAM.Row row) { var pp = row[prop]; if (pp != null) { var pprop = pp.GetType().GetProperty("Value"); return(new PropertiesChangedAction(pprop, pp, newval)); } } if (WrappedObject is MergedParamRow mrow) { var pp = mrow[prop]; if (pp != null) { var pprop = pp.GetType().GetProperty("Value"); return(new PropertiesChangedAction(pprop, pp, newval)); } } var p = WrappedObject.GetType().GetProperty(prop); if (p != null) { return(new PropertiesChangedAction(p, WrappedObject, newval)); } return(null); }
public PropertyInfo GetProperty(string prop) { if (WrappedObject == null) { return(null); } if (WrappedObject is PARAM.Row row) { var pp = row[prop]; if (pp != null) { return(pp.GetType().GetProperty("Value")); } } else if (WrappedObject is MergedParamRow mrow) { var pp = mrow[prop]; if (pp != null) { return(pp.GetType().GetProperty("Value")); } } var p = WrappedObject.GetType().GetProperty(prop); if (p != null) { return(p); } return(null); }
public T GetPropertyValue <T>(string prop) { if (WrappedObject == null) { return(default(T)); } if (WrappedObject is PARAM.Row row) { var pp = row.Cells.FirstOrDefault(cell => cell.Def.InternalName == prop); if (pp != null) { return((T)pp.Value); } } else if (WrappedObject is MergedParamRow mrow) { var pp = mrow[prop]; if (pp != null) { return((T)pp.Value); } } var p = WrappedObject.GetType().GetProperty(prop); if (p != null && p.PropertyType == typeof(T)) { return((T)p.GetValue(WrappedObject, null)); } return(default(T)); }
public Action GetUpdateTransformAction(Transform newt) { if (WrappedObject is PARAM.Row || WrappedObject is MergedParamRow) { var actions = new List <Action>(); float roty = newt.EulerRotation.Y * Utils.Rad2Deg - 180.0f; actions.Add(GetPropertyChangeAction("PositionX", newt.Position.X)); actions.Add(GetPropertyChangeAction("PositionY", newt.Position.Y)); actions.Add(GetPropertyChangeAction("PositionZ", newt.Position.Z)); actions.Add(GetPropertyChangeAction("RotationX", newt.EulerRotation.X * Utils.Rad2Deg)); actions.Add(GetPropertyChangeAction("RotationY", roty)); actions.Add(GetPropertyChangeAction("RotationZ", newt.EulerRotation.Z * Utils.Rad2Deg)); var act = new CompoundAction(actions); act.SetPostExecutionAction((undo) => { UpdateRenderModel(); }); return(act); } else { var act = new PropertiesChangedAction(WrappedObject); var prop = WrappedObject.GetType().GetProperty("Position"); act.AddPropertyChange(prop, newt.Position); prop = WrappedObject.GetType().GetProperty("Rotation"); if (prop != null) { if (IsRotationPropertyRadians("Rotation")) { if (IsRotationXZY("Rotation")) { act.AddPropertyChange(prop, newt.EulerRotationXZY); } else { act.AddPropertyChange(prop, newt.EulerRotation); } } else { if (IsRotationXZY("Rotation")) { act.AddPropertyChange(prop, newt.EulerRotationXZY * Utils.Rad2Deg); } else { act.AddPropertyChange(prop, newt.EulerRotation * Utils.Rad2Deg); } } } act.SetPostExecutionAction((undo) => { UpdateRenderModel(); }); return(act); } }
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) { var properties = base.GetProperties(attributes).Cast <PropertyDescriptor>() .Where(p => BrowsableProperties.Contains(p.Name)) .Select(p => TypeDescriptor.CreateProperty( WrappedObject.GetType(), p, p.Attributes.Cast <Attribute>().ToArray())) .ToArray(); return(new PropertyDescriptorCollection(properties)); }
public bool IsRotationXZY(string prop) { if (WrappedObject == null) { return(false); } if (WrappedObject is PARAM.Row row || WrappedObject is MergedParamRow mrow) { return(false); } return(WrappedObject.GetType().GetProperty(prop).GetCustomAttribute <RotationXZY>() != null); }
public override bool TryGetMember(GetMemberBinder binder, out object result) { // Locate property by name var propertyInfo = WrappedObject.GetType().GetProperty(binder.Name, BindingFlags.Instance | BindingFlags.Public | (binder.IgnoreCase ? BindingFlags.IgnoreCase : 0)); if (propertyInfo == null || !propertyInfo.CanRead) { result = null; return(false); } result = propertyInfo.GetValue(WrappedObject, null); return(true); }
public virtual void UpdateRenderModel() { if (!HasTransform) { return; } Matrix4x4 t = UseTempTransform ? TempTransform.WorldMatrix : GetLocalTransform().WorldMatrix; var p = Parent; while (p != null) { t = t * (p.UseTempTransform ? p.TempTransform.WorldMatrix : p.GetLocalTransform().WorldMatrix); p = p.Parent; } if (RenderSceneMesh != null) { RenderSceneMesh.World = t; } foreach (var c in Children) { if (c.HasTransform) { c.UpdateRenderModel(); } } if (UseDrawGroups) { var prop = WrappedObject.GetType().GetProperty("DrawGroups"); if (prop != null && RenderSceneMesh != null) { RenderSceneMesh.DrawGroups.AlwaysVisible = false; RenderSceneMesh.DrawGroups.Drawgroups = (uint[])prop.GetValue(WrappedObject); } } if (RenderSceneMesh != null) { RenderSceneMesh.Visible = _EditorVisible; } }
public override IEnumerable <string> GetDynamicMemberNames() { return(from f in WrappedObject.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public) select f.Name); }
public object this[string fieldName] { get { if (Fields.TryGetValue(fieldName, out var field)) { return(field.Get(WrappedObject)); } else { throw new MissingFieldException("Field " + fieldName + " does not exist in Type " + WrappedObject.GetType()); } } set { if (Fields.TryGetValue(fieldName, out var field)) { field.Set(WrappedObject, value); } else { throw new MissingFieldException("Field " + fieldName + " does not exist in Type " + WrappedObject.GetType()); } } }
public object Invoke(string methodName, IEnumerable <object> arguments = null) { MethodInfoEx method = null; if (MethodsByName.TryGetValue(methodName, out var methods)) { if (methods.Count > 1) { method = methods.First(); } else { if (!arguments.Any(x => x == null)) { method = methods.Where(x => x.MethodInfo.HasSignature(arguments.Select(y => y.GetType()))).FirstOrDefault(); } if (method == null) { //Best match var matches = methods.Where(x => x.MethodInfo.IsInvokableWith(arguments)).ToList(); if (matches.Count == 1) { method = matches.First(); } else if (matches.Count > 1) { throw new AmbiguousMatchException("More than one possible matches for " + methodName + " found in Type" + WrappedObject.GetType()); } } } } if (method == null) { throw new MissingMethodException("Method " + methodName + " does not exist in Type " + WrappedObject.GetType()); } else { return(method.Invoke(WrappedObject, arguments)); } }
public object Invoke(string methodName, IEnumerable <Type> signature, IEnumerable <object> arguments) { if (MethodsByName.TryGetValue(methodName, out var methods)) { var method = methods.Where(x => x.MethodInfo.HasSignature(signature)).FirstOrDefault(); if (method == null) { throw new MissingMethodException("Method " + methodName + "with given signature does not exist in Type " + WrappedObject.GetType()); } else { return(method.Invoke(WrappedObject, arguments)); } } else { throw new MissingMethodException("Method " + methodName + " does not exist in Type " + WrappedObject.GetType()); } }
public object this[string propertyName] { get { if (Properties.TryGetValue(propertyName, out var prop)) { return(prop.Get(WrappedObject)); } else { throw new MissingMemberException("Property " + propertyName + " does not exist in Type " + WrappedObject.GetType()); } } set { if (Properties.TryGetValue(propertyName, out var prop)) { prop.Set(WrappedObject, value); } else { throw new MissingMemberException("Property " + propertyName + " does not exist in Type " + WrappedObject.GetType()); } } }