// ----- SetProperty methods ------ FBXResult SetIndexedProperty(object idx, fbxvariant value) { object convertedValue; DefaultMemberAttribute defaultMember = (DefaultMemberAttribute)Attribute.GetCustomAttribute(type, typeof(DefaultMemberAttribute)); var property = (defaultMember != null) ? getProp(defaultMember.MemberName) : null; if (property != null) { FBXResult returnValue = Converter.ToNet(value, property.PropertyType.GetElementType(), out convertedValue); if (!returnValue.success) { return(returnValue); } try { property.SetValue(this.wrappedObject, value, new object[] { idx }); } catch (Exception e) { return(new FBXResult(false, e.ToString())); } return(FBXResult.successful); } return(new FBXResult(false, "Property '" + idx + "' not found")); }
public override FBXResult SetProperty(string propertyName, fbxvariant value) { object convertedValue; FieldInfo field = type.GetField(propertyName); if (field != null) { FBXResult returnValue = Converter.ToNet(value, field.FieldType, out convertedValue); if (!returnValue.success) { return(returnValue); } try { field.SetValue(this.wrappedObject, convertedValue); } catch (Exception e) { return(new FBXResult(false, e.ToString())); } return(returnValue); } PropertyInfo property = getProp(propertyName); if (property != null) { FBXResult returnValue = Converter.ToNet(value, property.PropertyType, out convertedValue); if (!returnValue.success) { return(returnValue); } try { property.SetValue(this.wrappedObject, convertedValue, null); } catch (Exception e) { return(new FBXResult(false, e.ToString())); } return(returnValue); } FBXResult result = SetIndexedProperty(propertyName, value); if (!result.success) { int idx; if (Int32.TryParse(propertyName, out idx)) { return(SetIndexedProperty(idx, value)); } } return(result); }
public override FBXResult GetProperty(string propertyName, fbxvariant value) { if (propertyName == "toString") { propertyName = "ToString"; } // possible types: all, constructor, custom, event, field, method, nested type, property, typeinfo object obj; FieldInfo field = type.GetField(propertyName); if (field != null) { try { obj = field.GetValue(this.wrappedObject); } catch (Exception e) { return(new FBXResult(false, e.ToString())); } return(Converter.FromNet(obj, value)); } var property = getProp(propertyName); if (property != null) { try { obj = property.GetValue(this.wrappedObject, null); } catch (Exception e) { return(new FBXResult(false, e.ToString())); } return(Converter.FromNet(obj, value)); } // todo: why not use Delegate.CreateDelegate() here? Because we need to convert parameters explicitly to the desired target types? // maybe we should get rid of variants and replace them with DynamicObjects instead. if (type.GetMethods().Any(method => method.Name == propertyName)) { return(Converter.FromNet(new MethodObject(this.wrappedObject, propertyName), value)); } FBXResult result = GetIndexedProperty(propertyName, value); if (!result.success) { int idx; if (Int32.TryParse(propertyName, out idx)) { return(GetIndexedProperty(idx, value)); } } return(result); }
// Getting a property. public override bool TryGetMember(GetMemberBinder binder, out object result) { fbxvariant value = new fbxvariant(); FBXResult jsresult = wrappedObject.GetProperty(binder.Name, value); if (!jsresult.success) { throw new Exception(jsresult.message); } Converter.ToNet(value, typeof(object), out result); return(true); }
public override FBXResult Construct(VariantVector args, fbxvariant returnValue) { FBXResult result = Converter.InvokeOverload(this.typeObject, this.typeObject.GetConstructors(), "*ctor*", args, returnValue); if (!result.success) { return(result); } /*dynamic newInstance = new JSObject(returnValue.get_object()); * newInstance._cs_prototype = this.typeObject;*/ return(result); }
// Setting a property. public override bool TrySetMember(SetMemberBinder binder, object value) { fbxvariant convertedValue = new fbxvariant(); FBXResult jsresult = Converter.FromNet(value, convertedValue); if (!jsresult.success) { throw new Exception(jsresult.message); } jsresult = wrappedObject.SetProperty(binder.Name, convertedValue); if (!jsresult.success) { throw new Exception(jsresult.message); } return(true); }