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