static void Main(string[] args) { var codeFile = new CodeFile { DefinedInNamespace = "BlueprintTech.CodeGeneration.Test", UsingNamespaces = new[] { "System" }, ClassName = "ACodeGenerationTestClass", AccessModifiers = new[] { SyntaxKind.PublicKeyword, SyntaxKind.StaticKeyword }, Members = () => new[] { Methods.Header("Test", Types.Void) .WithModifiers(Tokens.StaticModifier) .WithBody( Invocations.Invoke("Console", "WriteLine", "Hello world!".AsLiteral().AsArgument()) .AsStatement().AsBlock()) } }; File.WriteAllText("ACodeGenerationTestClass.cs", codeFile.Definition()); }
public void Generate(string definedInNamespace, IEnumerable <T> instances, string file) { var instancesAr = instances.ToArray(); var member = new[] { Constructs.Class(MetadataResolver.DataDirectoryToOperateIn, new[] { SyntaxKind.PublicKeyword, SyntaxKind.StaticKeyword, SyntaxKind.PartialKeyword }, () => SyntaxFactory.List(SubClass(instancesAr)) ) }; var namespaces = instancesAr.Select(i => i.GetType().Namespace) .Union(Mapper.FoundTypes.SelectMany(ExtractNamespaces)) .Except(new[] { "System" }) .Distinct(); var codeFile = new CodeFile { DefinedInNamespace = definedInNamespace, UsingNamespaces = namespaces, ClassName = "Factory", AccessModifiers = new[] { SyntaxKind.PublicKeyword, SyntaxKind.StaticKeyword, SyntaxKind.PartialKeyword }, Members = () => member }; File.WriteAllText(file, codeFile.Definition()); }