/// <summary> /// Create an instance of a PropWrapper based on the supplied ID string /// </summary> /// <param name="id"></param> /// <param name="expectedType"></param> /// <param name="delOnChanged"></param> /// <returns></returns> public static PropertyWrapper Create(string id, Type expectedType, MethodInvoker delOnChanged) { if (string.IsNullOrEmpty(id)) { return(null); } try { PropertyWrapper propWrapper = new PropertyWrapper(id, expectedType) { _delOnChanged = delOnChanged }; propWrapper.Initialize(); return(propWrapper); } catch (Exception ex) { U.LogPopup(ex, "Unable to create Property Wrapper"); } return(null); }
private MethodWrapper(string id) { _args = null; // Assumes a MethodId exists string methodName = string.Empty; string[] sArgs = null; string methodPath = string.Empty; if (!id.Contains('.')) { //throw new MCoreExceptionPopup("The MethodID should contain a Target component: '{0}'", id); _target = U.RootComp; sArgs = U.SplitMethodID(id, out methodPath); methodName = methodPath; } else { sArgs = U.SplitMethodID(id, out methodPath); if (methodPath.Contains(".")) { // Extract Target and Method name int lastPeriod = methodPath.LastIndexOf('.'); _target = U.GetComponent(methodPath.Substring(0, lastPeriod)); methodName = methodPath.Substring(lastPeriod + 1); } else { _target = U.RootComp; methodName = methodPath; } } _argTypes = null; if (sArgs != null) { _args = new PropertyWrapper[sArgs.Length]; _argTypes = new Type[sArgs.Length]; for (int i = 0; i < sArgs.Length; i++) { // Extract Target and Method name PropertyWrapper propWrapper = PropertyWrapper.Create(sArgs[i]); _args[i] = propWrapper; _argTypes[i] = propWrapper.PropertyType; } } else { _argTypes = new Type[0]; } _mi = _target.GetType().GetMethod(methodName, _argTypes); if (_mi == null) { throw new Exception(string.Format("Could not obtain the Method name from the MethodID: '{0}'", id)); } _delMethod = D.CreateGenericDelegateWithArgs(_mi); }