Exemplo n.º 1
0
        private string CreateAbstractMethod(MethodInfo methodInfo)
        {
            Print($"------method:{methodInfo.Name}-----{methodInfo.DeclaringType}------");
            var    methodStr    = methodInfo.ReturnType == typeof(void) ? _abmVoidTmpd : _abmReturnTmpd;
            string argStr       = "";
            string argNoTypeStr = "";

            methodStr = methodStr.Replace("{$AMethodName}", methodInfo.Name);
            foreach (var pInfo in methodInfo.GetParameters())
            {
                argStr       += pInfo.ParameterType.Name + " " + pInfo.Name + ",";
                argNoTypeStr += pInfo.Name + ",";
            }
            argStr       = argStr.Trim(',');
            argNoTypeStr = argNoTypeStr.Trim(',');
            methodStr    = methodStr.Replace("{$args}", argStr);
            methodStr    = methodStr.Replace("{$args_no_type}", argNoTypeStr);

            methodStr = methodStr.Replace("{$comma}", argStr == "" ? "" : ",");
            methodStr = methodStr.Replace("{$modifier}", methodInfo.Accessmodifier().ToString().ToLower());

            if (methodInfo.ReturnType == typeof(void))
            {
                return(methodStr);
            }

            methodStr = methodStr.Replace("{$returnType}", methodInfo.ReturnType.Name);
            var returnStr = methodInfo.ReturnType.IsValueType ? "return 0;" : "return null;";

            methodStr = methodStr.Replace("{$returnDefault}", returnStr);

            return(methodStr);
        }
Exemplo n.º 2
0
        private string CreateVirtualMethod(MethodInfo methodInfo)
        {
            Print($"------method:{methodInfo.Name}-----{methodInfo.DeclaringType}------");
            var methodStr    = methodInfo.ReturnType == typeof(void) ? _vmVoidTmpd : _vmReturnTmpd;
            var argStr       = "";
            var argNoTypeStr = "";

            methodStr = methodStr.Replace("{$VMethodName}", methodInfo.Name);
            foreach (var pInfo in methodInfo.GetParameters())
            {
                argStr       += pInfo.ParameterType.Name + " " + pInfo.Name + ",";
                argNoTypeStr += pInfo.Name + ",";
            }
            argStr       = argStr.Trim(',');
            argNoTypeStr = argNoTypeStr.Trim(',');
            methodStr    = methodStr.Replace("{$args}", argStr);
            methodStr    = methodStr.Replace("{$args_no_type}", argNoTypeStr);

            methodStr = methodStr.Replace("{$comma}", argStr == "" ? "" : ",");
            methodStr = methodStr.Replace("{$modifier}", methodInfo.Accessmodifier().ToString().ToLower());

            if (methodInfo.ReturnType != typeof(void))
            {
                methodStr = methodStr.Replace("{$returnType}", methodInfo.ReturnType.Name);
            }

            return(methodStr);
        }