Exemple #1
0
        protected sealed override void Run()
        {
            if (!CodeGeneratorConfigurationUtility.TryParseLanguage(Language, out var codeGeneratorLanguage))
            {
                throw new BuildErrorException(Strings.UnsupportedLanguageFmt, Language ?? "<null>");
            }

            if (StringUtility.IsNullOrEmpty(OutputPath))
            {
                throw new BuildErrorException(Strings.MissingParameterFmt, nameof(OutputPath));
            }

            var generatedCode = new GeneratedCode(codeGeneratorLanguage, GetCodeFragments());
            var code          = CodeGenerator.GenerateCode(generatedCode);

            File.WriteAllText(OutputPath, code, Encoding.UTF8);
        }
Exemple #2
0
        public void GenerateCode_ReturnsNonEmptyString(string languageStr)
        {
            var assemblyAttribute = new AssemblyAttribute(
                "System.Runtime.InteropServices.ComVisible",
                new[] { new OrderedParameter(false) });

            var thisAssemblyClass = new ThisAssemblyClass(
                null,
                "ThisAssembly",
                new[] { new Constant("Answer", 42) });

            _ = CodeGeneratorConfigurationUtility.TryParseLanguage(languageStr, out var language);
            var configuration = new GeneratedCode(
                language,
                new CodeFragment[] { assemblyAttribute, thisAssemblyClass });

            var code = CodeGenerator.GenerateCode(configuration);

            Assert.IsNotNull(code);
            Assert.IsNotEmpty(code);
        }