コード例 #1
0
        public void Initialize(ModuleDeclaration module)
        {
            this.loggingImplementation = new LoggingImplementationTypeBuilder(module);
            this.formatWriter = new StringFormatWriter(module);

            this.loggerType = module.FindType(typeof(Logger));

            Predicate<MethodDefDeclaration> singleMessagePredicate =
                method => method.Parameters.Count == 1 &&
                    IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String);

            this.categoryInitializerMethod = module.FindMethod(module.FindType(typeof(LogManager)), "GetLogger", singleMessagePredicate);

            this.writeDebugMethod = module.FindMethod(this.loggerType, "Trace", singleMessagePredicate);
            this.writeInfoMethod = module.FindMethod(this.loggerType, "Info", singleMessagePredicate);
            this.writeWarnMethod = module.FindMethod(this.loggerType, "Warn", singleMessagePredicate);
            this.writeErrorMethod = module.FindMethod(this.loggerType, "Error", singleMessagePredicate);
            this.writeFatalMethod = module.FindMethod(this.loggerType, "Fatal", singleMessagePredicate);

            this.getIsTraceEnabledMethod = module.FindMethod(this.loggerType, "get_IsTraceEnabled");
            this.getIsInfoEnabledMethod = module.FindMethod(this.loggerType, "get_IsInfoEnabled");
            this.getIsWarnEnabledMethod = module.FindMethod(this.loggerType, "get_IsWarnEnabled");
            this.getIsErrorEnabledMethod = module.FindMethod(this.loggerType, "get_IsErrorEnabled");
            this.getIsFatalEnabledMethod = module.FindMethod(this.loggerType, "get_IsFatalEnabled");
        }
コード例 #2
0
        public void Initialize(ModuleDeclaration module)
        {
            this.loggingImplementation = new LoggingImplementationTypeBuilder(module);
            this.formatWriter          = new StringFormatWriter(module);

            this.loggerType = module.FindType(typeof(Logger));

            Predicate <MethodDefDeclaration> singleMessagePredicate =
                method => method.Parameters.Count == 1 &&
                IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String);

            this.categoryInitializerMethod = module.FindMethod(module.FindType(typeof(LogManager)), "GetLogger", singleMessagePredicate);

            this.writeDebugMethod = module.FindMethod(this.loggerType, "Trace", singleMessagePredicate);
            this.writeInfoMethod  = module.FindMethod(this.loggerType, "Info", singleMessagePredicate);
            this.writeWarnMethod  = module.FindMethod(this.loggerType, "Warn", singleMessagePredicate);
            this.writeErrorMethod = module.FindMethod(this.loggerType, "Error", singleMessagePredicate);
            this.writeFatalMethod = module.FindMethod(this.loggerType, "Fatal", singleMessagePredicate);

            this.getIsTraceEnabledMethod = module.FindMethod(this.loggerType, "get_IsTraceEnabled");
            this.getIsInfoEnabledMethod  = module.FindMethod(this.loggerType, "get_IsInfoEnabled");
            this.getIsWarnEnabledMethod  = module.FindMethod(this.loggerType, "get_IsWarnEnabled");
            this.getIsErrorEnabledMethod = module.FindMethod(this.loggerType, "get_IsErrorEnabled");
            this.getIsFatalEnabledMethod = module.FindMethod(this.loggerType, "get_IsFatalEnabled");
        }
コード例 #3
0
        public static AssemblyLoaderInfo LoadAssemblyLoader(bool createTemporaryAssemblies,
                                                            bool hasUnmanaged,
                                                            ModuleDeclaration module)
        {
            AssemblyLoaderInfo info = new AssemblyLoaderInfo();
            TypeDefDeclaration sourceType;

            if (createTemporaryAssemblies)
            {
                sourceType = module.FindType("PostSharp.Community.Packer.Templates.ILTemplateWithTempAssembly")
                             .GetTypeDefinition();
            }
            else if (hasUnmanaged)
            {
                sourceType = module.FindType("PostSharp.Community.Packer.Templates.ILTemplateWithUnmanagedHandler")
                             .GetTypeDefinition();
            }
            else
            {
                sourceType = module.FindType("PostSharp.Community.Packer.Templates.ILTemplate")
                             .GetTypeDefinition();
            }

            info.AttachMethod            = module.FindMethod(sourceType, "Attach").GetMethodDefinition();
            info.StaticConstructorMethod = module.FindMethod(sourceType, ".cctor").GetMethodDefinition();

            info.AssemblyNamesField = sourceType.FindField("assemblyNames")?.Field;
            info.SymbolNamesField   = sourceType.FindField("symbolNames")?.Field;
            info.PreloadListField   = sourceType.FindField("preloadList")?.Field;
            info.Preload32ListField = sourceType.FindField("preload32List")?.Field;
            info.Preload64ListField = sourceType.FindField("preload64List")?.Field;
            info.Md5HashField       = sourceType.FindField("md5Hash")?.Field;
            info.ChecksumsField     = sourceType.FindField("checksums")?.Field;
            return(info);
        }
