本文整理汇总了C#中System.Reflection.Emit.FieldBuilder类的典型用法代码示例。如果您正苦于以下问题:C# FieldBuilder类的具体用法?C# FieldBuilder怎么用?C# FieldBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FieldBuilder类属于System.Reflection.Emit命名空间,在下文中一共展示了FieldBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: MixinType
public static void MixinType (TypeBuilder typeBuilder,Type mixinInterfaceType,FieldBuilder mixinField)
{
MethodInfo[] methods = mixinInterfaceType.GetMethods();
foreach (MethodInfo method in methods)
MixinMethod(typeBuilder,method,mixinField);
}
开发者ID:Dawn-of-Light,项目名称:Puzzle.NET,代码行数:7,代码来源:EmitHelper.cs
示例2: Build
public void Build(TypeBuilder typeBuilder, FieldBuilder injectionSetField, Type injectionType)
{
var parameterTypes = new[] { typeof(DbModelBuilder), typeof(DbContext) };
var methods = new Methods(typeBuilder, MethodName, new[] { typeof(DbModelBuilder) });
var injectionMethod = ReflectionHelper.GetMethod(injectionType, MethodName, BindingFlags.Instance | BindingFlags.Public, parameterTypes);
var il = methods.GetILGenerator(injectionType);
DeclareLocals(injectionType, il);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Call, methods.BaseMethod);
il.EmitGetInjections(injectionSetField, injectionType);
il.EmitInjectionLoop(x =>
{
x.Emit(OpCodes.Ldarg_1);
x.Emit(OpCodes.Ldarg_0);
x.Emit(OpCodes.Callvirt, injectionMethod);
ConfigureDbSets(typeBuilder, x);
});
il.Emit(OpCodes.Ret);
}
开发者ID:fjdiazt,项目名称:EntityFramework.Injection,代码行数:29,代码来源:ModelCreationBuilder.cs
示例3: DefineRaiseMethod
private MethodBuilder DefineRaiseMethod(TypeBuilder builder, FieldBuilder addPropertyChangedField)
{
var notifyPropertyChangedMethod = builder.DefineMethod("NotifyPropertyChanged", MethodAttributes.Public | MethodAttributes.Virtual, typeof(void),
new [] {typeof (string)});
var il = notifyPropertyChangedMethod.GetILGenerator();
il.DeclareLocal(typeof (bool));
il.Emit(OpCodes.Ldnull);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldfld, addPropertyChangedField);
il.Emit(OpCodes.Ceq);
il.Emit(OpCodes.Stloc_0);
il.Emit(OpCodes.Ldloc_0);
Label ifNullLabel = il.DefineLabel();
il.Emit(OpCodes.Brtrue_S, ifNullLabel);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldfld, addPropertyChangedField);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Newobj, typeof (PropertyChangedEventArgs).GetConstructors().First());
il.Emit(OpCodes.Callvirt, typeof(PropertyChangedEventHandler).GetMethod("Invoke"));
il.MarkLabel(ifNullLabel);
il.Emit(OpCodes.Ret);
return notifyPropertyChangedMethod;
}
开发者ID:fkalseth,项目名称:tinyaop,代码行数:30,代码来源:AutoNotifyPropertyChangedImplementationStrategy.cs
示例4: CreateGenerator
public override MethodGenerator CreateGenerator(
FieldMetadataFieldBuilderMap instanceFieldBuilders,
MethodMetadataFieldBuilderMap methodMetadataFieldBuilders,
FieldBuilder dispatcherField)
{
return new DuckTypeMethodGenerator(this);
}
开发者ID:bradleyjford,项目名称:inception,代码行数:7,代码来源:DuckTypeMethodMetadata.cs
示例5: PropertyEmitter
public PropertyEmitter(TypeBuilder owner, string name, Type propertyType, FieldBuilder propertyChangedField) {
this.owner = owner;
this.propertyChangedField = propertyChangedField;
fieldBuilder = owner.DefineField(String.Format("<{0}>", name), propertyType, FieldAttributes.Private);
getterBuilder = owner.DefineMethod(String.Format("get_{0}", name), MethodAttributes.Public|MethodAttributes.Virtual|MethodAttributes.HideBySig|MethodAttributes.SpecialName, propertyType, Type.EmptyTypes);
ILGenerator getterIl = getterBuilder.GetILGenerator();
getterIl.Emit(OpCodes.Ldarg_0);
getterIl.Emit(OpCodes.Ldfld, fieldBuilder);
getterIl.Emit(OpCodes.Ret);
setterBuilder = owner.DefineMethod(String.Format("set_{0}", name), MethodAttributes.Public|MethodAttributes.Virtual|MethodAttributes.HideBySig|MethodAttributes.SpecialName, typeof(void), new[] {propertyType});
ILGenerator setterIl = setterBuilder.GetILGenerator();
setterIl.Emit(OpCodes.Ldarg_0);
setterIl.Emit(OpCodes.Ldarg_1);
setterIl.Emit(OpCodes.Stfld, fieldBuilder);
if (propertyChangedField != null) {
setterIl.Emit(OpCodes.Ldarg_0);
setterIl.Emit(OpCodes.Dup);
setterIl.Emit(OpCodes.Ldfld, propertyChangedField);
setterIl.Emit(OpCodes.Ldstr, name);
setterIl.Emit(OpCodes.Call, proxyBase_NotifyPropertyChanged);
}
setterIl.Emit(OpCodes.Ret);
propertyBuilder = owner.DefineProperty(name, PropertyAttributes.None, propertyType, null);
propertyBuilder.SetGetMethod(getterBuilder);
propertyBuilder.SetSetMethod(setterBuilder);
}
开发者ID:NicoGBN,项目名称:AutoMapper,代码行数:26,代码来源:PropertyEmitter.cs
示例6: InterfaceImplementation
public InterfaceImplementation(
TypeBuilder typeBuilder,
Type @interface,
GenericParameterMapper genericParameterMapper,
FieldBuilder proxyInterceptionPipelineField,
bool explicitImplementation,
FieldBuilder targetField)
{
this.typeBuilder = typeBuilder;
[email protected] = @interface;
this.genericParameterMapper = genericParameterMapper;
this.proxyInterceptionPipelineField = proxyInterceptionPipelineField;
this.explicitImplementation = explicitImplementation;
this.targetField = targetField;
if (@interface.IsGenericType)
{
// when the @interface is generic we need to get references to its methods though it
// in this case, the targetInterface is a constructed version using the generic type parameters
// from the generated type generate type
var definition = @interface.GetGenericTypeDefinition();
var mappedParameters = definition.GetGenericArguments().Select(t => genericParameterMapper.Map(t)).ToArray();
this.targetInterface = definition.MakeGenericType(mappedParameters);
}
else
{
this.targetInterface = @interface;
}
}
开发者ID:kangkot,项目名称:unity,代码行数:29,代码来源:InterfaceImplementation.cs
示例7: GenerateProperties
private static FieldInfo[] GenerateProperties(TypeBuilder tb, IDictionary<string, Type> properties)
{
const MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig;
FieldInfo[] fields = new FieldBuilder[properties.Count];
int i = 0;
foreach (string key in properties.Keys)
{
string name = key;
Type type = properties[key];
FieldBuilder fb = tb.DefineField("_" + key, type, FieldAttributes.Public);
PropertyBuilder pb = tb.DefineProperty(key, PropertyAttributes.HasDefault, type, null);
MethodBuilder mbGet = tb.DefineMethod("get_" + name, getSetAttr, type, Type.EmptyTypes);
ILGenerator genGet = mbGet.GetILGenerator(8);
genGet.Emit(OpCodes.Ldarg_0);
genGet.Emit(OpCodes.Ldfld, fb);
genGet.Emit(OpCodes.Ret);
pb.SetGetMethod(mbGet);
MethodBuilder mbSet = tb.DefineMethod("set_" + name, getSetAttr, null, new Type[] { type });
ILGenerator genSet = mbSet.GetILGenerator(8);
genSet.Emit(OpCodes.Ldarg_0);
genSet.Emit(OpCodes.Ldarg_1);
genSet.Emit(OpCodes.Stfld, fb);
genSet.Emit(OpCodes.Ret);
pb.SetSetMethod(mbSet);
fields[i] = fb;
}
return fields;
}
开发者ID:StefH,项目名称:System.Linq.Dynamic,代码行数:33,代码来源:Fact.cs
示例8: GenerateProperties
private FieldInfo[] GenerateProperties(TypeBuilder tb, DynamicProperty[] properties)
{
FieldInfo[] array = new FieldBuilder[properties.Length];
for (int i = 0; i < properties.Length; i++)
{
DynamicProperty dynamicProperty = properties[i];
FieldBuilder fieldBuilder = tb.DefineField("_" + dynamicProperty.Name, dynamicProperty.Type, FieldAttributes.Private);
PropertyBuilder propertyBuilder = tb.DefineProperty(dynamicProperty.Name, PropertyAttributes.HasDefault, dynamicProperty.Type, null);
MethodBuilder methodBuilder = tb.DefineMethod("get_" + dynamicProperty.Name, MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.HideBySig | MethodAttributes.SpecialName, dynamicProperty.Type, Type.EmptyTypes);
ILGenerator iLGenerator = methodBuilder.GetILGenerator();
iLGenerator.Emit(OpCodes.Ldarg_0);
iLGenerator.Emit(OpCodes.Ldfld, fieldBuilder);
iLGenerator.Emit(OpCodes.Ret);
MethodBuilder methodBuilder2 = tb.DefineMethod("set_" + dynamicProperty.Name, MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.HideBySig | MethodAttributes.SpecialName, null, new Type[]
{
dynamicProperty.Type
});
ILGenerator iLGenerator2 = methodBuilder2.GetILGenerator();
iLGenerator2.Emit(OpCodes.Ldarg_0);
iLGenerator2.Emit(OpCodes.Ldarg_1);
iLGenerator2.Emit(OpCodes.Stfld, fieldBuilder);
iLGenerator2.Emit(OpCodes.Ret);
propertyBuilder.SetGetMethod(methodBuilder);
propertyBuilder.SetSetMethod(methodBuilder2);
array[i] = fieldBuilder;
}
return array;
}
开发者ID:charreal,项目名称:Jq.Grid,代码行数:28,代码来源:ClassFactory.cs
示例9: InterfaceImplementation
public InterfaceImplementation(
TypeBuilder typeBuilder,
Type @interface,
FieldBuilder proxyInterceptionPipelineField,
bool explicitImplementation)
: this(typeBuilder, @interface, proxyInterceptionPipelineField, explicitImplementation, null)
{ }
开发者ID:shhyder,项目名称:MapApplication,代码行数:7,代码来源:InterfaceImplementation.cs
示例10: TargetedInvocationMethodGenerator
public TargetedInvocationMethodGenerator(
TargetedMethodMetadata methodMetadata,
FieldBuilder targetField)
{
_methodMetadata = methodMetadata;
_targetField = targetField;
}
开发者ID:bradleyjford,项目名称:inception,代码行数:7,代码来源:TargetedInvocationMethodGenerator.cs
示例11: BuildConstructor
private static void BuildConstructor(TypeBuilder proxyBuilder, Type proxyType,
FieldBuilder wrappedType, FieldBuilder invokeHandlers, TypeDebugging debug)
{
var arguments = new Type[] { proxyType, typeof(IInvocationHandler[]) };
var constructor = proxyBuilder.DefineConstructor(
MethodAttributes.Public | MethodAttributes.SpecialName |
MethodAttributes.RTSpecialName | MethodAttributes.HideBySig,
CallingConventions.Standard, arguments);
using (var generator = debug.GetMethodDebugging(constructor))
{
// Call the base constructor.
generator.Emit(OpCodes.Ldarg_0);
var objectCtor = proxyType.GetConstructor(Type.EmptyTypes);
generator.Emit(OpCodes.Call, objectCtor);
// Store the target object.
generator.Emit(OpCodes.Ldarg_0);
generator.Emit(OpCodes.Ldarg_1);
generator.Emit(OpCodes.Stfld, wrappedType);
// Store the handlers.
generator.Emit(OpCodes.Ldarg_0);
generator.Emit(OpCodes.Ldarg_2);
generator.Emit(OpCodes.Stfld, invokeHandlers);
generator.Emit(OpCodes.Ret);
}
}
开发者ID:JasonBock,项目名称:DynamicProxies,代码行数:26,代码来源:ProxyConstructorBuilder.cs
示例12: AbstractProxyBuilder
public AbstractProxyBuilder(ModuleBuilder moduleBuilder, string className, Type interfaceType, Type innerType)
{
Verify.ArgumentNotNull(moduleBuilder, "moduleBuilder");
Verify.ArgumentNotNull(className, "className");
Verify.ArgumentNotNull(interfaceType, "interfaceType");
Verify.ArgumentNotNull(innerType, "innerType");
if (!interfaceType.IsInterface) {
throw new ArgumentException("must be an interface type", "interfaceType");
}
_errorMessages = new List<string>();
_moduleBuilder = moduleBuilder;
_className = className;
_interfaceType = interfaceType;
_innerType = innerType;
_typeBuilder = _moduleBuilder.DefineType(
_className,
TypeAttributes.Public |
TypeAttributes.Class |
TypeAttributes.AutoClass |
TypeAttributes.AnsiClass |
TypeAttributes.BeforeFieldInit |
TypeAttributes.AutoLayout,
typeof(object),
new Type[] {_interfaceType});
_innerFieldBuilder = _typeBuilder.DefineField("inner", _innerType, FieldAttributes.Private);
}
开发者ID:matthewc-mps-aust,项目名称:quokka,代码行数:30,代码来源:AbstractProxyBuilder.cs
示例13: Build
public void Build(TypeBuilder typeBuilder, FieldBuilder injectionSetField, Type injectionType)
{
var parameterTypes = new[] { typeof(string) };
var methods = new Methods(typeBuilder, _methodName, parameterTypes);
var injectionMethod = injectionType.GetMethod(_methodName, new[] { typeof(BaseType), typeof(string) });
var il = methods.GetILGenerator(injectionType);
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Call, methods.BaseMethod);
il.EmitGetInjections(injectionSetField, injectionType);
il.EmitInjectionLoop(x =>
{
x.Emit(OpCodes.Ldarg_0);
x.Emit(OpCodes.Ldarg_1);
x.Emit(OpCodes.Callvirt, injectionMethod);
});
il.Emit(OpCodes.Ret);
}
开发者ID:OlegAxenow,项目名称:Method.Injection,代码行数:26,代码来源:DoWorkMethodBuilder.cs
示例14: EmitInitField
private static void EmitInitField(ILGenerator il, FieldBuilder fb, Type type)
{
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldtoken, type);
il.Emit(OpCodes.Call, typeof(Type).GetMethod("GetTypeFromHandle"));
il.Emit(OpCodes.Stfld, fb);
}
开发者ID:ExM,项目名称:OncRpc,代码行数:7,代码来源:ReadBuilder.EmitDynReadMapper.cs
示例15: SwitchCase
public SwitchCase(TypeContainer elemType, string elemName, object[] discriminatorValues,
FieldBuilder elemField) {
m_elemType = elemType;
m_elemName = elemName;
m_elemField = elemField;
m_discriminatorValues = discriminatorValues;
}
开发者ID:JnS-Software-LLC,项目名称:iiop-net,代码行数:7,代码来源:UnionGenerationHelper.cs
示例16: Build
public void Build(TypeBuilder typeBuilder, FieldBuilder injectionSetField, Type injectionType)
{
var parameterTypes = new[] { typeof(DbEntityEntry), typeof(IDictionary<object, object>) };
var returnType = typeof(DbEntityValidationResult);
var methods = new Methods(typeBuilder, MethodName, parameterTypes, returnType);
var injectionMethod = injectionType.GetMethod("On" + MethodName, new[] { returnType, parameterTypes[0], parameterTypes[1] });
var il = methods.GetILGenerator(injectionType);
// declare result variable
il.DeclareLocal(typeof(DbEntityValidationResult));
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Ldarg_2);
il.Emit(OpCodes.Call, methods.BaseMethod);
il.Emit(OpCodes.Stloc_3);
il.EmitGetInjections(injectionSetField, injectionType);
il.EmitInjectionLoop(x =>
{
x.Emit(OpCodes.Ldloc_3);
x.Emit(OpCodes.Ldarg_1);
x.Emit(OpCodes.Ldarg_2);
x.Emit(OpCodes.Callvirt, injectionMethod);
});
il.Emit(OpCodes.Ldloc_3);
il.Emit(OpCodes.Ret);
}
开发者ID:fjdiazt,项目名称:EntityFramework.Injection,代码行数:35,代码来源:EntityValidationBuilder.cs
示例17: MethodOverride
internal MethodOverride(
TypeBuilder typeBuilder,
FieldBuilder proxyInterceptionPipelineField,
MethodInfo methodToOverride,
Type targetType,
GenericParameterMapper targetTypeParameterMapper,
int overrideCount)
{
this.typeBuilder = typeBuilder;
this.proxyInterceptionPipelineField = proxyInterceptionPipelineField;
this.methodToOverride = methodToOverride;
this.methodParameters = methodToOverride.GetParameters();
this.targetType = targetType;
// if the method is inherited and the declaring type is generic, we need to map
// the parameters of the original declaration to the actual intercepted type type
// E.g. consider given class Type1<T> with virtual method "T Method<U>()", the mappings in
// different scenarios would look like:
// Type2<S> : Type2<S> => S Method<U>()
// Type2<S> : Type2<IEnumerable<S>> => IEnumerable<S> Method<U>()
// Type2 : Type1<IEnumerable<string>> => IEnumerable<string> Method<U>()
var declaringType = methodToOverride.DeclaringType;
this.targetTypeParameterMapper =
declaringType.IsGenericType && declaringType != methodToOverride.ReflectedType
? new GenericParameterMapper(declaringType, targetTypeParameterMapper)
: targetTypeParameterMapper;
this.overrideCount = overrideCount;
}
开发者ID:calebnelton,项目名称:unity,代码行数:28,代码来源:MethodOverride.cs
示例18: GenerateProperties
private FieldInfo[] GenerateProperties( TypeBuilder tb , DynamicProperty[] properties ) {
FieldInfo[] fields = new FieldBuilder[properties.Length];
for ( int i = 0 ; i < properties.Length ; i++ ) {
DynamicProperty dp = properties[i];
FieldBuilder fb = tb.DefineField( "_" + dp.Name , dp.Type , FieldAttributes.Private );
PropertyBuilder pb = tb.DefineProperty( dp.Name , PropertyAttributes.HasDefault , dp.Type , null );
MethodBuilder mbGet = tb.DefineMethod( "get_" + dp.Name ,
MethodAttributes.Public | MethodAttributes.SpecialName |
MethodAttributes.HideBySig ,
dp.Type , Type.EmptyTypes );
ILGenerator genGet = mbGet.GetILGenerator();
genGet.Emit( OpCodes.Ldarg_0 );
genGet.Emit( OpCodes.Ldfld , fb );
genGet.Emit( OpCodes.Ret );
MethodBuilder mbSet = tb.DefineMethod( "set_" + dp.Name ,
MethodAttributes.Public | MethodAttributes.SpecialName |
MethodAttributes.HideBySig ,
null , new[] { dp.Type } );
ILGenerator genSet = mbSet.GetILGenerator();
genSet.Emit( OpCodes.Ldarg_0 );
genSet.Emit( OpCodes.Ldarg_1 );
genSet.Emit( OpCodes.Stfld , fb );
genSet.Emit( OpCodes.Ret );
pb.SetGetMethod( mbGet );
pb.SetSetMethod( mbSet );
fields[i] = fb;
}
return fields;
}
开发者ID:kisflying,项目名称:kion,代码行数:29,代码来源:ClassFactory.cs
示例19: EmitGetInjections
/// <summary>
/// First local variable should be injectionType.MakeArrayType() type.
/// </summary>
/// <remarks> Parameters not checked.</remarks>
public static void EmitGetInjections(this ILGenerator il, FieldBuilder injectionSetField, Type injectionType)
{
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldfld, injectionSetField);
il.Emit(OpCodes.Callvirt, typeof(InjectionSet).GetMethod(GetInjectionsName, EmptyParameters).MakeGenericMethod(new[] { injectionType }));
il.Emit(OpCodes.Stloc_0);
}
开发者ID:OlegAxenow,项目名称:Method.Injection,代码行数:12,代码来源:EmitHelper.cs
示例20: Build
internal static void Build(TypeBuilder proxyBuilder, Type proxyType,
FieldBuilder wrappedObject, FieldBuilder invokeHandlers, TypeDebugging debug)
{
ProxyConstructorBuilder.BuildParameterlessConstructor(
proxyBuilder, proxyType, debug);
ProxyConstructorBuilder.BuildConstructor(
proxyBuilder, proxyType, wrappedObject, invokeHandlers, debug);
}
开发者ID:JasonBock,项目名称:DynamicProxies,代码行数:8,代码来源:ProxyConstructorBuilder.cs
注:本文中的System.Reflection.Emit.FieldBuilder类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论