public void Execute() { var assemblyLevelSettings = new AssemblyLevelSettings(ModuleDefinition.Assembly); if (assemblyLevelSettings.AssemblyConfigureAwait.HasValue) { LogInfo( $"Detected assembly wide configuration (ConfigureAwait({assemblyLevelSettings.AssemblyConfigureAwait.Value}))"); } var types = ModuleDefinition.GetTypes().ToList(); var typeProvider = new TypeProvider(AssemblyResolver); var typeReferenceProvider = new TypeReferenceProvider(ModuleDefinition, typeProvider); var asyncIlHelper = new AsyncIlHelper(typeProvider, typeReferenceProvider, ModuleDefinition); var stopwach = Stopwatch.StartNew(); foreach (var typeDefinition in types) { ProcessType(assemblyLevelSettings, typeDefinition, asyncIlHelper); } LogInfo($"Needed {stopwach.ElapsedMilliseconds} ms to process {types.Count} types"); RemoveReference(); }
private void ProcessType(AssemblyLevelSettings assemblySettings, TypeDefinition type, AsyncIlHelper asyncIlHelper) { if (!type.HasMethods || type.IsCompilerGenerated() && type.IsIAsyncStateMachine()) { return; } var typeSettings = new TypeLevelSettings(type, assemblySettings); foreach (var method in type.Methods) { var methodSettings = new MethodLevelSettings(method, typeSettings); var configureAwait = methodSettings.GetConfigureAwait(); if (configureAwait == null) { continue; } var asyncStateMachineType = method.GetAsyncStateMachineType(); if (asyncStateMachineType == null) { if (methodSettings.MethodConfigureAwait.HasValue) { LogWarning($"ConfigureAwaitAttribue applied to non-async method '{method.FullName}'."); } continue; } asyncIlHelper.AddAwaitConfigToAsyncMethod(asyncStateMachineType, configureAwait.Value); } }