public string CreateClass(string csharp, IMethodBuilder methodBuilder, IParameterTransform transform, string classSuffix, params SyntaxKind[] fieldModifiers) { var fieldModifierTokens = fieldModifiers.Length > 0 ? fieldModifiers.Select(f => Token(f)).ToArray() : new SyntaxToken[] { Token(SyntaxKind.PrivateKeyword), Token(SyntaxKind.ReadOnlyKeyword) }; var tree = CSharpSyntaxTree.ParseText(csharp); var root = tree.GetRoot(); var ctor = root.DescendantNodes().OfType <ConstructorDeclarationSyntax>().FirstOrDefault(); if (ctor == null) { return(string.Empty); } return(ClassDeclaration(Identifier(string.Concat(ctor.Identifier.Value, classSuffix))) .WithMembers(List(GetFields(ctor, transform, fieldModifierTokens).Concat(new MemberDeclarationSyntax[] { methodBuilder.Build(ctor, transform) }))) .WithModifiers(TokenList(new SyntaxToken[] { Token(SyntaxKind.PublicKeyword) })) .NormalizeWhitespace() .ToFullString()); }
public void BuildMethod(IMethodBuilder methodBuilder, Type injectionType) { if (methodBuilder == null) throw new ArgumentNullException("methodBuilder"); methodBuilder.Build(_typeBuilder, _injectionSetField, injectionType); }