示例#1
0
        public static CodeStringBuilder AppendAttribute(this CodeStringBuilder code, Type attributeType, params string[] args)
        {
            var name = attributeType.Name;

            if (name.EndsWith("Attribute", StringComparison.Ordinal))
            {
                name = name.Substring(0, attributeType.Name.Length - 9);
            }

            code
            .Append("[")
            .AppendTypeName(attributeType.Namespace, name);

            if (args.Length > 0)
            {
                code.Append("(");
                for (var i = 0; i < args.Length; i++)
                {
                    code
                    .AppendCommaIf(i != 0)
                    .Append(args[i]);
                }

                code.Append(")");
            }

            return(code.AppendLine("]"));
        }
示例#2
0
        public void WriteNewAttribute(AttributeData attribute, string expected)
        {
            var output = new CodeStringBuilder();

            CSharpServiceEndpointBinderBuilder.WriteNewAttribute(output, attribute);

            output.AsStringBuilder().ToString().ShouldBe(expected);
        }
示例#3
0
 public static CodeStringBuilder AppendArgumentNullException(this CodeStringBuilder code, string paramName)
 {
     return(code
            .Append("if (")
            .Append(paramName)
            .Append(" == null) throw new ArgumentNullException(\"")
            .Append(paramName)
            .AppendLine("\");"));
 }
示例#4
0
        public static CodeStringBuilder AppendMessage(this CodeStringBuilder code, MessageDescription message)
        {
            if (message.IsBuiltIn)
            {
                code
                .Append("global::")
                .Append(typeof(Message).Namespace)
                .Append(".");
            }

            code.Append(message.ClassName);
            return(code);
        }
示例#5
0
        internal static void WriteNewAttribute(CodeStringBuilder output, AttributeData attribute)
        {
            output
            .Append("new ")
            .Append(SyntaxTools.GetFullName(attribute.AttributeClass !));

            if (attribute.ConstructorArguments.Length == 0 && attribute.NamedArguments.Length == 0)
            {
                output.Append("()");
                return;
            }

            if (attribute.ConstructorArguments.Length > 0)
            {
                output.Append("(");

                for (var i = 0; i < attribute.ConstructorArguments.Length; i++)
                {
                    var arg = attribute.ConstructorArguments[i];
                    if (i > 0)
                    {
                        output.Append(", ");
                    }

                    output.Append(arg.ToCSharpString());
                }

                output.Append(")");
            }

            if (attribute.NamedArguments.Length > 0)
            {
                output.Append(" { ");

                for (var i = 0; i < attribute.NamedArguments.Length; i++)
                {
                    var arg = attribute.NamedArguments[i];
                    if (i > 0)
                    {
                        output.Append(", ");
                    }

                    output
                    .Append(arg.Key)
                    .Append(" = ")
                    .Append(arg.Value.ToCSharpString());
                }

                output.Append(" }");
            }
        }
示例#6
0
        public static CodeStringBuilder AppendTypeName(this CodeStringBuilder code, string?typeNamespace, string name)
        {
            if (typeNamespace != null)
            {
                code
                .Append("global::")
                .Append(typeNamespace)
                .Append(".");
            }

            var index = name.IndexOf('`');

            if (index > 0)
            {
                code.Append(name.Substring(0, index));
                code.Append("<");
            }
            else
            {
                code.Append(name);
            }

            return(code);
        }
示例#7
0
 public static CodeStringBuilder AppendType(this CodeStringBuilder code, Type type)
 {
     return(AppendTypeName(code, type.Namespace, type.Name));
 }
示例#8
0
 public static CodeStringBuilder AppendMessageOrDefault(this CodeStringBuilder code, MessageDescription?message)
 {
     return(AppendMessage(code, message ?? MessageDescription.Empty));
 }
示例#9
0
 public void GenerateMemberDeclaration(CodeStringBuilder output)
 {
     Output = output;
     Generate();
 }
示例#10
0
 public void BeforeEachTest()
 {
     _sut = new CodeStringBuilder();
 }
示例#11
0
 public Indenter(CodeStringBuilder owner)
 {
     _owner = owner;
     owner._writer.Indent++;
 }