本文整理汇总了C#中FieldDefinition.GetGeneric方法的典型用法代码示例。如果您正苦于以下问题:C# FieldDefinition.GetGeneric方法的具体用法?C# FieldDefinition.GetGeneric怎么用?C# FieldDefinition.GetGeneric使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FieldDefinition
的用法示例。
在下文中一共展示了FieldDefinition.GetGeneric方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InjectField
void InjectField(TypeDefinition type, FieldDefinition fieldDefinition)
{
var staticConstructor = type.GetStaticConstructor();
staticConstructor.Body.SimplifyMacros();
var genericInstanceMethod = new GenericInstanceMethod(forContextDefinition);
if (type.IsCompilerGenerated() && type.IsNested)
{
genericInstanceMethod.GenericArguments.Add(type.DeclaringType.GetGeneric());
}
else
{
genericInstanceMethod.GenericArguments.Add(type.GetGeneric());
}
var instructions = staticConstructor.Body.Instructions;
type.Fields.Add(fieldDefinition);
var returns = instructions.Where(_ => _.OpCode == OpCodes.Ret)
.ToList();
var ilProcessor = staticConstructor.Body.GetILProcessor();
foreach (var returnInstruction in returns)
{
var newReturn = Instruction.Create(OpCodes.Ret);
ilProcessor.InsertAfter(returnInstruction, newReturn);
ilProcessor.InsertBefore(newReturn, Instruction.Create(OpCodes.Call, genericInstanceMethod));
ilProcessor.InsertBefore(newReturn, Instruction.Create(OpCodes.Stsfld, fieldDefinition.GetGeneric()));
returnInstruction.OpCode = OpCodes.Nop;
}
staticConstructor.Body.OptimizeMacros();
}
示例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);
}
示例4: WeaveEvent
// Thank you to Romain Verdier
// largely copied from http://codingly.com/2008/11/10/introduction-a-monocecil-implementer-inotifypropertychanging/
void WeaveEvent(TypeDefinition type)
{
var propertyChangingFieldDef = new FieldDefinition("PropertyChanging", FieldAttributes.Private, PropChangingHandlerReference);
type.Fields.Add(propertyChangingFieldDef);
var propertyChangingField = propertyChangingFieldDef.GetGeneric();
var eventDefinition = new EventDefinition("PropertyChanging", EventAttributes.None, PropChangingHandlerReference)
{
AddMethod = CreateEventMethod("add_PropertyChanging", DelegateCombineMethodRef, propertyChangingField),
RemoveMethod = CreateEventMethod("remove_PropertyChanging", DelegateRemoveMethodRef, propertyChangingField)
};
type.Methods.Add(eventDefinition.AddMethod);
type.Methods.Add(eventDefinition.RemoveMethod);
type.Events.Add(eventDefinition);
}
示例5: CreateSignaledField
void CreateSignaledField()
{
var field = new FieldDefinition("disposeSignaled", FieldAttributes.Private, typeSystem.Int32);
TargetType.Fields.Add(field);
signaledField = field.GetGeneric();
}
示例6: CreateDisposedField
void CreateDisposedField()
{
var field = new FieldDefinition("disposed", FieldAttributes.Private, typeSystem.Boolean);
TargetType.Fields.Add(field);
disposedField = field.GetGeneric();
}