private static void RegisterCommandProperty(Type type, object obj) { PropertyInfo[] properties; if (null == obj) { properties = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); } else { properties = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); } foreach (PropertyInfo info in properties) { object[] customAttributes = info.GetCustomAttributes(typeof(CommandLineAttribute), true); if (0 != customAttributes.Length) { CommandLineAttribute attribute = (CommandLineAttribute)customAttributes[0]; string name = attribute.Name; if (string.IsNullOrEmpty(name)) { name = info.Name; } RegisterPropertyCommandHandler(type, obj, info, attribute.Description, name); } } }
//注册方法 private static void RegisterCommandMethod(Type type, object obj) { MethodInfo[] methods; if (null == obj) { methods = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); } else { methods = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); } foreach (MethodInfo info in methods) { object[] customAttributes = info.GetCustomAttributes(typeof(CommandLineAttribute), true); if (customAttributes.Length > 0) { CommandLineAttribute attribute = (CommandLineAttribute)customAttributes[0]; RegisterCommandHandlerMethod(type, obj, info, attribute.Description, attribute.Name); } } }