コード例 #4
0
 public TransformationAssets(ModuleDeclaration module)
 {
     ObjectTypeSignature = module.FindType(typeof(object));
     ObjectEqualsMethod = module.FindMethod(typeof(object).GetMethod("Equals", new[] { typeof(object), typeof(object) }), BindingOptions.Default);
     LocationBindingTypeSignature = module.FindType(typeof(LocationBinding<>));
     SetValueMethod = module.FindMethod(LocationBindingTypeSignature, "SetValue", x => x.DeclaringType.IsGenericDefinition);
     GetValueMethod = module.FindMethod(LocationBindingTypeSignature, "GetValue", x => x.DeclaringType.IsGenericDefinition);
 }
コード例 #5
0
        public void Initialize(ModuleDeclaration module)
        {
            this.module = module;
            this.loggingImplementation = new LoggingImplementationTypeBuilder(module);
            this.loggerType = module.FindType(typeof(Logger));

            LoggerMethodsBuilder builder = new LoggerMethodsBuilder(module, this.loggerType);

            this.categoryInitializerMethod = module.FindMethod(module.FindType(typeof(LogManager)), "GetLogger",
                method => method.Parameters.Count == 1 && IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String) );

            this.loggerMethods[LogLevel.Debug] = builder.CreateLoggerMethods("Trace");
            this.loggerMethods[LogLevel.Info] = builder.CreateLoggerMethods("Info");
            this.loggerMethods[LogLevel.Warning] = builder.CreateLoggerMethods("Warn");
            this.loggerMethods[LogLevel.Error] = builder.CreateLoggerMethods("Error");
            this.loggerMethods[LogLevel.Fatal] = builder.CreateLoggerMethods("Fatal");
        }
コード例 #6
0
        public void Initialize(ModuleDeclaration module)
        {
            this.module = module;
            this.loggingImplementation = new LoggingImplementationTypeBuilder(module);

            this.loggerType = module.FindType(typeof(ILog));
            LoggerMethodsBuilder builder = new LoggerMethodsBuilder(module, this.loggerType);

            this.categoryInitializerMethod = module.FindMethod(module.FindType(typeof(LogManager)), "GetLogger",
                                                               method => method.Parameters.Count == 1 &&
                                                               IntrinsicTypeSignature.Is(method.Parameters[0].ParameterType, IntrinsicType.String));

            this.loggerMethods[LogLevel.Debug]   = builder.CreateLoggerMethods("Debug");
            this.loggerMethods[LogLevel.Info]    = builder.CreateLoggerMethods("Info");
            this.loggerMethods[LogLevel.Warning] = builder.CreateLoggerMethods("Warn");
            this.loggerMethods[LogLevel.Error]   = builder.CreateLoggerMethods("Error");
            this.loggerMethods[LogLevel.Fatal]   = builder.CreateLoggerMethods("Fatal");
        }
コード例 #7
0
        public Assets(ModuleDeclaration module)
        {
            INamedType dictionary = (INamedType)module.FindType(typeof(Dictionary <,>));

            DictionaryOfStringOfStringAdd = module.FindMethod(dictionary, "Add").GetGenericInstance(
                new GenericMap(module, new List <ITypeSignature>
            {
                module.Cache.GetIntrinsic(IntrinsicType.String),
                module.Cache.GetIntrinsic(IntrinsicType.String)
            }));

            INamedType list = (INamedType)module.FindType(typeof(List <>));

            ListOfStringAdd = module.FindMethod(list, "Add").GetGenericInstance(
                new GenericMap(module, new List <ITypeSignature>
            {
                module.Cache.GetIntrinsic(IntrinsicType.String)
            }));
        }
コード例 #8
0
        public PropertyNotificationAssets(ModuleDeclaration module)
        {
            if (module == null) throw new ArgumentNullException("module");
            Contract.EndContractBlock();
            //INotifyPropertyChanged Related
            INotifyPropertyChangedTypeSignature = module.FindType(typeof(INotifyPropertyChanged));
            PropertyChangedEventHandlerTypeSignature =
                module.FindType(typeof(INotifyPropertyChanged).GetEvent("PropertyChanged").EventHandlerType);

            PropertyChangedEventHandlerInvokeMethod =
                module.FindMethod(PropertyChangedEventHandlerTypeSignature, "Invoke");

            PropertyChangedEventArgsTypeSignature =
                module.FindType(typeof(PropertyChangedEventArgs));

            PropertyChangedEventArgsConstructor =
                module.FindMethod(PropertyChangedEventArgsTypeSignature, ".ctor");

            //INotifyPropertyChanging Realted
            INotifyPropertyChangingTypeSignature =
                module.FindType(typeof(INotifyPropertyChanging));
            PropertyChangingEventHandlerTypeSignature =
                module.FindType(typeof(INotifyPropertyChanging).GetEvent("PropertyChanging").EventHandlerType);

            PropertyChangingEventHandlerInvokeMethod =
                module.FindMethod(PropertyChangingEventHandlerTypeSignature, "Invoke");

            PropertyChangingEventArgsTypeSignature =
                module.FindType(typeof(PropertyChangingEventArgs));

            PropertyChangingEventArgsConstructor =
                module.FindMethod(PropertyChangingEventArgsTypeSignature, ".ctor");
        }
