/// <summary> /// Создает словарь с названиями команд cli и соответствующими им методы. /// </summary> Dictionary <string, ResolvedCmdInfo> CreateReflectionDict() { var cmdNameAndMethod = new Dictionary <string, ResolvedCmdInfo>(); foreach (MethodInfo item in GetType().GetMethods()) { CmdInfoAttribute attr = item.GetCustomAttribute(typeof(CmdInfoAttribute)) as CmdInfoAttribute; if (attr != null) { var name = attr?.CmdName ?? TextExtensions.ToUnderscoreCase(item.Name); var newCmdInfo = new ResolvedCmdInfo() { CmdName = name, Description = attr.Description, MethodInfo = item, OriginalMethodName = item.Name }; cmdNameAndMethod.Add( name, newCmdInfo) ; } } return(cmdNameAndMethod); }
object[] ResolveCmdParams(string cmdAndParamsStr, ResolvedCmdInfo resolvedCmdInfo) { int firstParamIndex = cmdAndParamsStr.IndexOf('/'); string paramsStr = null; if (firstParamIndex > 0) { paramsStr = cmdAndParamsStr.Substring(firstParamIndex).Trim(); } else { paramsStr = ""; } var parameters = resolvedCmdInfo.MethodInfo.GetParameters().ToParam(); var parametesValues = CmdStringToParamsBindings.Inst.ResolveFromCmd(paramsStr, parameters, splitter: '/'); return(parametesValues.ToArray()); }