public void Run(string path, IEnumerable <SyntaxTree> syntaxForrest)
        {
            var codeBuilder = new StringBuilder();

            WriteUsingList(path, codeBuilder, syntaxForrest);
            WriteClassHeader(codeBuilder);

            var useCaseSyntaxForrest = syntaxForrest
                                       .Where(tree => tree.GetRoot()
                                              .DescendantNodes().OfType <NamespaceDeclarationSyntax>().Any())
                                       .Where(tree => tree.GetRoot()
                                              .DescendantNodes().OfType <NamespaceDeclarationSyntax>()
                                              .First().Name.ToString().Contains(SourceNamespace));

            foreach (var syntaxTree in useCaseSyntaxForrest)
            {
                var sourceType = syntaxTree.GetRoot().DescendantNodes().OfType <ClassDeclarationSyntax>().FirstOrDefault();

                if (sourceType != null)
                {
                    var className = sourceType.Identifier.Text;

                    if (className.EndsWith(ClassNamePostfix))
                    {
                        codeBuilder.Append($"services.AddScoped<I{className}, {className}>();");
                    }
                }
            }

            WriteClassFooter(codeBuilder);

            SourceCodeWriter.Write(
                codeBuilder.ToString(),
                Path.Combine(path, "Generated", GeneratedFileName));
        }
        public void Run(string path, IEnumerable <SyntaxTree> syntaxForrest)
        {
            var mappingExtensionBuilder = new StringBuilder();
            var mappingProfileBuilder   = new StringBuilder();

            WriteUsingList(mappingExtensionBuilder, syntaxForrest);
            WriteUsingList(mappingProfileBuilder, syntaxForrest);

            WriteExtensionsClassHeader(mappingExtensionBuilder);
            WriteProfileClassHeader(mappingProfileBuilder);

            GenerateMappings(syntaxForrest, mappingExtensionBuilder, mappingProfileBuilder);

            WriteExtensionsClassFooter(mappingExtensionBuilder);
            WriteProfileClassFooter(mappingProfileBuilder);

            Directory.CreateDirectory(Path.Combine(path, "Generated"));

            SourceCodeWriter.Write(
                mappingExtensionBuilder.ToString(),
                Path.Combine(path, "Generated", "MappingExtensions.cs"));
            SourceCodeWriter.Write(
                mappingProfileBuilder.ToString(),
                Path.Combine(path, "Generated", "GeneratedMappingProfile.cs"));
        }
Ejemplo n.º 3
0
 protected override void WriteAfterLiteralBody(SourceCodeWriter tw)
 {
     tw.UnShift();
     if (!string.IsNullOrWhiteSpace(tw.Context.Namespace))
     {
         tw.UnShift();
     }
 }
Ejemplo n.º 4
0
 protected SourceCodeWriter.StoredState ShelveSourceDefinitionBegin(IILDynamicType target)
 {
     if ((_sourceCodeWriter = target.TryGetSourceCodeWriter()) != null)
     {
         return(_sourceCodeWriter.ShelveBegin());
     }
     return(null);
 }
Ejemplo n.º 5
0
        protected override void WriteImport(SourceCodeWriter tw, string namespaceName)
        {
            var required = IsRequiredSelfHostingMetadataAttribute(tw.Context);

            if (required)
            {
                tw.WriteLine("#pragma warning disable 436");
                tw.WriteLine();
            }

            tw.WriteLine("using {0};", namespaceName);
        }
Ejemplo n.º 6
0
 public void GenerateSupportFilesIfNeeded(NPath outputDir)
 {
     string[] append = new string[] { "document-debug-info.h" };
     using (SourceCodeWriter writer = new SourceCodeWriter(outputDir.Combine(append)))
     {
         this.WriteDocumentDebugInfoHeader(writer);
     }
     string[] textArray2 = new string[] { "document-debug-info.cpp" };
     using (SourceCodeWriter writer2 = new SourceCodeWriter(outputDir.Combine(textArray2)))
     {
         this.WriteDocumentDebugInfoSource(writer2);
     }
 }
Ejemplo n.º 7
0
        protected override void WriteBeforeLiteralBody(SourceCodeWriter tw)
        {
            if (!string.IsNullOrWhiteSpace(tw.Context.Namespace))
            {
                tw.WriteLine("namespace {0}", tw.Context.Namespace);
                tw.WriteLine("{");
                tw.Shift();
            }

            tw.WriteLine("internal static class ThisAssembly");
            tw.WriteLine("{");
            tw.Shift();
        }
