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("]")); }
public void WriteNewAttribute(AttributeData attribute, string expected) { var output = new CodeStringBuilder(); CSharpServiceEndpointBinderBuilder.WriteNewAttribute(output, attribute); output.AsStringBuilder().ToString().ShouldBe(expected); }
public static CodeStringBuilder AppendArgumentNullException(this CodeStringBuilder code, string paramName) { return(code .Append("if (") .Append(paramName) .Append(" == null) throw new ArgumentNullException(\"") .Append(paramName) .AppendLine("\");")); }
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); }
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(" }"); } }
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); }
public static CodeStringBuilder AppendType(this CodeStringBuilder code, Type type) { return(AppendTypeName(code, type.Namespace, type.Name)); }
public static CodeStringBuilder AppendMessageOrDefault(this CodeStringBuilder code, MessageDescription?message) { return(AppendMessage(code, message ?? MessageDescription.Empty)); }
public void GenerateMemberDeclaration(CodeStringBuilder output) { Output = output; Generate(); }
public void BeforeEachTest() { _sut = new CodeStringBuilder(); }
public Indenter(CodeStringBuilder owner) { _owner = owner; owner._writer.Indent++; }