/// <summary> /// Adds a <see cref="TargetFrameworkAttribute"/> to the <see cref="CILAssembly"/> which has given framework information. /// This method should not be used when adding <see cref="TargetFrameworkAttribute"/> to Portable Class Libraries. /// </summary> /// <param name="assembly">The <see cref="CILAssembly"/>.</param> /// <param name="fwName">The name of the target framework. This will be passed directly as string argument to the attribute constructor.</param> /// <param name="fwDisplayName">The display name of the target framework.</param> /// <exception cref="NullReferenceException">If <paramref name="assembly"/> is <c>null</c>.</exception> public static void AddTargetFrameworkAttributeNative(this CILAssembly assembly, String fwName, String fwDisplayName) { assembly.AddCustomAttribute( ModuleReader.TARGET_FRAMEWORK_ATTRIBUTE_CTOR.NewWrapper(assembly.ReflectionContext), new CILCustomAttributeTypedArgument[] { CILCustomAttributeFactory.NewTypedArgument(ModuleReader.TARGET_FRAMEWORK_ATTRIBUTE_CTOR.GetParameters().First().ParameterType.NewWrapperAsType(assembly.ReflectionContext), fwName) }, fwDisplayName == null ? null : new CILCustomAttributeNamedArgument[] { CILCustomAttributeFactory.NewNamedArgument(ModuleReader.TARGET_FRAMEWORK_ATTRIBUTE_NAMED_PROPERTY.NewWrapper(assembly.ReflectionContext), CILCustomAttributeFactory.NewTypedArgument((CILType)ModuleReader.TARGET_FRAMEWORK_ATTRIBUTE_NAMED_PROPERTY.NewWrapper(assembly.ReflectionContext).GetPropertyType(), fwDisplayName)) } ); }
/// <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)) } ); }
private IDictionary <Assembly, CILModule> PerformEmitting(Boolean isSilverlight, CILReflectionContext reflectionContext, out IDictionary <CompositeModel, CompositeEmittingInfo> cResultsOut) { var typeModelDic = this._typeModelDic.Value; var assembliesArray = this._affectedAssemblies.Value.ToArray(); var models = this._models.CQ.Values.ToArray(); var supports = this._compositeModelTypeSupport; var cResults = models.ToDictionary(muudel => muudel, muudel => new CompositeEmittingInfo(reflectionContext, models)); cResultsOut = cResults; var codeGens = models .Select(muudel => supports[muudel.ModelType]) .Distinct() .ToDictionary(mt => mt.AssemblyScopeSupport.ModelType, mt => Tuple.Create(mt.NewCodeGenerator(isSilverlight, reflectionContext), mt.CodeGenerationInfo)); var assemblyDic = new Dictionary <Assembly, CILModule>(); foreach (var currentAssembly in assembliesArray) { if (!ReflectionHelper.QI4CS_ASSEMBLY.Equals(currentAssembly)) { var assemblyBareFileName = Qi4CSGeneratedAssemblyAttribute.GetGeneratedAssemblyName(currentAssembly); var ass = reflectionContext.NewBlankAssembly(assemblyBareFileName); var eAss = currentAssembly.NewWrapper(reflectionContext); ass.Name.MajorVersion = eAss.Name.MajorVersion; ass.Name.MinorVersion = eAss.Name.MinorVersion; ass.Name.BuildNumber = eAss.Name.BuildNumber; ass.Name.Revision = eAss.Name.Revision; ass.Name.Culture = eAss.Name.Culture; ass.AddNewCustomAttributeTypedParams(ASS_TITLE_ATTRIBUTE_CTOR.NewWrapper(reflectionContext), CILCustomAttributeFactory.NewTypedArgument(assemblyBareFileName, reflectionContext)); ass.AddNewCustomAttributeTypedParams(ASS_DESCRIPTION_ATTRIBUTE_CTOR.NewWrapper(reflectionContext), CILCustomAttributeFactory.NewTypedArgument((assemblyBareFileName + " Enhanced by Qi4CS."), reflectionContext)); //ass.AddNewCustomAttributeTypedParams( ASS_DEFAULT_ALIAS_ATTRIBUTE_CTOR.NewWrapper( reflectionContext ), CILCustomAttributeFactory.NewTypedArgument( assemblyBareFileName, reflectionContext ) ); ass.AddNewCustomAttributeTypedParams(QI4CS_GENERATED_ATTRIBUTE_CTOR.NewWrapper(reflectionContext)); var mod = ass.AddModule(assemblyBareFileName + ".dll"); assemblyDic.Add(currentAssembly, mod); } } // Phase 1: Emit empty types System.Threading.Tasks.Parallel.ForEach(assembliesArray, currentAssembly => { foreach (var model in models) { var tuple1 = codeGens[model.ModelType]; var tuple2 = cResults[model]; tuple1.Item1.EmitTypesForModel(model, typeModelDic[model], currentAssembly, GetEmittingModule(model, assemblyDic, currentAssembly), tuple1.Item2, tuple2); } }); // Phase 2: Emit fragment methods System.Threading.Tasks.Parallel.ForEach(assembliesArray, currentAssembly => { foreach (var model in models) { var tuple1 = codeGens[model.ModelType]; var tuple2 = cResults[model]; tuple1.Item1.EmitFragmentMethods(model, typeModelDic[model], currentAssembly, tuple1.Item2, tuple2); } }); // Phase 3: Emit composite methods and concern & side-effect invocation types System.Threading.Tasks.Parallel.ForEach(assembliesArray, currentAssembly => { foreach (var model in models) { var tuple1 = codeGens[model.ModelType]; var tuple2 = cResults[model]; tuple1.Item1.EmitCompositeMethosAndInvocationInfos(model, typeModelDic[model], currentAssembly, tuple1.Item2, tuple2); } }); // Phase 4: Emit all composite extra methods (state check, pre-prototype, etc) System.Threading.Tasks.Parallel.ForEach(assembliesArray, currentAssembly => { foreach (var model in models) { var tuple1 = codeGens[model.ModelType]; var tuple2 = cResults[model]; tuple1.Item1.EmitCompositeExtraMethods(model, typeModelDic[model], currentAssembly, tuple1.Item2, tuple2); } }); // Phase 5: Emit all composite constructors System.Threading.Tasks.Parallel.ForEach(assembliesArray, currentAssembly => { foreach (var model in models) { var tuple1 = codeGens[model.ModelType]; var tuple2 = cResults[model]; tuple1.Item1.EmitCompositeConstructors(model, typeModelDic[model], currentAssembly, tuple1.Item2, tuple2); } }); // Phase 6: Emit all composite factory types System.Threading.Tasks.Parallel.ForEach(assembliesArray, currentAssembly => { foreach (var model in models) { var tuple1 = codeGens[model.ModelType]; var tuple2 = cResults[model]; tuple1.Item1.EmitCompositeFactory(model, currentAssembly, GetEmittingModule(model, assemblyDic, currentAssembly), tuple1.Item2, tuple2); } }); return(assemblyDic); }
private static void ctx_CustomAttributeDataLoadEvent(object sender, CustomAttributeDataEventArgs e) { IEnumerable <System.Reflection.CustomAttributeData> attrs; if (e.Member != null) { attrs = e.Member.GetCustomAttributesData(); } else if (e.Type != null) { attrs = e.Type.GetCustomAttributesData(); } else if (e.Parameter != null) { attrs = e.Parameter.GetCustomAttributesData(); } else if (e.Assembly != null) { attrs = e.Assembly.GetCustomAttributesData(); } else if (e.Module != null) { attrs = e.Module.GetCustomAttributesData(); } else { throw new ArgumentException("Custom attribute data event with no native member?"); } e.CustomAttributeData = attrs.Select(attr => Tuple.Create( attr.Constructor.NewWrapper(e.Context), attr.ConstructorArguments.Select(cArg => CILCustomAttributeFactory.NewTypedArgument((cArg.ArgumentType.NewWrapperAsType(e.Context)), cArg.Value)), attr.NamedArguments.Select(nArg => CILCustomAttributeFactory.NewNamedArgument((nArg.MemberInfo is System.Reflection.PropertyInfo ? (CILElementForNamedCustomAttribute)((System.Reflection.PropertyInfo)nArg.MemberInfo).NewWrapper(e.Context) : ((System.Reflection.FieldInfo)nArg.MemberInfo).NewWrapper(e.Context)), CILCustomAttributeFactory.NewTypedArgument(nArg.TypedValue.ArgumentType.NewWrapperAsType(e.Context), nArg.TypedValue.Value))) )); }