Ejemplo n.º 8
0
        protected override void WriteBeforeLiteralBody(SourceCodeWriter tw)
        {
            if (!string.IsNullOrWhiteSpace(tw.Context.Namespace))
            {
                tw.WriteLine("namespace {0}", tw.Context.Namespace);
                tw.WriteLine("{");
                tw.Shift();
            }

            tw.WriteLine("private ref class ThisAssembly abstract sealed");
            tw.WriteLine("{");
            tw.WriteLine("public:");
            tw.Shift();
        }
Ejemplo n.º 9
0
        public static string[] WriteSourceCode(
            CodeTextStorage storage,
            TranslateContext translateContext,
            PreparedInformations prepared,
            bool enableBundler,
            DebugInformationOptions debugInformationOption)
        {
            var sourceFilePaths = new List <string>();

            var assemblyName = translateContext.Assembly.Name;

            // Write assembly level common internal header.
            HeaderWriter.WriteCommonInternalHeader(
                storage,
                translateContext,
                prepared,
                assemblyName);

            // Write assembly level common internal source code.
            sourceFilePaths.Add(
                SourceCodeWriter.WriteCommonInternalSourceCode(
                    storage,
                    translateContext,
                    prepared,
                    assemblyName));

            // Write source code bundler.
            if (enableBundler)
            {
                SourceCodeWriter.WriteBundlerSourceCode(
                    storage,
                    prepared,
                    assemblyName);
            }

            using (var _ = storage.EnterScope(assemblyName, false))
            {
                // Write source codes.
                sourceFilePaths.AddRange(
                    SourceCodeWriter.WriteSourceCodes(
                        storage,
                        translateContext,
                        prepared,
                        debugInformationOption));
            }

            return(sourceFilePaths.ToArray());
        }
Ejemplo n.º 10
0
        protected override void WriteBeforeLiteralBody(SourceCodeWriter tw)
        {
            tw.WriteLine("do()");
            tw.UnShift();
            tw.WriteLine();

            if (!string.IsNullOrWhiteSpace(tw.Context.Namespace))
            {
                tw.WriteLine("namespace {0}", tw.Context.Namespace);
            }
            else
            {
                tw.WriteLine("namespace global");
            }
            tw.Shift();

            tw.WriteLine("module internal ThisAssembly =");
            tw.Shift();
        }
Ejemplo n.º 11
0
        protected override void WriteBeforeBody(SourceCodeWriter tw)
        {
            tw.WriteLine("#include \"stdafx.h\"");
            tw.WriteLine();

            var required = IsRequiredSelfHostingMetadataAttribute(tw.Context);

            if (!required)
            {
                tw.WriteLine("#if defined(NET20) || defined(NET30) || defined(NET35) || defined(NET40)");
                tw.WriteLine();
            }

            tw.WriteLine("namespace System");
            tw.WriteLine("{");
            tw.WriteLine("	namespace Reflection");
            tw.WriteLine("	{");
            tw.WriteLine("		[System::AttributeUsage(System::AttributeTargets::Assembly, AllowMultiple = true, Inherited = false)]");
            tw.WriteLine("		private ref class AssemblyMetadataAttribute sealed : public System::Attribute");
            tw.WriteLine("		{");
            tw.WriteLine("		private:");
            tw.WriteLine("			System::String^ key_;");
            tw.WriteLine("			System::String^ value_;");
            tw.WriteLine("		public:");
            tw.WriteLine("			AssemblyMetadataAttribute(System::String^ key, System::String^ value)");
            tw.WriteLine("				: key_(key), value_(value) { }");
            tw.WriteLine("			property System::String^ Key { System::String^ get() { return key_; } }");
            tw.WriteLine("			property System::String^ Value { System::String^ get() { return value_; } }");
            tw.WriteLine("		};");
            tw.WriteLine("	}");
            tw.WriteLine("}");

            if (!required)
            {
                tw.WriteLine();
                tw.WriteLine("#endif");
            }

            tw.WriteLine();
        }
Ejemplo n.º 12
0
        protected override void WriteAfterBody(SourceCodeWriter tw)
        {
            var required = IsRequiredSelfHostingMetadataAttribute(tw.Context);

            if (!required)
            {
                tw.WriteLine("#if NET10 || NET11 || NET20 || NET30 || NET35 || NET40");
                tw.WriteLine();
            }

            tw.WriteLine("namespace System.Reflection");
            tw.WriteLine("{");
            tw.Shift();
            tw.WriteLine("[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]");
            tw.WriteLine("internal sealed class AssemblyMetadataAttribute : Attribute");
            tw.WriteLine("{");
            tw.Shift();
            tw.WriteLine("public AssemblyMetadataAttribute(string key, string value)");
            tw.WriteLine("{");
            tw.Shift();
            tw.WriteLine("this.Key = key;");
            tw.WriteLine("this.Value = value;");
            tw.UnShift();
            tw.WriteLine("}");
            tw.WriteLine("public string Key { get; private set; }");
            tw.WriteLine("public string Value { get; private set; }");
            tw.UnShift();
            tw.WriteLine("}");
            tw.UnShift();
            tw.WriteLine("}");

            if (!required)
            {
                tw.WriteLine();
                tw.WriteLine("#endif");
            }

            tw.WriteLine();
        }
