/// <summary> /// Ищем методы. /// </summary> /// <param name="t">Исследуемый тип, не путать с InspectedType, ведь с погружением в его поля это будет их тип, соответственно.</param> /// <param name="funcToGetLocalInstanceFromGlobal">Делегат для получения объекта с типом t из InspectedType.</param> void InspectMetods(string prefix, string realNamePrefix, Type t, Func <object, object> funcToGetLocalInstanceFromGlobal) { var methodInfoList = GetAllMethods(t); foreach (var item in methodInfoList) { var attr = item.GetCustomAttribute(typeof(MethodReflectionMapAttribute)) as MethodReflectionMapAttribute; if (attr != null) { var newMethod = new ReflectionMapMethod() { DisplayName = prefix + (attr.DisplayName ?? ToCurrentNotation(item.Name)), RealName = realNamePrefix + item.Name, Description = attr.Description, Parameters = ParameterInfoArrayToParamsArray(item.GetParameters()), ReturnType = item.ReturnType }; newMethod.InvokeAction = (globalInst, parameters) => { var locInst = funcToGetLocalInstanceFromGlobal(globalInst); return(item.Invoke(locInst, parameters)); }; _longNameAndMethod.Add( newMethod.DisplayName, newMethod ); } } }
/// <summary> /// Ищем простые свойства (которые будут сконвертированы в методы с приставкой get и set. /// </summary> /// <param name="t">Исследуемый тип, не путать с InspectedType, ведь с погружением в его поля это будет их тип, соответственно.</param> /// <param name="funcToGetLocalInstanceFromGlobal">Делегат для получения объекта с типом t из InspectedType.</param> void InspectSimpleProps(string prefix, string realNamePrefix, Type t, Func <object, object> funcToGetLocalInstanceFromGlobal) { foreach (var item in t.GetProperties()) { var attr = item.GetCustomAttribute(typeof(SimplePropReflectionMapAttribute)) as SimplePropReflectionMapAttribute; if (attr != null) { if (attr.CanGet && item.CanRead) { var newMethod = new ReflectionMapMethod() { DisplayName = prefix + (NotationGetPrefix() + (attr.DisplayName ?? ToCurrentNotation(item.Name))), RealName = realNamePrefix + item.Name, Description = attr.Description, Parameters = new Parameter[] { }, ReturnType = item.PropertyType, Kind = MethodKind.PropertyGetter }; var getter = item.GetMethod; newMethod.InvokeAction = (globalInst, parameters) => { var locInst = funcToGetLocalInstanceFromGlobal(globalInst); return(getter.Invoke(locInst, parameters)); }; _longNameAndMethod.Add( newMethod.DisplayName, newMethod ); } if (attr.CanSet && item.CanWrite) { var param = new Parameter { ParamName = "val" }; var newMethod = new ReflectionMapMethod() { DisplayName = prefix + (NotationSetPrefix() + (attr.DisplayName ?? ToCurrentNotation(item.Name))), RealName = realNamePrefix + item.Name, Description = attr.Description, Parameters = new Parameter[] { param }, ReturnType = typeof(void), Kind = MethodKind.PropertySetter }; var setter = item.SetMethod; newMethod.InvokeAction = (globalInst, parameters) => { var locInst = funcToGetLocalInstanceFromGlobal(globalInst); return(setter.Invoke(locInst, parameters)); }; _longNameAndMethod.Add( newMethod.DisplayName, newMethod ); } } } }