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


C# FieldDefinition.GetGeneric方法代码示例

本文整理汇总了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();
    }
开发者ID:vlaci,项目名称:Anotar,代码行数:31,代码来源: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

示例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);
    }
开发者ID:mdabbagh88,项目名称:PropertyChanging,代码行数:17,代码来源:InterfaceInjector.cs

示例5: CreateSignaledField

 void CreateSignaledField()
 {
     var field = new FieldDefinition("disposeSignaled", FieldAttributes.Private, typeSystem.Int32);
     TargetType.Fields.Add(field);
     signaledField = field.GetGeneric();
 }
开发者ID:modulexcite,项目名称:Janitor,代码行数:6,代码来源:TypeProcessor.cs

示例6: CreateDisposedField

 void CreateDisposedField()
 {
     var field = new FieldDefinition("disposed", FieldAttributes.Private, typeSystem.Boolean);
     TargetType.Fields.Add(field);
     disposedField = field.GetGeneric();
 }
开发者ID:modulexcite,项目名称:Janitor,代码行数:6,代码来源:TypeProcessor.cs


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