Ejemplo n.º 13
0
        protected override void WriteBeforeBody(SourceCodeWriter tw)
        {
            var required = IsRequiredSelfHostingMetadataAttribute(tw.Context);

            if (!required)
            {
                tw.WriteLine("#if NET20 || NET30 || NET35 || NET40");
                tw.WriteLine();
            }

            tw.WriteLine("namespace System.Reflection");
            tw.Shift();
            tw.WriteLine("open System");
            tw.WriteLine("[<Sealed>]");
            tw.WriteLine("[<NoEquality>]");
            tw.WriteLine("[<NoComparison>]");
            tw.WriteLine("[<AutoSerializable(false)>]");
            tw.WriteLine("[<AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)>]");
            tw.WriteLine("type internal AssemblyMetadataAttribute(key: string, value: string) =");
            tw.Shift();
            tw.WriteLine("inherit Attribute()");
            tw.WriteLine("member this.Key = key");
            tw.WriteLine("member this.Value = value");
            tw.UnShift();
            tw.UnShift();

            if (!required)
            {
                tw.WriteLine();
                tw.WriteLine("#endif");
            }

            tw.WriteLine();
            tw.WriteLine("namespace global");
            tw.Shift();
        }
Ejemplo n.º 14
0
 protected override void WriteAttribute(SourceCodeWriter tw, string name, string args) =>
 tw.WriteLine("[assembly: {0}({1})];", name.Replace(".", "::"), args);
Ejemplo n.º 15
0
 protected override void WriteImport(SourceCodeWriter tw, string namespaceName) =>
 tw.WriteLine("using namespace {0};", namespaceName.Replace(".", "::"));
Ejemplo n.º 16
0
 protected override void WriteAfterNestedLiteralBody(SourceCodeWriter tw)
 {
     tw.UnShift();
     tw.WriteLine("};");
 }
Ejemplo n.º 17
0
 protected override void WriteAfterBody(SourceCodeWriter tw)
 {
     tw.WriteLine("do()");
     tw.UnShift();
     tw.WriteLine();
 }
Ejemplo n.º 18
0
 public void Write(NPath outputDir)
 {
     string[] append = new string[] { "driver.cpp" };
     using (SourceCodeWriter writer = new SourceCodeWriter(outputDir.Combine(append)))
     {
         this.WriteIncludes(writer);
         this.WriteMainInvoker(writer);
         this.WriteEntryPoint(writer);
         this.WritePlatformSpecificEntryPoints(writer);
     }
 }
Ejemplo n.º 19
0
 protected override void WriteImport(SourceCodeWriter tw, string namespaceName) =>
 tw.WriteLine("open {0}", namespaceName);
Ejemplo n.º 20
0
 protected override void WriteAttribute(SourceCodeWriter tw, string name, string args) =>
 tw.WriteLine("[<assembly: {0}({1})>]", name, args);
Ejemplo n.º 21
0
 protected override void WriteLiteral(SourceCodeWriter tw, string name, string value) =>
 tw.WriteLine("literal System::String^ __identifier({0}) = {1};", name, value);
Ejemplo n.º 22
0
 protected override void WriteLiteral(SourceCodeWriter tw, string name, string value)
 {
     tw.WriteLine("[<Literal>]");
     tw.WriteLine("let ``{0}`` = {1};", name, value);
 }
Ejemplo n.º 23
0
 protected override void WriteBeforeNestedLiteralBody(SourceCodeWriter tw, string name)
 {
     tw.WriteLine("module {0} =", name);
     tw.Shift();
 }
Ejemplo n.º 24
0
 protected override void WriteBeforeNestedLiteralBody(SourceCodeWriter tw, string name)
 {
     tw.WriteLine("ref class {0} abstract sealed", name);
     tw.WriteLine("{");
     tw.Shift();
 }
Ejemplo n.º 25
0
 protected override void WriteBeforeNestedLiteralBody(SourceCodeWriter tw, string name)
 {
     tw.WriteLine("public static class {0}", name);
     tw.WriteLine("{");
     tw.Shift();
 }
Ejemplo n.º 26
0
 protected override void WriteLiteral(SourceCodeWriter tw, string name, string value) =>
 tw.WriteLine("public const string @{0} = {1};", name, value);
Ejemplo n.º 27
0
 protected override void WriteAfterNestedLiteralBody(SourceCodeWriter tw) =>
 tw.UnShift();