internal CILFieldImpl( CILReflectionContextImpl ctx, Int32 anID, CILType declaringType, String name, CILTypeBase fieldType, FieldAttributes attrs ) : this( ctx, anID, new LazyWithLock <ListProxy <CILCustomAttribute> >(() => ctx.CollectionsFactory.NewListProxy <CILCustomAttribute>()), new SettableValueForEnums <FieldAttributes>(attrs), new SettableValueForClasses <String>(name), () => declaringType, () => fieldType, new SettableLazy <Object>(() => null), new SettableValueForClasses <Byte[]>(null), new LazyWithLock <ListProxy <CILCustomModifier> >(() => ctx.CollectionsFactory.NewListProxy <CILCustomModifier>()), new SettableLazy <Int32>(() => NO_OFFSET), new SettableLazy <MarshalingInfo>(() => null), true ) { }
internal ModuleWriter(CILModule module) { ArgumentValidator.ValidateNotNull("Module", module); this._context = (CILReflectionContextImpl)module.ReflectionContext; this._module = module; }
internal protected CommonFunctionality(CILReflectionContextImpl aContext, Int32 anID) { ArgumentValidator.ValidateNotNull("Context", aContext); this.context = aContext; this.id = anID; }
internal CILPropertyImpl( CILReflectionContextImpl ctx, Int32 anID, LazyWithLock <ListProxy <CILCustomAttribute> > cAttrDataFunc, SettableValueForClasses <String> aName, SettableValueForEnums <PropertyAttributes> aPropertyAttributes, Func <CILMethod> setMethodFunc, Func <CILMethod> getMethodFunc, Func <CILType> declaringTypeFunc, SettableLazy <Object> aConstValue, LazyWithLock <ListProxy <CILCustomModifier> > customMods, Boolean resettablesAreSettable = false ) : base(ctx, CILElementKind.Property, anID, cAttrDataFunc) { InitFields( ref this.name, ref this.propertyAttributes, ref this.setMethod, ref this.getMethod, ref this.declaringType, ref this.constValue, ref this.customModifiers, aName, aPropertyAttributes, setMethodFunc, getMethodFunc, declaringTypeFunc, aConstValue, customMods, resettablesAreSettable ); }
internal CILParameterImpl( CILReflectionContextImpl ctx, Int32 anID, System.Reflection.ParameterInfo parameter ) : base(ctx, anID, CILElementKind.Parameter, () => new CustomAttributeDataEventArgs(ctx, parameter)) { var member = parameter.Member; var isCtor = member is System.Reflection.ConstructorInfo; InitFields( ref this.paramAttributes, ref this.position, ref this.name, ref this.method, ref this.parameterType, ref this.defaultValue, ref this.customModifiers, ref this.marshalInfo, new SettableValueForEnums <ParameterAttributes>((ParameterAttributes)parameter.Attributes), parameter.Position, new SettableValueForClasses <String>(parameter.Name), () => isCtor ? (CILMethodBase)ctx.Cache.GetOrAdd((System.Reflection.ConstructorInfo)member) : ctx.Cache.GetOrAdd((System.Reflection.MethodInfo)member), () => ctx.Cache.GetOrAdd(parameter.ParameterType), new SettableLazy <Object>(() => ctx.LaunchConstantValueLoadEvent(new ConstantValueLoadArgs(parameter))), ctx.LaunchEventAndCreateCustomModifiers(new CustomModifierEventLoadArgs(parameter)), new SettableLazy <MarshalingInfo>(() => MarshalingInfo.FromAttribute(parameter.GetCustomAttributes(true).OfType <System.Runtime.InteropServices.MarshalAsAttribute>().FirstOrDefault(), ctx)), true ); }
internal CILModuleImpl(CILReflectionContextImpl ctx, Int32 anID, System.Reflection.Module mod) : base(ctx, anID, CILElementKind.Module, () => new CustomAttributeDataEventArgs(ctx, mod)) { ArgumentValidator.ValidateNotNull("Module", mod); var mName = mod.Name; //var match = EXTENSION_REGEX.Match( mName ); InitFields( ref this.name, ref this.assembly, ref this.types, ref this.moduleInitializer, ref this.associatedMSCorLib, ref this.typeNameCache, ref this.manifestResources, mod.Name, // match.Success ? mName.Substring( 0, match.Index ) : mName, () => ctx.Cache.GetOrAdd(mod.Assembly), () => ctx.CollectionsFactory.NewListProxy <CILType>( ctx.LaunchModuleTypesLoadEvent(new ModuleTypesEventArgs(mod)) .Select(type => (CILType)ctx.Cache.GetOrAdd(type)) .ToList() ), this.BuildModuleInitializerType, this.LoadNativeMSCorLibModule, null, this ); }
internal CILConstructorImpl( CILReflectionContextImpl ctx, Int32 anID, System.Reflection.ConstructorInfo ctor ) : base(ctx, anID, ctor) { }
private static Tuple <Boolean, CILTypeBase>[] GetLocalsFromArgs(CILReflectionContextImpl ctx, MethodBodyLoadArgs args) { var result = new Tuple <Boolean, CILTypeBase> [args.Locals.Count]; for (var i = 0; i < result.Length; ++i) { result[i] = Tuple.Create(args.Locals[i].Item1, args.Locals[i].Item2.NewWrapper(ctx)); } return(result); }
internal CILFieldImpl( CILReflectionContextImpl ctx, Int32 anID, System.Reflection.FieldInfo field ) : base(ctx, anID, CILElementKind.Field, () => new CustomAttributeDataEventArgs(ctx, field)) { ArgumentValidator.ValidateNotNull("Field", field); if (field.DeclaringType #if WINDOWS_PHONE_APP .GetTypeInfo() #endif .IsGenericType&& !field.DeclaringType #if WINDOWS_PHONE_APP .GetTypeInfo() #endif .IsGenericTypeDefinition) { throw new ArgumentException("This constructor may be used only on fields declared in genericless types or generic type definitions."); } Byte[] rvaValue = null; if (((FieldAttributes)field.Attributes).HasRVA()) { rvaValue = BitUtils.ObjectToByteArray(field.GetValue(null)); } InitFields( ref this.fieldAttributes, ref this.name, ref this.declaringType, ref this.fieldType, ref this.constValue, ref this.initialValue, ref this.customModifiers, ref this.fieldOffset, ref this.marshalInfo, new SettableValueForEnums <FieldAttributes>((FieldAttributes)field.Attributes), new SettableValueForClasses <String>(field.Name), () => (CILType)ctx.Cache.GetOrAdd(field.DeclaringType), () => ctx.Cache.GetOrAdd(field.FieldType), new SettableLazy <Object>(() => ctx.LaunchConstantValueLoadEvent(new ConstantValueLoadArgs(field))), new SettableValueForClasses <Byte[]>(rvaValue), ctx.LaunchEventAndCreateCustomModifiers(new CustomModifierEventLoadArgs(field)), new SettableLazy <Int32>(() => { var offset = field.GetCustomAttributes(true).OfType <System.Runtime.InteropServices.FieldOffsetAttribute>().FirstOrDefault(); return(offset == null ? -1 : offset.Value); }), new SettableLazy <MarshalingInfo>(() => MarshalingInfo.FromAttribute(field.GetCustomAttributes(true).OfType <System.Runtime.InteropServices.MarshalAsAttribute>().FirstOrDefault(), ctx)), true ); }
internal CILMethodImpl( CILReflectionContextImpl ctx, Int32 anID, System.Reflection.MethodInfo method ) : base(ctx, anID, method) { var nGDef = method.IsGenericMethodDefinition ? method : null; var dllImportAttr = method.GetCustomAttributes(typeof(System.Runtime.InteropServices.DllImportAttribute), true).FirstOrDefault() as System.Runtime.InteropServices.DllImportAttribute; InitFields( ref this.name, ref this.returnParameter, ref this.gArgs, ref this.gArgsLock, ref this.gDef, ref this.overriddenMethods, ref this.overriddenMethodsLock, ref this.pInvokeAttributes, ref this.pInvokeName, ref this.pInvokeModule, new SettableValueForClasses <String>(method.Name), () => ctx.Cache.GetOrAdd(method.ReturnParameter), () => ctx.CollectionsFactory.NewListProxy <CILTypeBase>(method.GetGenericArguments().Select(gArg => ctx.Cache.GetOrAdd(gArg)).ToList()), () => ctx.Cache.GetOrAdd(nGDef), () => { var result = this.context.CollectionsFactory.NewListProxy <CILMethod>(); if (!method.DeclaringType #if WINDOWS_PHONE_APP .GetTypeInfo() #endif .IsInterface&& !method.IsPublic) { var args = new ExplicitMethodImplementationLoadArgs(method.DeclaringType); ctx.LaunchInterfaceMappingLoadEvent(args); System.Reflection.MethodInfo[] resultNMethods; if (args.ExplicitlyImplementedMethods.TryGetValue(method, out resultNMethods)) { result.AddRange(resultNMethods.Select(nMethod => ctx.Cache.GetOrAdd(nMethod))); } } return(result); }, new SettableValueForEnums <PInvokeAttributes>(dllImportAttr == null ? (PInvokeAttributes)0 : dllImportAttr.GetCorrespondingPInvokeAttributes()), new SettableValueForClasses <String>(dllImportAttr == null ? null : dllImportAttr.EntryPoint), new SettableValueForClasses <String>(dllImportAttr == null ? null : dllImportAttr.Value), true ); }
internal MethodILImpl(CILModule module) { ArgumentValidator.ValidateNotNull("Module", module); this._module = module; this.context = (CILReflectionContextImpl)module.ReflectionContext; this._opCodes = new List <OpCodeInfo>(); this._labelOffsets = new List <Int32>(); this._allExceptionBlocks = new List <ExceptionBlockInfo>(); this._currentExceptionBlocks = new Stack <ExceptionBlockInfo>(); this._locals = new List <LocalBuilder>(); this._branchTargetsCount = 0; this._initLocals = true; // Maybe set to false by default? }
internal CILCustomAttributeContainerImpl( CILReflectionContextImpl ctx, CILElementKind kind, Int32 anID, LazyWithLock <ListProxy <CILCustomAttribute> > cAttrDataFunc ) : base(ctx, anID) { InitFields( ref this.cilKind, ref this.attributes, kind, cAttrDataFunc ); }
internal CILConstructorImpl( CILReflectionContextImpl ctx, Int32 anID, LazyWithLock <ListProxy <CILCustomAttribute> > cAttrDataFunc, SettableValueForEnums <CallingConventions> aCallingConvention, SettableValueForEnums <MethodAttributes> aMethodAttributes, Func <CILType> declaringTypeFunc, Func <ListProxy <CILParameter> > parametersFunc, Func <MethodIL> methodIL, SettableLazy <MethodImplAttributes> aMethodImplementationAttributes, Lazy <DictionaryWithRoles <SecurityAction, ListProxy <SecurityInformation>, ListProxyQuery <SecurityInformation>, ListQuery <SecurityInformation> > > aSecurityInfo, Boolean resettablesAreSettable ) : base(ctx, anID, true, cAttrDataFunc, aCallingConvention, aMethodAttributes, declaringTypeFunc, parametersFunc, methodIL, aMethodImplementationAttributes, aSecurityInfo, resettablesAreSettable) { }
internal CILEventImpl(CILReflectionContextImpl ctx, Int32 anID, CILType declaringType, String aName, EventAttributes anEventAttributes, CILTypeBase anEventType) : this( ctx, anID, new LazyWithLock <ListProxy <CILCustomAttribute> >(() => ctx.CollectionsFactory.NewListProxy <CILCustomAttribute>()), new SettableValueForClasses <String>(aName), new SettableValueForEnums <EventAttributes>(anEventAttributes), () => anEventType, () => null, () => null, () => null, () => ctx.CollectionsFactory.NewListProxy <CILMethod>(), () => declaringType, true) { }
internal CILPropertyImpl(CILReflectionContextImpl ctx, Int32 anID, CILType declaringType, String aName, PropertyAttributes aPropertyAttributes) : this( ctx, anID, new LazyWithLock <ListProxy <CILCustomAttribute> >(() => ctx.CollectionsFactory.NewListProxy <CILCustomAttribute>()), new SettableValueForClasses <String>(aName), new SettableValueForEnums <PropertyAttributes>(aPropertyAttributes), () => null, () => null, () => declaringType, new SettableLazy <Object>(() => null), new LazyWithLock <ListProxy <CILCustomModifier> >(() => ctx.CollectionsFactory.NewListProxy <CILCustomModifier>()), true ) { }
internal CILAssemblyImpl( CILReflectionContextImpl ctx, Int32 anID, System.Reflection.Assembly ass ) : base(ctx, anID, CILElementKind.Assembly, () => new CustomAttributeDataEventArgs(ctx, ass)) { ArgumentValidator.ValidateNotNull("Assembly", ass); InitFields( ref this.name, ref this.modules, ref this.forwardedTypes, ref this.mainModule, () => { var result = CILAssemblyName.Parse(ass.FullName); var args = new AssemblyNameEventArgs(ass); ctx.LaunchAssemblyNameLoadEvent(args); var info = args.AssemblyNameInfo; if (info != null) { result.HashAlgorithm = info.Item1; result.Flags = info.Item2; if (info.Item3 != null) { result.PublicKey = info.Item3; if (result.PublicKey.IsNullOrEmpty()) { // .NET for some reason returns PublicKey-flag set, even with no public key... result.Flags = result.Flags & ~(AssemblyFlags.PublicKey); } } } return(result); }, () => ctx.CollectionsFactory.NewListProxy <CILModule>(ass .GetModules() .Select(module => ctx.Cache.GetOrAdd(module)) .ToList()), () => { // TODO seems that getting type forward info is not really possible via C# managed reflection API? throw new NotImplementedException(); }, () => ctx.Cache.GetOrAdd(ass.ManifestModule) ); }
internal CILParameterImpl(CILReflectionContextImpl ctx, Int32 anID, CILMethodBase ownerMethod, Int32 position, String name, ParameterAttributes attrs, CILTypeBase paramType) : this( ctx, anID, new LazyWithLock <ListProxy <CILCustomAttribute> >(() => ctx.CollectionsFactory.NewListProxy <CILCustomAttribute>()), new SettableValueForEnums <ParameterAttributes>(attrs), position, new SettableValueForClasses <String>(name), () => ownerMethod, () => paramType, new SettableLazy <Object>(() => null), new LazyWithLock <ListProxy <CILCustomModifier> >(() => ctx.CollectionsFactory.NewListProxy <CILCustomModifier>()), new SettableLazy <MarshalingInfo>(() => null), true ) { }
internal CILAssemblyImpl( CILReflectionContextImpl ctx, Int32 anID ) : base(ctx, CILElementKind.Assembly, anID, new LazyWithLock <ListProxy <CILCustomAttribute> >(() => ctx.CollectionsFactory.NewListProxy <CILCustomAttribute>())) { InitFields( ref this.name, ref this.modules, ref this.forwardedTypes, ref this.mainModule, () => new CILAssemblyName(), () => ctx.CollectionsFactory.NewListProxy <CILModule>(), () => ctx.CollectionsFactory.NewDictionaryProxy <Tuple <String, String>, TypeForwardingInfo>(), () => null ); }
internal CILMethodImpl( CILReflectionContextImpl ctx, Int32 anID, LazyWithLock <ListProxy <CILCustomAttribute> > cAttrDataFunc, SettableValueForEnums <CallingConventions> aCallingConvention, SettableValueForEnums <MethodAttributes> aMethodAttributes, Func <CILType> declaringTypeFunc, Func <ListProxy <CILParameter> > parametersFunc, Func <MethodIL> methodIL, SettableLazy <MethodImplAttributes> aMethodImplementationAttributes, Lazy <DictionaryWithRoles <SecurityAction, ListProxy <SecurityInformation>, ListProxyQuery <SecurityInformation>, ListQuery <SecurityInformation> > > aSecurityInformation, SettableValueForClasses <String> aName, Func <CILParameter> returnParameterFunc, Func <ListProxy <CILTypeBase> > gArgsFunc, Func <CILMethod> gDefFunc, Func <ListProxy <CILMethod> > overriddenMethodFunc, SettableValueForEnums <PInvokeAttributes> aPInvokeAttributes, SettableValueForClasses <String> aPInvokeName, SettableValueForClasses <String> aPInvokeModuleName, Boolean resettablesAreSettable ) : base(ctx, anID, false, cAttrDataFunc, aCallingConvention, aMethodAttributes, declaringTypeFunc, parametersFunc, methodIL, aMethodImplementationAttributes, aSecurityInformation, resettablesAreSettable) { InitFields( ref this.name, ref this.returnParameter, ref this.gArgs, ref this.gArgsLock, ref this.gDef, ref this.overriddenMethods, ref this.overriddenMethodsLock, ref this.pInvokeAttributes, ref this.pInvokeName, ref this.pInvokeModule, aName, returnParameterFunc, gArgsFunc, gDefFunc, overriddenMethodFunc, aPInvokeAttributes, aPInvokeName, aPInvokeModuleName, resettablesAreSettable ); }
internal MethodILWriter(CILReflectionContextImpl ctx, MetaDataWriter md, CILMethodBase method, EmittingAssemblyMapper mapper) { var methodIL = (MethodILImpl)method.MethodIL; this._method = method; this._methodIL = methodIL; this._metaData = md; this._assemblyMapper = mapper; this._ilCode = new Byte[methodIL._opCodes.Sum(info => info.MaxSize)]; this._ilCodeCount = 0; this._methodILOffset = 0; this._opCodeInfoOffsets = new Int32[methodIL._opCodes.Count]; this._labelInfos = new LabelEmittingInfo[methodIL._branchTargetsCount]; this._labelInfoIndex = 0; this._stackSizes = new Dictionary <Int32, Int32>(); this._currentStack = 0; this._maxStack = 0; }
internal CILMethodImpl( CILReflectionContextImpl ctx, Int32 anID, LazyWithLock <ListProxy <CILCustomAttribute> > cAttrDataFunc, SettableValueForEnums <CallingConventions> aCallingConvention, SettableValueForEnums <MethodAttributes> aMethodAttributes, Func <CILType> declaringTypeFunc, Func <ListProxy <CILParameter> > parametersFunc, SettableLazy <MethodImplAttributes> aMethodImplementationAttributes, Lazy <DictionaryWithRoles <SecurityAction, ListProxy <SecurityInformation>, ListProxyQuery <SecurityInformation>, ListQuery <SecurityInformation> > > aSecurityInformation, SettableValueForClasses <String> aName, Func <CILParameter> returnParameterFunc, Func <ListProxy <CILTypeBase> > gArgsFunc, Func <CILMethod> gDefFunc, Boolean resettablesAreSettable = false ) : this(ctx, anID, cAttrDataFunc, aCallingConvention, aMethodAttributes, declaringTypeFunc, parametersFunc, null, aMethodImplementationAttributes, aSecurityInformation, aName, returnParameterFunc, gArgsFunc, gDefFunc, null, null, null, null, resettablesAreSettable) { }
internal CILModuleImpl(CILReflectionContextImpl ctx, Int32 anID, LazyWithLock <ListProxy <CILCustomAttribute> > cAttrs, Func <CILAssembly> ass, String name, Func <CILType> moduleInitializerFunc, Func <ListProxy <CILType> > definedTypes, Func <CILModule> associatedMSCorLibFunc, IDictionary <String, ManifestResource> mResources) : base(ctx, CILElementKind.Module, anID, cAttrs) { InitFields( ref this.name, ref this.assembly, ref this.types, ref this.moduleInitializer, ref this.associatedMSCorLib, ref this.typeNameCache, ref this.manifestResources, name, ass, definedTypes, moduleInitializerFunc, associatedMSCorLibFunc, mResources, this ); }
internal CILModuleImpl(CILReflectionContextImpl ctx, Int32 anID, CILAssembly ass, String name) : base(ctx, CILElementKind.Module, anID, new LazyWithLock <ListProxy <CILCustomAttribute> >(() => ctx.CollectionsFactory.NewListProxy <CILCustomAttribute>())) { InitFields( ref this.name, ref this.assembly, ref this.types, ref this.moduleInitializer, ref this.associatedMSCorLib, ref this.typeNameCache, ref this.manifestResources, name, () => ass, () => ctx.CollectionsFactory.NewListProxy <CILType>(), this.BuildModuleInitializerType, this.LoadNativeMSCorLibModule, null, this ); }
internal CILConstructorImpl( CILReflectionContextImpl ctx, Int32 anID, CILType declaringType, MethodAttributes attrs ) : this( ctx, anID, new LazyWithLock <ListProxy <CILCustomAttribute> >(() => ctx.CollectionsFactory.NewListProxy <CILCustomAttribute>()), new SettableValueForEnums <CallingConventions>(CallingConventions.Standard), new SettableValueForEnums <MethodAttributes>(attrs | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName), () => declaringType, () => ctx.CollectionsFactory.NewListProxy <CILParameter>(), () => new MethodILImpl(declaringType.Module), new SettableLazy <MethodImplAttributes>(() => MethodImplAttributes.IL), null, true ) { }
internal CILEventImpl( CILReflectionContextImpl ctx, Int32 anID, System.Reflection.EventInfo evt) : base(ctx, anID, CILElementKind.Event, () => new CustomAttributeDataEventArgs(ctx, evt)) { ArgumentValidator.ValidateNotNull("Event", evt); if (evt.DeclaringType #if WINDOWS_PHONE_APP .GetTypeInfo() #endif .IsGenericType&& !evt.DeclaringType #if WINDOWS_PHONE_APP .GetTypeInfo() #endif .IsGenericTypeDefinition) { throw new ArgumentException("This constructor may be used only on events declared in genericless types or generic type definitions."); } InitFields( ref this.name, ref this.eventAttributes, ref this.eventType, ref this.addMethod, ref this.removeMethod, ref this.raiseMethod, ref this.otherMethods, ref this.declaringType, new SettableValueForClasses <String>(evt.Name), new SettableValueForEnums <EventAttributes>((EventAttributes)evt.Attributes), () => ctx.Cache.GetOrAdd(evt.EventHandlerType), () => ctx.Cache.GetOrAdd(evt.GetAddMethod(true)), () => ctx.Cache.GetOrAdd(evt.GetRemoveMethod(true)), () => ctx.Cache.GetOrAdd(evt.GetRaiseMethod(true)), () => ctx.CollectionsFactory.NewListProxy <CILMethod>(ctx.LaunchEventOtherMethodsLoadEvent(new EventOtherMethodsEventArgs(evt)).Select(method => ctx.Cache.GetOrAdd(method)).ToList()), () => (CILType)ctx.Cache.GetOrAdd(evt.DeclaringType), true ); }
internal CILAssemblyImpl( CILReflectionContextImpl ctx, Int32 anID, LazyWithLock <ListProxy <CILCustomAttribute> > cAttrs, Func <CILAssemblyName> nameFunc, Func <ListProxy <CILModule> > modulesFunc, Func <DictionaryProxy <Tuple <String, String>, TypeForwardingInfo> > forwardedTypesFunc, Func <CILModule> mainModuleFunc ) : base(ctx, CILElementKind.Assembly, anID, cAttrs) { InitFields( ref this.name, ref this.modules, ref this.forwardedTypes, ref this.mainModule, nameFunc, modulesFunc, forwardedTypesFunc, mainModuleFunc ); }
internal CILPropertyImpl( CILReflectionContextImpl ctx, Int32 anID, System.Reflection.PropertyInfo pInfo) : base(ctx, anID, CILElementKind.Property, () => new CustomAttributeDataEventArgs(ctx, pInfo)) { ArgumentValidator.ValidateNotNull("Property", pInfo); if (pInfo.DeclaringType #if WINDOWS_PHONE_APP .GetTypeInfo() #endif .IsGenericType&& !pInfo.DeclaringType #if WINDOWS_PHONE_APP .GetTypeInfo() #endif .IsGenericTypeDefinition) { throw new ArgumentException("This constructor may be used only on properties declared in genericless types or generic type definitions."); } InitFields( ref this.name, ref this.propertyAttributes, ref this.setMethod, ref this.getMethod, ref this.declaringType, ref this.constValue, ref this.customModifiers, new SettableValueForClasses <String>(pInfo.Name), new SettableValueForEnums <PropertyAttributes>((PropertyAttributes)pInfo.Attributes), () => ctx.Cache.GetOrAdd(pInfo.GetSetMethod(true)), () => ctx.Cache.GetOrAdd(pInfo.GetGetMethod(true)), () => (CILType)ctx.Cache.GetOrAdd(pInfo.DeclaringType), new SettableLazy <Object>(() => ctx.LaunchConstantValueLoadEvent(new ConstantValueLoadArgs(pInfo))), ctx.LaunchEventAndCreateCustomModifiers(new CustomModifierEventLoadArgs(pInfo)), true ); }
private static Func <Int32, ILResolveKind, Object> TokenResolverFromArgs(CILReflectionContextImpl ctx, MethodBodyLoadArgs args) { var module = new Lazy <System.Reflection.Module>(() => ctx.LaunchTypeModuleLoadEvent(new TypeModuleEventArgs(args.Method.DeclaringType)), System.Threading.LazyThreadSafetyMode.ExecutionAndPublication); var dType = args.Method.DeclaringType; var gArgs = dType #if WINDOWS_PHONE_APP .GetTypeInfo() #endif .IsGenericType ? dType.GetGenericTypeDefinition().GetGenericArguments() : null; var mgArgs = args.Method is System.Reflection.MethodInfo && args.Method.GetGenericArguments().Any() ? ((System.Reflection.MethodInfo)args.Method).GetGenericMethodDefinition().GetGenericArguments() : null; return((token, rKind) => { var tArgs = new TokenResolveArgs(module.Value, token, rKind == ILResolveKind.String ? TokenResolveArgs.ResolveKinds.String : (rKind == ILResolveKind.Signature ? TokenResolveArgs.ResolveKinds.Signature : TokenResolveArgs.ResolveKinds.Member), gArgs, mgArgs); ctx.LaunchTokenResolveEvent(tArgs); switch (rKind) { case ILResolveKind.String: return tArgs.ResolvedString; case ILResolveKind.Signature: // TODO basically same thing as in ModuleReadingContext, except use this method to resolve tokens. // Maybe could make static methods to ModuleReadingContext (ReadFieldSignature, ReadMethodSignature, ReadType) that would use callbacks to resolve tokens. throw new NotImplementedException("Implement creating method signature + var args from byte array (at this point)."); default: return tArgs.ResolvedMember is Type? ctx.Cache.GetOrAdd((Type)tArgs.ResolvedMember) : (tArgs.ResolvedMember is System.Reflection.FieldInfo ? ctx.Cache.GetOrAdd((System.Reflection.FieldInfo)tArgs.ResolvedMember) : (tArgs.ResolvedMember is System.Reflection.MethodInfo ? (Object)ctx.Cache.GetOrAdd((System.Reflection.MethodInfo)tArgs.ResolvedMember) : ctx.Cache.GetOrAdd((System.Reflection.ConstructorInfo)tArgs.ResolvedMember) ) ); } }); }
internal CILFieldImpl( CILReflectionContextImpl ctx, Int32 anID, LazyWithLock <ListProxy <CILCustomAttribute> > cAttrDataFunc, SettableValueForEnums <FieldAttributes> fAttributes, SettableValueForClasses <String> aName, Func <CILType> declaringTypeFunc, Func <CILTypeBase> fieldTypeFunc, SettableLazy <Object> aConstValue, SettableValueForClasses <Byte[]> anInitialValue, LazyWithLock <ListProxy <CILCustomModifier> > customModsFunc, SettableLazy <Int32> aFieldOffset, SettableLazy <MarshalingInfo> marshalInfoVal, Boolean resettablesAreSettable = false ) : base(ctx, CILElementKind.Field, anID, cAttrDataFunc) { InitFields( ref this.fieldAttributes, ref this.name, ref this.declaringType, ref this.fieldType, ref this.constValue, ref this.initialValue, ref this.customModifiers, ref this.fieldOffset, ref this.marshalInfo, fAttributes, aName, declaringTypeFunc, fieldTypeFunc, aConstValue, anInitialValue, customModsFunc, aFieldOffset, marshalInfoVal, resettablesAreSettable ); }
internal CILCustomAttributeContainerImpl( CILReflectionContextImpl ctx, Int32 anID, CILElementKind kind, Func <CustomAttributeDataEventArgs> evtArgsFunc ) : base(ctx, anID) { ArgumentValidator.ValidateNotNull("Reflection context", ctx); InitFields( ref this.cilKind, ref this.attributes, kind, new LazyWithLock <ListProxy <CILCustomAttribute> >(() => { var evtArgs = evtArgsFunc(); ctx.LaunchCustomAttributeDataLoadEvent(evtArgs); var thisElement = (CILCustomAttributeContainer)this.context.Cache.ResolveAnyID(this.cilKind, this.id); return(ctx.CollectionsFactory.NewListProxy <CILCustomAttribute>(new List <CILCustomAttribute>(evtArgs.CustomAttributeData.Select(tuple => CILCustomAttributeFactory.NewAttribute(thisElement, tuple.Item1, tuple.Item2, tuple.Item3))))); }) ); }