コード例 #9
0
            // ReSharper restore InconsistentNaming

            public MoveNextTransformation(AsyncStateMachineAspectWeaver parent)
                : base(parent)
            {
                ModuleDeclaration module = parent.Module;

                // ReSharper disable InconsistentNaming
                IType actor_Type = (IType)module.FindType(typeof(Actor), BindingOptions.Default);

                this.actor_GetDispatcher_Method = module.FindMethod(actor_Type, "get_Dispatcher");


                IType dispatcher_Type = (IType)module.FindType(typeof(IDispatcher), BindingOptions.Default);

                this.dispatcher_CheckAccess_Method = module.FindMethod(dispatcher_Type, "CheckAccess");
                this.dispatcher_getSynchronizationContext_Method = module.FindMethod(dispatcher_Type, "get_SynchronizationContext");

                IType task_Type = (IType)module.FindType(typeof(Task), BindingOptions.Default);

                this.task_Yield_Method = module.FindMethod(task_Type, "Yield", 0);

                IType yieldAwaitable_Type = (IType)module.FindType("System.Runtime.CompilerServices.YieldAwaitable, mscorlib", BindingOptions.Default);

                this.yieldAwaitable_GetAwaiter_Method = module.FindMethod(yieldAwaitable_Type, "GetAwaiter");

                this.yieldAwaiter_Type = (IType)this.yieldAwaitable_GetAwaiter_Method.ReturnType;

                this.asyncVoidMethodBuilder_Type = (IType)module.FindType("System.Runtime.CompilerServices.AsyncVoidMethodBuilder, mscorlib",
                                                                          BindingOptions.Default);
                this.asyncVoidMethodBuilder_AwaitUnsafeOnCompleted_Method = module.FindMethod(this.asyncVoidMethodBuilder_Type, "AwaitUnsafeOnCompleted");

                this.asyncTaskMethodBuilder_Type = (IType)module.FindType("System.Runtime.CompilerServices.AsyncTaskMethodBuilder, mscorlib",
                                                                          BindingOptions.Default);
                this.asyncTaskMethodBuilder_AwaitUnsafeOnCompleted_Method = module.FindMethod(this.asyncTaskMethodBuilder_Type, "AwaitUnsafeOnCompleted");

                this.asyncTaskMethodBuilderGenericType = (IType)module.FindType("System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1, mscorlib",
                                                                                BindingOptions.Default);
                this.asyncTaskMethodBuilderGeneric_AwaitUnsafeOnCompleted_Method = module.FindMethod(this.asyncTaskMethodBuilderGenericType,
                                                                                                     "AwaitUnsafeOnCompleted");

                this.synchronizationContext_Type = (IType)module.FindType(typeof(SynchronizationContext), BindingOptions.Default);
                this.synchronizationContext_getCurrent_Method = module.FindMethod(this.synchronizationContext_Type, "get_Current");
                this.synchronizationContext_SetSynchronizationContext_Method = module.FindMethod(this.synchronizationContext_Type, "SetSynchronizationContext");


                // ReSharper restore InconsistentNaming
            }
コード例 #10
0
        private IMethod FindConsoleWriteLine()
        {
            // Represents the module (= assembly) that we're modifying:
            ModuleDeclaration module = this.Project.Module;

            // Finds the System.Console type usable in that module. We don't know exactly where it comes from. It could
            // be mscorlib in .NET Framework or something else in .NET Core:
            INamedType console = (INamedType)module.FindType(typeof(Console));

            // Finds the one overload that we want: System.Console.WriteLine(System.String):
            IGenericMethodDefinition method = module.FindMethod(console, "WriteLine",
                                                                declaration => declaration.Parameters.Count == 1 &&
                                                                declaration.Parameters[0].ParameterType.GetReflectionName() == "System.String");

            return(method);
        }
コード例 #11
0
 public Assets(ModuleDeclaration module)
 {
     OnThrow   = module.FindMethod(typeof(OnThrowAspectAttribute).GetMethod("OnThrow", new[] { typeof(Exception) }), BindingOptions.Default);
     Exception = module.FindType(typeof(Exception));
 }
コード例 #12
0
 public Assets(ModuleDeclaration module)
 {
     OnThrow = module.FindMethod(typeof(OnThrowAspectAttribute).GetMethod("OnThrow", new[] { typeof(Exception) }), BindingOptions.Default);
     Exception = module.FindType(typeof(Exception));
 }