private string GetUsageOptionName(Option opt) { Type type = opt.Type; if (type != null && type.IsArray) { Array arr = (Array)opt.Target.GetValue(this); if (arr != null) { int length = arr.Length; string elementTypeName = CClassUtils.TypeShortName(arr.GetType().GetElementType()); StringBuilder result = new StringBuilder(); for (int i = 0; i < length; ++i) { result.Append(elementTypeName); if (i < length - 1) { result.Append(','); } } return(result.ToString()); } } string typename = CClassUtils.TypeShortName(type); return(typename != null ? typename : "opt"); }
private MethodInfo[] resolveExecuteMethods() { List <MethodInfo> result = new List <MethodInfo>(); CMethodsFilter filter = delegate(MethodInfo method) { if (method.Name != "Execute") { return(false); } if (method.IsAbstract) { return(false); } return(method.ReturnType == typeof(void) || method.ReturnType == typeof(bool)); }; Type type = GetCommandType(); while (type != null) { CClassUtils.ListInstanceMethods(result, type, filter); type = type.BaseType; } return(result.ToArray()); }
private bool CanExecute <T>(int argsCount) where T : class { Type type = typeof(T); List <MethodInfo> methods = CClassUtils.ListInstanceMethods(type, delegate(MethodInfo method) { return(method.Name.Equals("Execute")); }); Assert.AreEqual(1, methods.Count); return(CCommandUtils.CanInvokeMethodWithArgsCount(methods[0], argsCount)); }
protected void RegisterCommand(Type type, bool hidden = true) { CCommand command = CClassUtils.CreateInstance <CCommand>(type); if (command == null) { throw new ArgumentException("Can't create class instance: " + type.FullName); } String commandName = type.Name; if (commandName.StartsWith("Cmd_")) { commandName = commandName.Substring("Cmd_".Length); } command.Name = commandName; command.IsHidden = hidden; CRuntimeResolver.ResolveOptions(command); CRegistery.Register(command); }
private static CTimer NextTimer(CTimer timer) { return(CClassUtils.GetObjectField <CTimer>(timer, "next")); }