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


C# TypeDefinition.GetStaticConstructor方法代码示例

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


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

示例1: InjectField

	void InjectField(TypeDefinition type, FieldDefinition fieldDefinition)
	{
		var staticConstructor = type.GetStaticConstructor();
		var instructions = staticConstructor.Body.Instructions;

	    if (type.HasGenericParameters)
	    {
	        instructions.Insert(0, Instruction.Create(OpCodes.Call, buildLoggerGenericMethod));
	        instructions.Insert(1, Instruction.Create(OpCodes.Stsfld, fieldDefinition.GetGeneric()));
	    }
	    else
	    {
	        var logName = type.FullName;
	        if (type.IsCompilerGenerated() && type.IsNested)
	        {
	            logName = type.DeclaringType.FullName;
	        }

	        instructions.Insert(0, Instruction.Create(OpCodes.Ldstr, logName));
	        instructions.Insert(1, Instruction.Create(OpCodes.Call, buildLoggerMethod));
	        instructions.Insert(2, Instruction.Create(OpCodes.Stsfld, fieldDefinition));
	    }

	    type.Fields.Add(fieldDefinition);
	}
开发者ID:vlaci,项目名称:Anotar,代码行数:25,代码来源:TypeProcessor.cs

示例2: InjectField

    void InjectField(TypeDefinition type, FieldDefinition fieldDefinition)
    {
        var staticConstructor = type.GetStaticConstructor();
        var instructions = staticConstructor.Body.Instructions;

        instructions.Insert(0, Instruction.Create(OpCodes.Ldstr, type.FullName));
        instructions.Insert(1, Instruction.Create(OpCodes.Call, buildLoggerMethod));
        instructions.Insert(2, Instruction.Create(OpCodes.Stsfld, fieldDefinition.GetGeneric()));
        type.Fields.Add(fieldDefinition);
    }
开发者ID:GeorgeHahn,项目名称:Anotar,代码行数:10,代码来源:TypeProcessor.cs

示例3: InjectField

    void InjectField(TypeDefinition type, FieldDefinition fieldDefinition)
	{
        var logName = type.GetNonCompilerGeneratedType().FullName;
		var staticConstructor = type.GetStaticConstructor();
	    var instructions = staticConstructor.Body.Instructions;
	    instructions.Insert(0, Instruction.Create(OpCodes.Call, GetDefaultLogManager));
        instructions.Insert(1, Instruction.Create(OpCodes.Ldstr, logName));
	    instructions.Insert(2, Instruction.Create(OpCodes.Ldnull));
	    instructions.Insert(3, Instruction.Create(OpCodes.Callvirt, constructLoggerMethod));
	    instructions.Insert(4, Instruction.Create(OpCodes.Stsfld, fieldDefinition.GetGeneric()));
	    type.Fields.Add(fieldDefinition);
    }
开发者ID:AndreGleichner,项目名称:Anotar,代码行数:12,代码来源:TypeProcessor.cs


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