Пример #1
0
        private static void AddString(StringBuilder stringBuilder, IMethod consoleMethod)
        {
            const string NullStr = "Null";

            MethodDescription description = consoleMethod.Description;

            if (description.Parameters.Count > 0)
            {
                stringBuilder.AppendFormat("Name : {0}", description.Name);
                foreach (var parameter in description.Parameters)
                {
                    stringBuilder.Append(string.Format(" [{0}]", parameter.Type));
                }

                stringBuilder.AppendFormat("; Tag : {0}; Message : {1} ;", description.Tag ?? NullStr, description.Message ?? NullStr);

                stringBuilder.Append(" Parameters : ");
                for (int index = 0; index < description.Parameters.Count; index++)
                {
                    var parameter = description.Parameters[index];
                    stringBuilder.AppendFormat("[{0}]({1}){2} ", index, parameter.Type, parameter.Message);
                }

                stringBuilder.Append(';');
            }
            else
            {
                stringBuilder.AppendFormat("Name : {0}; Tag : {1}; Message : {2} ;", description.Name, description.Tag ?? NullStr, description.Message ?? NullStr);
            }
        }
Пример #2
0
            public ConsoleMethod_Action6(Action6 method, MethodDescription description) : base(description)
            {
                if (method == null)
                {
                    throw new ArgumentNullException(nameof(method));
                }

                this.method = method;
            }
Пример #3
0
        /// <summary>
        /// 创建一个新的控制台方法;
        /// </summary>
        /// <param name="methodInfo">对应的方法</param>
        /// <param name="target">若未静态方法则为null,否则传入实例</param>
        public static Method Create(MethodInfo methodInfo, Object target, MethodDescription description = null)
        {
            ParameterInfo[] parameterInfos = methodInfo.GetParameters();
            foreach (var parameterInfo in parameterInfos)
            {
                if (parameterInfo.ParameterType != typeof(string))
                {
                    throw new ArgumentException(string.Format("[{0}]参数类型存在一个或多个不为 string 类型;", methodInfo.Name));
                }
            }

            switch (parameterInfos.Length)
            {
            case 0:
                var method0 = CreateDelegate <Action>(methodInfo, target);
                return(Create(method0, description));

            case 1:
                var method1 = CreateDelegate <Action1>(methodInfo, target);
                return(Create(method1, description));

            case 2:
                var method2 = CreateDelegate <Action2>(methodInfo, target);
                return(Create(method2, description));

            case 3:
                var method3 = CreateDelegate <Action3>(methodInfo, target);
                return(Create(method3, description));

            case 4:
                var method4 = CreateDelegate <Action4>(methodInfo, target);
                return(Create(method4, description));

            case 5:
                var method5 = CreateDelegate <Action5>(methodInfo, target);
                return(Create(method5, description));

            case 6:
                var method6 = CreateDelegate <Action6>(methodInfo, target);
                return(Create(method6, description));

            default:
                throw new NotImplementedException(string.Format("还未支持方法参数数目为 {0} 的方法;", parameterInfos.Length));
            }
        }
Пример #4
0
 /// <summary>
 /// 创建一个新的控制台方法;
 /// </summary>
 public static Method Create(Action5 method, MethodDescription description)
 {
     return(new ConsoleMethod_Action5(method, description));
 }
Пример #5
0
 /// <summary>
 /// 构造函数;
 /// </summary>
 /// <param name="description">方法描述</param>
 /// <param name="prerequisite">前提,为null,则代表不存在前提</param>
 private Method(MethodDescription description)
 {
     Description = description;
 }