本文整理汇总了C#中CodeGenerator类的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerator类的具体用法?C# CodeGenerator怎么用?C# CodeGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeGenerator类属于命名空间,在下文中一共展示了CodeGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
try
{
Parameter = ProjectParameter.GetSettingsByProjectName(CurrentSession.UserCode, ProjectName);
Generator = new CodeGenerator(Parameter);
ColumnInfos = Generator.GetColumnsInfo(TableName, PrimaryKeyOverwrite);
ReferFolder = Path.Combine(Server.MapPath(".."), "Manage\\Refer");
OutputFolder = Path.Combine(Server.MapPath(".."), string.Concat("Manage\\", CurrentSession.UserCode, "\\", TableName));
if (!System.IO.Directory.Exists(OutputFolder)) System.IO.Directory.CreateDirectory(OutputFolder);
switch (type)
{
case 1:
Search();
Callback();
Result();
Edit();
GetTogether.Mapping.MappingInfoCache.Caches.Clear();
if (!string.IsNullOrEmpty(Request["download"]))
Compress(OutputFolder, string.Concat(OutputFolder, "-Management.zip"));
break;
default:
break;
}
JsonSuccess();
}
catch (Exception ex)
{
JsonError(ex.Message);
}
}
示例2: CSharpTarget
protected CSharpTarget(CodeGenerator gen, string language)
: base(gen, language)
{
targetCharValueEscape[0] = "\\0";
targetCharValueEscape[0x0007] = "\\a";
targetCharValueEscape[0x000B] = "\\v";
}
示例3: CompileTemplate
public override TemplateInfo CompileTemplate(string templateBody, Dictionary<string, Type> globalsTypes, List<Assembly> referencedAssemblies)
{
lock (_templateInfoCacheLock)
{
// Generate template program
TemplateInfo ti = GenerateTemplateProgram(templateBody, globalsTypes, referencedAssemblies);
// Generated template found in cache
if (_templateInfoCache.ContainsKey(ti.TemplateKey))
{
return _templateInfoCache[ti.TemplateKey];
}
// Generate code
ICodeGenerator codeGenerator = new CodeGenerator();
ti.GeneratedSourceCode = codeGenerator.GenerateCode(ti);
// Generate assembly
var assemblyCompiler = new AssemblyGenerator();
Assembly assembly = assemblyCompiler.GenerateAssembly(ti, true, null, null);
// Try to load the Render() method from assembly
ti.RenderMethod = GetTemplateRenderMethod(assembly, ti);
// Try to load the template generator version from assembly
ti.GeneratorVersion = GetTemplateGeneratorVersion(assembly, ti);
_templateInfoCache.Add(ti.TemplateKey, ti);
return ti;
}
}
示例4: GenerateCreateInstanceDelegate
internal CreateInstanceDelegate GenerateCreateInstanceDelegate(Type type, ConstructorInfo constructor)
{
bool allowPrivateMemberAccess = !IsTypeVisible(type) || ConstructorRequiresMemberAccess(constructor);
this.ilg = new CodeGenerator();
try
{
this.ilg.BeginMethod("Create" + type.FullName, typeof(CreateInstanceDelegate), allowPrivateMemberAccess);
}
catch (SecurityException exception)
{
if (!allowPrivateMemberAccess || !exception.PermissionType.Equals(typeof(ReflectionPermission)))
{
throw;
}
if (DiagnosticUtility.ShouldTraceWarning)
{
DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning);
}
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityException(System.ServiceModel.SR.GetString("PartialTrustServiceCtorNotVisible", new object[] { type.FullName })));
}
if (type.IsValueType)
{
LocalBuilder local = this.ilg.DeclareLocal(type, type.Name + "Instance");
this.ilg.LoadZeroValueIntoLocal(type, local);
this.ilg.Load(local);
}
else
{
this.ilg.New(constructor);
}
this.ilg.ConvertValue(type, this.ilg.CurrentMethod.ReturnType);
return (CreateInstanceDelegate) this.ilg.EndMethod();
}
示例5: MultipleParameterGeneratesCode
public void MultipleParameterGeneratesCode()
{
// Arrange
IContainer container = new Container ();
container.Register<ISimpleObject, SimpleObject> ();
container.Register<IShallowDependent, ShallowDependent> ();
container.Register<IDeepDependent, DeepDependent> ();
container.Register<IMultipleParameterObject, MultipleParameterObject> ();
CodeGenerator codeGenerator = new CodeGenerator ();
MemoryStream memoryStream = new MemoryStream ();
// Act
codeGenerator.WriteToStream(LanguageEnum.Csharp, container, memoryStream, "SomeNamespace", "TestContainer");
memoryStream.Position = 0;
string charpString;
using (StreamReader reader = new StreamReader(memoryStream)) {
charpString = reader.ReadToEnd ();
}
TestContainer testContainer = new TestContainer ();
IMultipleParameterObject result = testContainer.Resolve<IMultipleParameterObject> ();
// Assert
Assert.IsNotNull (result);
Assert.IsNotNull (result.ShallowDependent);
Assert.IsNotNull (result.SimpleObject);
}
开发者ID:JamesRandall,项目名称:AccidentalFish.Xamarin.DependencyInjection,代码行数:26,代码来源:CsharpGeneratorTests.cs
示例6: 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());
}
示例7: ConstantQuery
//---------------------------------------------------------------------
public static void ConstantQuery(OleDbConnection dbcon, CodeGenerator cg)
{
cg.ConstantList.Clear();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM Constants ORDER BY Topic, ID", dbcon);
OleDbDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Constant curConst = new Constant();
curConst.Name = dr["Name"].ToString();
curConst.Value = dr["Value"].ToString();
Int32 nTopic = Convert.ToInt32(dr["Topic"].ToString());
if (nTopic > 0)
{
curConst.Topic = cg.TopicList[nTopic - 1].Name.ToString();
}
else
{
curConst.Topic = "";
}
curConst.Description = dr["Description"].ToString();
cg.ConstantList.Add(curConst);
//curConst.Print();
}
dr.Close();
}
示例8: DatatypeQuery
//---------------------------------------------------------------------
public static void DatatypeQuery(OleDbConnection dbcon, CodeGenerator cg)
{
cg.DataTypeList.Clear();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM DataTypes", dbcon);
OleDbDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
DataType curDatatype = new DataType();
curDatatype.ID = Convert.ToInt32(dr["ID"].ToString());
curDatatype.DataTypeName = dr["DataTypeName"].ToString();
curDatatype.CType = dr["CType"].ToString();
curDatatype.CTypeDef = dr["CTypeDef"].ToString();
curDatatype.CSType = dr["CSType"].ToString();
curDatatype.CSTypeDef = dr["CSTypeDef"].ToString();
curDatatype.VBType = dr["VBType"].ToString();
curDatatype.VBTypeDef = dr["VBTypeDef"].ToString();
curDatatype.PythonType = dr["PythonType"].ToString();
curDatatype.PythonTypeDef = dr["PythonTypeDef"].ToString();
cg.DataTypeList.Add(curDatatype);
}
dr.Close();
}
示例9: 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());
}
示例10: GenerateCreateXmlSerializableDelegate
internal System.Runtime.Serialization.CreateXmlSerializableDelegate GenerateCreateXmlSerializableDelegate()
{
Type underlyingType = base.UnderlyingType;
CodeGenerator generator = new CodeGenerator();
bool allowPrivateMemberAccess = this.RequiresMemberAccessForCreate(null);
try
{
generator.BeginMethod("Create" + DataContract.GetClrTypeFullName(underlyingType), typeof(System.Runtime.Serialization.CreateXmlSerializableDelegate), allowPrivateMemberAccess);
}
catch (SecurityException exception)
{
if (!allowPrivateMemberAccess || !exception.PermissionType.Equals(typeof(ReflectionPermission)))
{
throw;
}
this.RequiresMemberAccessForCreate(exception);
}
if (underlyingType.IsValueType)
{
LocalBuilder localBuilder = generator.DeclareLocal(underlyingType, underlyingType.Name + "Value");
generator.Ldloca(localBuilder);
generator.InitObj(underlyingType);
generator.Ldloc(localBuilder);
}
else
{
generator.New(this.GetConstructor());
}
generator.ConvertValue(base.UnderlyingType, Globals.TypeOfIXmlSerializable);
generator.Ret();
return (System.Runtime.Serialization.CreateXmlSerializableDelegate) generator.EndMethod();
}
示例11: DecorateCodeGenerator
public override CodeGenerator DecorateCodeGenerator(CodeGenerator generator, CodeGeneratorContext context)
{
String type = ChunkHelper.GetModelTypeName(context.ChunkTreeBuilder.Root, "dynamic");
DefaultBaseClass = $"Genny.GennyTemplate<{type}>";
return base.DecorateCodeGenerator(generator, context);
}
示例12: SourceInfo
public SourceInfo(string source, string arg, MemberInfo memberInfo, Type type, CodeGenerator ilg) {
this.Source = source;
this.Arg = arg ?? source;
this.MemberInfo = memberInfo;
this.Type = type;
this.ILG = ilg;
}
示例13: CreateCodeFile
private void CreateCodeFile(CodeGenerator generator)
{
using (IndentedTextWriter writer = CreateWriter(generator.Name + ".cs"))
{
generator.Write(writer, _Types);
Close(writer);
}
}
示例14: Main
static void Main(string[] args)
{
if (args.Length != 3)
{
PrintUsage();
return;
}
try
{
string destinationNamespace = args[0].Substring(3);
string wsdlLocation = args[1].Substring(3);
string outputFolder = args[2].Substring(3); ;
CodeGenerator codeGen = new CodeGenerator();
CodeGenerationOptions options = new CodeGenerationOptions();
options.GenerateDataContracts = false;
options.GenerateProperties = true;
options.GenerateCollections = false;
options.GenerateSeparateFiles = false;
options.OverwriteExistingFiles = true;
options.AdjustCasing = false;
options.EnableDataBinding = false;
options.GenerateOrderIdentifiers = true;
options.GenerateTypedLists = true;
options.ClrNamespace = destinationNamespace;
options.OutputFileName = destinationNamespace + ".cs";
options.OutputLocation = outputFolder;
options.ProjectDirectory = outputFolder;
options.Language = CodeLanguage.CSharp;
options.ConfigurationFile = "App.config";
options.EnableWsdlEndpoint = false;
options.FormatSoapActions = false;
options.GenerateAsyncCode = false;
options.GenerateService = false;
options.GenerateSvcFile = true;
options.ConcurrencyMode = "Single";
options.InstanceContextMode = "PerCall";
options.MetadataLocation = wsdlLocation;
options.MethodImplementation = MethodImplementation.NotImplementedException;
options.UseSynchronizationContext = true;
codeGen.GenerateCode(options);
}
catch (Exception e)
{
System.Console.WriteLine("Exception: " + e.Message);
PrintUsage();
}
}
示例15: EmitCreateTargetInstance
private static void EmitCreateTargetInstance(Type targetType, TypeBuilder typeBuilder)
{
MethodBuilder methodBuilder = typeBuilder.DefineMethod(CreateTargetInstanceMethod, OverrideProtected, targetType, Type.EmptyTypes);
var codeGenerator = new CodeGenerator(methodBuilder.GetILGenerator());
IEmitterType result = targetType.IsValueType ? EmitValueType(targetType, codeGenerator) : EmitRefType(targetType);
EmitReturn.Return(result, targetType).Emit(codeGenerator);
}