示例#1
0
        /// <summary>
        /// Generates the method call information declarition.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="methodInfo">The method information.</param>
        /// <param name="indent">The indent.</param>
        /// <param name="methodCallInfoVariableName">Name of the method call information variable.</param>
        protected void GenerateMethodCallInfoDeclarition(StringBuilder builder, MethodInfo methodInfo, int indent, string methodCallInfoVariableName)
        {
            if (builder != null && methodInfo != null && !string.IsNullOrWhiteSpace(methodCallInfoVariableName))
            {
                var tmpMethodCallInfo = new MethodCallInfo();
                tmpMethodCallInfo.Fill(methodInfo);

                builder.AppendIndent(indent);
                builder.Append(string.Format("{0} {1} = new {0}(", typeof(MethodCallInfo).ToCodeLook(), methodCallInfoVariableName));
                builder.Append(string.Format("\"{0}\",", tmpMethodCallInfo.MethodFullName));
                builder.Append(" new Dictionary<string, object>{");
                foreach (var one in tmpMethodCallInfo.InArgs)
                {
                    builder.Append(" {\"");
                    builder.Append(one.Key);
                    builder.Append("\", ");
                    builder.Append(one.Key);
                    builder.Append("},");
                }
                builder.RemoveLastIfMatch(StringConstants.CommaChar);
                builder.Append("}");
                builder.AppendLine(")");

                builder.AppendBeginBrace(ref indent);

                builder.AppendIndent(indent);
                builder.Append("SerializableArgNames = new System.Collections.Generic.List<System.String> {");
                builder.Append(CSharpCodeGenerateUtil.CombineCode(tmpMethodCallInfo.SerializableArgNames, (x) => { return(x.AsQuotedString()); }, 16));
                builder.AppendLine("}");

                builder.AppendEndBrace(ref indent);
                builder.AppendLine(";");
            }
        }
示例#2
0
        /// <summary>
        /// Fills the specified method call information.
        /// </summary>
        /// <param name="methodCallInfo">The method call information.</param>
        /// <param name="methodBase">The method base.</param>
        /// <param name="inArgsData">The in arguments data.</param>
        internal static void Fill(this MethodCallInfo methodCallInfo, MethodBase methodBase, object[] inArgsData = null)
        {
            if (methodCallInfo != null && methodBase != null)
            {
                methodCallInfo.MethodFullName = methodBase.GetFullName();
                var inArgs = new Dictionary <string, object>();

                var parameters = methodBase.GetParameters();

                for (var i = 0; i < parameters.Length; i++)
                {
                    inArgs.Add(parameters[i].Name, inArgsData == null ? null : inArgsData[i]);

                    var parameterType = parameters[i].ParameterType;
                    if (!(parameterType.IsContextful || parameterType.IsCOMObject))
                    {
                        methodCallInfo.SerializableArgNames.Add(parameters[i].Name);
                    }
                }

                methodCallInfo.InArgs = inArgs;
            }
        }