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; }
/// <summary> /// Adds a <see cref="TargetFrameworkAttribute"/> to the <see cref="CILAssembly"/> which represents information for given target framework. /// </summary> /// <param name="assembly">The <see cref="CILAssembly"/>.</param> /// <param name="monikerInfo">The information about target framework, see <see cref="FrameworkMonikerInfo"/>.</param> /// <param name="monikerMapper">The assembly mapper helper, created by <see cref="E_CIL.CreateMapperForFrameworkMoniker"/> method, or by creating <see cref="EmittingArguments"/> by <see cref="EmittingArguments.CreateForEmittingWithMoniker"/> method and accessing its <see cref="EmittingArguments.AssemblyMapper"/> property.</param> /// <exception cref="NullReferenceException">If <paramref name="assembly"/> is <c>null</c>.</exception> /// <exception cref="ArgumentNullException">If <paramref name="monikerInfo"/> or <paramref name="monikerMapper"/> is <c>null</c>.</exception> public static void AddTargetFrameworkAttributeWithMonikerInfo(this CILAssembly assembly, FrameworkMonikerInfo monikerInfo, EmittingAssemblyMapper monikerMapper) { ArgumentValidator.ValidateNotNull("Moniker info", monikerInfo); ArgumentValidator.ValidateNotNull("Moniker mapper", monikerMapper); var targetFWType = (CILType)monikerMapper.MapTypeBase(ModuleReader.TARGET_FRAMEWORK_ATTRIBUTE_CTOR.DeclaringType.NewWrapper(assembly.ReflectionContext)); var targetFWCtor = targetFWType.Constructors.First(ctor => ctor.Parameters.Count == 1 && ctor.Parameters[0].ParameterType is CILType && ((CILType)ctor.Parameters[0].ParameterType).TypeCode == CILTypeCode.String); var targetFWProp = targetFWType.DeclaredProperties.First(prop => prop.Name == ModuleReader.TARGET_FRAMEWORK_ATTRIBUTE_NAMED_PROPERTY.Name); var fwString = monikerInfo.FrameworkName + ",Version=" + monikerInfo.FrameworkVersion; if (!String.IsNullOrEmpty(monikerInfo.ProfileName)) { fwString += ",Profile=" + monikerInfo.ProfileName; } assembly.AddCustomAttribute( targetFWCtor, new CILCustomAttributeTypedArgument[] { CILCustomAttributeFactory.NewTypedArgument((CILType)targetFWCtor.Parameters[0].ParameterType, fwString) }, new CILCustomAttributeNamedArgument[] { CILCustomAttributeFactory.NewNamedArgument(targetFWProp, CILCustomAttributeFactory.NewTypedArgument((CILType)targetFWProp.GetPropertyType(), monikerInfo.FrameworkDisplayName)) } ); }