本文整理汇总了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());
}
示例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());
}
示例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());
}
示例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()};
}
示例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));
}
示例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);
}