public BoolFlag(XObject currentObject, string objectId, string flag) { this.eventName = objectId + ":" + flag; if (currentObject.FindGlobal(objectId) == null) { throw new InvalidOperationException(string.Format("Could not find object with id [{0}]", objectId)); } }
public static Expression CreateMethod(XObject currentObject, string objectId, string actionId, List <Expression> parameters) { XObject target; if (objectId == null) { target = currentObject.Parent; objectId = target.Id; } else { target = currentObject.FindGlobal(objectId); } if (target == null) { throw new InvalidOperationException(string.Format("Could not find object with Id: [{0}]", objectId)); } var method = target.GetType().GetMethod(actionId); if (method == null) { throw new InvalidOperationException(string.Format("Could not find method [{0}] on object [{1}]", actionId, objectId)); } var returnType = method.ReturnType; if (returnType == typeof(string)) { Func <List <Expression>, string> func; target.GetMethod(actionId, out func); return(new Method <string>(currentObject, objectId, actionId, func, parameters)); } else if (returnType == typeof(bool)) { Func <List <Expression>, bool> func; target.GetMethod(actionId, out func); return(new Method <bool>(currentObject, objectId, actionId, func, parameters)); } else if (returnType == typeof(void)) { Action <List <Expression> > func; target.GetMethod(actionId, out func); return(new Method <object>(currentObject, objectId, actionId, (ps) => { func(ps); return null; }, parameters)); } else { Func <List <Expression>, double> func; target.GetMethod(actionId, out func); return(new Method <double>(currentObject, objectId, actionId, func, parameters)); } }
public static Expression CreateMethod(XObject currentObject, string objectId, string actionId, List<Expression> parameters) { XObject target; if (objectId == null) { target = currentObject.Parent; objectId = target.Id; } else target = currentObject.FindGlobal(objectId); if (target == null) throw new InvalidOperationException(string.Format("Could not find object with Id: [{0}]", objectId)); var method = target.GetType().GetMethod(actionId); if (method == null) throw new InvalidOperationException(string.Format("Could not find method [{0}] on object [{1}]", actionId, objectId)); var returnType = method.ReturnType; if (returnType == typeof(string)) { Func<List<Expression>, string> func; target.GetMethod(actionId, out func); return new Method<string>(currentObject, objectId, actionId, func, parameters); } else if (returnType == typeof(bool)) { Func<List<Expression>, bool> func; target.GetMethod(actionId, out func); return new Method<bool>(currentObject, objectId, actionId, func, parameters); } else if (returnType == typeof(void)) { Action<List<Expression>> func; target.GetMethod(actionId, out func); return new Method<object>(currentObject, objectId, actionId, (ps) => { func(ps); return null; }, parameters); } else { Func<List<Expression>, double> func; target.GetMethod(actionId, out func); return new Method<double>(currentObject, objectId, actionId, func, parameters); } }
public static Expression CreateProperty(XObject currentObject, string objectId, string propertyId) { XObject target; if (objectId == null) { target = currentObject.Parent; objectId = target.Id; } else { target = currentObject.FindGlobal(objectId); } if (target == null) { throw new InvalidOperationException(string.Format("Could not find object with Id: [{0}]", objectId)); } Type returnType = null; var propertyInfo = target.GetType().GetProperty(propertyId); if (propertyInfo != null) { returnType = propertyInfo.PropertyType; } else { var fieldInfo = target.GetType().GetField(propertyId); if (fieldInfo != null) { returnType = fieldInfo.FieldType; } else { throw new InvalidOperationException( string.Format("Could not find property [{0}] on object [{1}] of type [{2}])", propertyId, target.Id, target.GetType().FullName) ); } } if (returnType == typeof(string) || returnType.IsEnum) { Func <string> getter; Action <string> setter; target.GetProperty(propertyId, out getter, out setter); return(new Property <string>(target, objectId, propertyId, getter, setter)); } else if (returnType == typeof(bool)) { Func <bool> getter; Action <bool> setter; target.GetProperty(propertyId, out getter, out setter); return(new Property <bool>(target, objectId, propertyId, getter, setter)); } else { Func <double> getter; Action <double> setter; target.GetProperty(propertyId, out getter, out setter); return(new Property <double>(target, objectId, propertyId, getter, setter)); } }