예제 #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(";");
            }
        }
        /// <summary>
        /// Generates the class declaration part.
        /// </summary>
        /// <param name="className">Name of the class.</param>
        /// <param name="interfaces">The interfaces.</param>
        /// <returns></returns>
        protected virtual string GenerateClassDeclarationPart(string className, ICollection <Type> interfaces)
        {
            StringBuilder builder = new StringBuilder("public class ", 512);
            SequencedKeyDictionary <string, List <Type> > genericTypes = new SequencedKeyDictionary <string, List <Type> >();

            interfaces = interfaces ?? new Collection <Type>();

            foreach (var one in interfaces)
            {
                var genericParameterConstraints = GetGenericTypeConstraints(one);
                if (genericParameterConstraints.HasItem())
                {
                    foreach (var g in genericParameterConstraints)
                    {
                        genericTypes.Merge(g.Key, g.Value.ToList());
                    }
                }
            }

            builder.Append(className);

            if (genericTypes.HasItem())
            {
                builder.Append("<");
                builder.Append(CSharpCodeGenerateUtil.CombineCode(genericTypes, x => x.Key, 16, StringConstants.CommaChar));
                builder.Append(">");
            }

            if (BaseClassType != null)
            {
                builder.Append(": ");
                builder.Append(BaseClassType.ToCodeLook());
            }

            builder.AppendLine();

            if (interfaces.HasItem())
            {
                builder.Append(",");
                builder.AppendLine(CSharpCodeGenerateUtil.CombineCode(interfaces, x => x.ToCodeLook(), 32, StringConstants.CommaChar));
                builder.AppendLine();
            }

            // Add generic constraints
            foreach (var constraint in genericTypes)
            {
                CSharpCodeGenerateUtil.InternalWriteGenericConstraintsCodeLook(builder, constraint.Key, constraint.Value, new string(CodeIndent[0], CodeIndent.Length * 3));
                builder.AppendLine();
            }

            return(builder.ToString());
        }