当前位置: 首页>>代码示例>>C#>>正文


C# CodeGenerator.Generate方法代码示例

本文整理汇总了C#中CodeGenerator.Generate方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerator.Generate方法的具体用法?C# CodeGenerator.Generate怎么用?C# CodeGenerator.Generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CodeGenerator的用法示例。


在下文中一共展示了CodeGenerator.Generate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestBuildCode

        protected void TestBuildCode(string classFileName, DocumentType contentType, string contentTypeName)
        {
            string expectedOutput;
            using (var goldReader = File.OpenText(@"..\..\TestFiles\" + classFileName + ".cs"))
            {
                expectedOutput = goldReader.ReadToEnd();
            }

            var configuration = CodeGeneratorConfiguration.Create();
            var typeConfig = configuration.Get(contentTypeName);
            typeConfig.BaseClass = "Umbraco.Core.Models.TypedModelBase";
            typeConfig.Namespace = "Umbraco.CodeGen.Models";

            configuration.TypeMappings.Add(new TypeMapping("Umbraco.Integer", "Int32"));

            OnConfiguring(configuration, contentTypeName);

            var sb = new StringBuilder();
            var writer = new StringWriter(sb);

            var dataTypeProvider = new TestDataTypeProvider();
            var generator = new CodeGenerator(typeConfig, dataTypeProvider, CreateGeneratorFactory());

            generator.Generate(contentType, writer);

            writer.Flush();
            Console.WriteLine(sb.ToString());

            Assert.AreEqual(expectedOutput, sb.ToString());
        }
开发者ID:scy0846,项目名称:Umbraco.CodeGen,代码行数:30,代码来源:CodeGeneratorAcceptanceTestBase.cs

示例2: TestBuildCode

		private static void TestBuildCode(string fileName, string contentTypeName)
		{
		    ContentType contentType;
			var expectedOutput = "";
			using (var inputReader = File.OpenText(@"..\..\TestFiles\" + fileName + ".xml"))
			{
                contentType = new ContentTypeSerializer().Deserialize(inputReader);
            }
            using (var goldReader = File.OpenText(@"..\..\TestFiles\" + fileName + ".cs"))
			{
				expectedOutput = goldReader.ReadToEnd();
			}

			var configuration = new CodeGeneratorConfiguration();
		    configuration.TypeMappings.Add(new TypeMapping("1413afcb-d19a-4173-8e9a-68288d2a73b8", "Int32"));
		    var typeConfig = configuration.Get(contentTypeName);
		    typeConfig.BaseClass = "DocumentTypeBase";
		    typeConfig.Namespace = "Umbraco.CodeGen.Models";

		    var sb = new StringBuilder();
			var writer = new StringWriter(sb);

		    var factory = new DefaultCodeGeneratorFactory();
		    var dataTypeProvider = new TestDataTypeProvider();
		    var generator = new CodeGenerator(typeConfig, dataTypeProvider, factory);
		    generator.Generate(contentType, writer);

            writer.Flush();
            Console.WriteLine(sb.ToString());

			Assert.AreEqual(expectedOutput, sb.ToString());
		}
开发者ID:jkarsrud,项目名称:Umbraco.CodeGen,代码行数:32,代码来源:CodeGeneratorAcceptanceTests.cs

示例3: Generate

        static void Generate(string DllPath)
        {
            string[] ExportStrings = CppHelper.GetExports(DllPath);

            List<SymbolPrototype> ExportList = new List<SymbolPrototype>();
            foreach (var E in ExportStrings) {
                try {
                    ExportList.Add(new SymbolPrototype(E));
                } catch (Exception) {
                }
            }

            foreach (var Export in ExportList)
                Console.WriteLine(Export);

            CodeGenerator Gen = new CodeGenerator(ExportList, Path.GetFileNameWithoutExtension(DllPath));
            if (File.Exists("Test.cs"))
                File.Delete("Test.cs");
            File.WriteAllText("Test.cs", Gen.Generate());
        }
开发者ID:cartman300,项目名称:Pinevoke,代码行数:20,代码来源:Program.cs

示例4: GetPreview

        public CodeDto GetPreview(int id)
        {
            var docType = ApplicationContext.Services.ContentTypeService.GetAllContentTypes(id).Single();
            var contentPath = ApplicationContext.Services.ContentTypeService.GetAllContentTypes(docType.Path.Split(',').Select(p => Convert.ToInt32(p)).ToArray());
            var defPath = "~/usync/" + "DocumentType/" + String.Join("/", contentPath.Select(c => c.Alias)) + "/def.config";
            var inputPath = HttpContext.Current.Server.MapPath(defPath);

            var typeConfig = inputPath.Contains("DocumentType")
                ? Integration.Configuration.CodeGen.DocumentTypes
                : Integration.Configuration.CodeGen.MediaTypes;

            Definitions.ContentType contentType;
            using (var reader = File.OpenText(inputPath))
                contentType = serializer.Deserialize(reader);

            var generatorFactory = ApplicationEvents.CreateFactory<CodeGeneratorFactory>(Integration.Configuration.CodeGen.GeneratorFactory);
            var classGenerator = new CodeGenerator(typeConfig, Integration.Configuration.DataTypesProvider, generatorFactory);
            var builder = new StringBuilder();
            using (var stream = new StringWriter(builder))
                classGenerator.Generate(contentType, stream);

            return new CodeDto {Name = docType.Name, Code = builder.ToString()};
        }
开发者ID:scy0846,项目名称:Umbraco.CodeGen,代码行数:23,代码来源:PreviewController.cs

示例5: GenerateModel

        private void GenerateModel(ContentType contentType, CodeGeneratorFactory specificGeneratorFactory, Func<ContentType, string> fileNameGetter)
        {
            var typeConfig = contentType is DocumentType
                ? configuration.DocumentTypes
                : configuration.MediaTypes;

            if (!typeConfig.GenerateClasses)
                return;

            var itemStart = DateTime.Now;

            LogHelper.Debug<CodeGenerator>(
                () => String.Format("Content type {0} saved, generating typed model", contentType.Name));
            LogHelper.Info<CodeGenerator>(() => String.Format("Generating typed model for {0}", contentType.Alias));

            var modelPath = EnsureModelPath(typeConfig);
            var path = GetPath(modelPath, fileNameGetter(contentType));
            RemoveReadonly(path);

            var classGenerator = new CodeGenerator(typeConfig, dataTypeProvider, specificGeneratorFactory);
            using (var stream = System.IO.File.CreateText(path))
                classGenerator.Generate(contentType, stream);

            LogHelper.Debug<CodeGenerator>(
                () => String.Format("Typed model for {0} generated. Took {1}", contentType.Alias, DateTime.Now - itemStart));
        }
开发者ID:scy0846,项目名称:Umbraco.CodeGen,代码行数:26,代码来源:ModelGenerator.cs

示例6: RunTest

        private void RunTest(string input, string expected, Dictionary<string, object> properties, Action<Template> check)
        {
            CodeGenerator codeGenerator = new CodeGenerator();
            string code = codeGenerator.Generate(input, new CodeGeneratorParameters()).Code;

            Template template;
            string actual;

            try
            {
                Compiler compiler = new Compiler();
                template = compiler.CompileTemplate(input, new CompilerParameters());

                foreach (var pair in properties)
                {
                    template.SetPropertyValue(pair.Key, pair.Value);
                }

                actual = template.Run();

                Console.WriteLine("=== Output ===");
                Console.WriteLine(actual);
            }
            finally
            {
                Console.WriteLine("=== Code ===");
                Console.WriteLine(code);
            }

            expected = expected.Replace(Environment.NewLine, string.Empty);
            actual = actual.Replace(Environment.NewLine, string.Empty);

            Assert.AreEqual(expected, actual);

            check(template);
        }
开发者ID:smack0007,项目名称:Machete,代码行数:36,代码来源:IntegrationTests.cs


注:本文中的CodeGenerator.Generate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。