コード例 #1
0
ファイル: ModuleWeaver.cs プロジェクト: caesay/ConfigureAwait
        private void ProcessType(bool? assemblyConfigureAwaitValue, TypeDefinition type)
        {
            if (type.IsCompilerGenerated() && type.IsIAsyncStateMachine())
            {
                return;
            }

            var configureAwaitValue = (bool?)type.GetConfigureAwaitAttribute()?.ConstructorArguments[0].Value;
            configureAwaitValue = configureAwaitValue ?? assemblyConfigureAwaitValue;

            foreach (var method in type.Methods)
            {
                var localConfigureAwaitValue = (bool?)method.GetConfigureAwaitAttribute()?.ConstructorArguments[0].Value;
                var localConfigWasSet = localConfigureAwaitValue.HasValue;
                localConfigureAwaitValue = localConfigureAwaitValue ?? configureAwaitValue;
                if (localConfigureAwaitValue == null)
                    continue;

                var asyncStateMachineType = method.GetAsyncStateMachineType();
                if (asyncStateMachineType != null)
                {
                    AddAwaitConfigToAsyncMethod(asyncStateMachineType, localConfigureAwaitValue.Value);
                }
                else if (localConfigWasSet)
                {
                    LogWarning($"ConfigureAwaitAttribue applied to non-async method '{method.FullName}'.");
                    continue;
                }
            }
        }
コード例 #2
0
		public void VisitType(TypeDefinition type)
		{						
			if (type.TypeImplements("System.Collections.IEnumerator") && !type.IsCompilerGenerated())
			{
				Log.DebugLine(this, "-----------------------------------"); 
				Log.DebugLine(this, "checking {0}", type);		
				
				PropertyDefinition[] properties = type.Properties.GetProperties("Current");
				
				bool found = false;
				foreach (PropertyDefinition prop in properties)
				{
					if (prop.PropertyType.ToString() != "System.Object")
					{
						found = true;
						break;
					}
				}
		
				if (!found)
				{
					Log.DebugLine(this, "no strongly typed Current");		
					Reporter.TypeFailed(type, CheckID, string.Empty);
				}
			}
		}
コード例 #3
0
ファイル: Helpers.cs プロジェクト: kiinoo/ILSpy
		public static MethodDefinition GetOriginalCodeLocation(TypeDefinition type)
		{
			if (type != null && type.DeclaringType != null && type.IsCompilerGenerated()) {
				MethodDefinition constructor = GetTypeConstructor(type);
				return FindMethodUsageInType(type.DeclaringType, constructor);
			}
			return null;
		}
コード例 #4
0
ファイル: AsyncDecompiler.cs プロジェクト: FaceHunter/ILSpy
		public static bool IsCompilerGeneratedStateMachine(TypeDefinition type)
		{
			if (!(type.DeclaringType != null && type.IsCompilerGenerated()))
				return false;
			foreach (TypeReference i in type.Interfaces) {
				if (i.Namespace == "System.Runtime.CompilerServices" && i.Name == "IAsyncStateMachine")
					return true;
			}
			return false;
		}
コード例 #5
0
 public static bool IsCompilerGeneratorEnumerator(TypeDefinition type)
 {
     if (!(type.DeclaringType != null && type.IsCompilerGenerated()))
         return false;
     foreach (TypeReference i in type.Interfaces) {
         if (i.Namespace == "System.Collections" && i.Name == "IEnumerator")
             return true;
     }
     return false;
 }
コード例 #6
0
ファイル: SuffixNameRule.cs プロジェクト: dbremner/smokey
		public void VisitType(TypeDefinition type)
		{						
			Log.DebugLine(this, "-----------------------------------"); 
			Log.DebugLine(this, "checking {0}", type);				

			if (!type.IsCompilerGenerated())
			{
				if (DoBaseFailed(type) || DoInterfaceFailed(type))
				{
					Reporter.TypeFailed(type, CheckID, string.Empty);
				}
			}
		}
コード例 #7
0
ファイル: Helpers.cs プロジェクト: FaceHunter/ILSpy
		/// <summary>
		/// Given a compiler-generated type, returns the method where that type is used.
		/// Used to detect the 'parent method' for a lambda/iterator/async state machine.
		/// </summary>
		public static MethodDefinition GetOriginalCodeLocation(TypeDefinition type)
		{
			if (type != null && type.DeclaringType != null && type.IsCompilerGenerated()) {
				if (type.IsValueType) {
					// Value types might not have any constructor; but they must be stored in a local var
					// because 'initobj' (or 'call .ctor') expects a managed ref.
					return FindVariableOfTypeUsageInType(type.DeclaringType, type);
				} else {
					MethodDefinition constructor = GetTypeConstructor(type);
					if (constructor == null)
						return null;
					return FindMethodUsageInType(type.DeclaringType, constructor);
				}
			}
			return null;
		}
コード例 #8
0
		public void VisitType(TypeDefinition type)
		{						
			DBC.Assert(m_state == State.Types, "state is {0}", m_state);
			Log.DebugLine(this, "{0}", type.FullName);

			if (!type.ExternallyVisible(Cache) && DoInstantiable(type) && DoValidType(type))
			{	
				if (!type.IsCompilerGenerated())
				{
					var key = new AssemblyCache.TypeKey(type);
					DBC.Assert(m_keys.IndexOf(key) < 0, "{0} is already in types", type.FullName);
					Log.DebugLine(this, "adding {0}", type.FullName);
					
					m_keys.Add(key);
				}
			}
		}
コード例 #9
0
		public void VisitType(TypeDefinition type)
		{
			if (!type.IsCompilerGenerated())
			{
				if (!type.IsSubclassOf("System.Delegate", Cache) && !type.IsSubclassOf("System.MulticastDelegate", Cache))
				{
					Log.DebugLine(this, "-----------------------------------"); 
					Log.DebugLine(this, "{0:F}", type.FullName);				
		
					if (!type.IsValueType && !type.IsInterface && !type.IsBeforeFieldInit)
					{
						if (type.Name != "<Module>")
							Reporter.TypeFailed(type, CheckID, string.Empty);
					}
				}
			}
		}
コード例 #10
0
		public void VisitType(TypeDefinition type)
		{						
			if (type.IsValueType && !type.IsEnum && !type.IsCompilerGenerated())
			{				
				Log.DebugLine(this, "-----------------------------------"); 
				Log.DebugLine(this, "checking {0}", type);				
	
				// Try to find Equals and GetHashCode.
				var methods = new List<MethodInfo>();
				methods.AddRange(Cache.FindMethods(type, "Equals"));
				methods.AddRange(Cache.FindMethods(type, "GetHashCode"));
				
				// Make sure we found the correct ones.
				bool foundEquals = false;
				for (int i = 0; i < methods.Count && !foundEquals; ++i)
					if (methods[i].Method.Reuses("System.Boolean", "Equals", "System.Object"))
						foundEquals = true;

				bool foundHash = false;
				for (int i = 0; i < methods.Count && !foundHash; ++i)
					if (methods[i].Method.Reuses("System.Int32", "GetHashCode"))
						foundHash = true;

				// If not we have a problem.
				if (!foundEquals && !foundHash)
				{
					string details = "Equals and GetHashCode are missing";
					Log.DebugLine(this, details);
					Reporter.TypeFailed(type, CheckID, details);
				}
				else if (!foundEquals)
				{
					string details = "Equals is missing";
					Log.DebugLine(this, details);
					Reporter.TypeFailed(type, CheckID, details);
				}
				else if (!foundHash)
				{
					string details = "GetHashCode is missing";
					Log.DebugLine(this, details);
					Reporter.TypeFailed(type, CheckID, details);
				}
			}
		}
コード例 #11
0
		public void VisitType(TypeDefinition type)
		{						
			Log.DebugLine(this, "-----------------------------------"); 
			Log.DebugLine(this, "checking {0}", type);				

			if (!type.IsCompilerGenerated())
			{
				if (!type.IsAbstract)
//				if (!type.IsAbstract && !type.FullName.Contains("PrivateImplementationDetails"))
				{
					if (type.BaseType != null && type.BaseType.FullName == "System.Object")
					{
						if (DoHasNoVirtuals(type) && DoAllFieldsAreStatic(type))
						{
							Log.DebugLine(this, "cab be made static"); 
							Reporter.TypeFailed(type, CheckID, string.Empty);
						}
					}
				}
			}
		}
コード例 #12
0
ファイル: NotSealedRule.cs プロジェクト: dbremner/smokey
		public void VisitType(TypeDefinition candidate)
		{
			if (!candidate.IsAbstract && !candidate.ExternallyVisible(Cache) && candidate.IsClass && !candidate.IsSealed)
			{
				if (candidate.FullName != "<Module>" && !candidate.IsCompilerGenerated())
				{
					Log.DebugLine(this, "checking {0}", candidate);	
					
					foreach (TypeDefinition type in Cache.Types)
					{	
						if (type.IsSubclassOf(candidate, Cache))
						{
//							Log.DebugLine(this, "   is base class for {0} [{1}]", type, type.BaseType);	
							return;
						}
//						else
//							Log.DebugLine(this, "   not a base class for {0} [{1}]", type, type.BaseType);	
					}
	
//					Log.DebugLine(this, "   failed");	
					Reporter.TypeFailed(candidate, CheckID, string.Empty);
				}
			}
		}
コード例 #13
0
		bool IsPotentialClosure(TypeDefinition potentialDisplayClass)
		{
			if (potentialDisplayClass == null || !potentialDisplayClass.IsCompilerGenerated())
				return false;
			// check that methodContainingType is within containingType
			while (potentialDisplayClass != context.CurrentType) {
				potentialDisplayClass = potentialDisplayClass.DeclaringType;
				if (potentialDisplayClass == null)
					return false;
			}
			return true;
		}
コード例 #14
0
		public static bool IsCompilerGeneratorEnumerator(TypeDefinition type)
		{
			if (!(type.Name.StartsWith("<", StringComparison.Ordinal) && type.IsCompilerGenerated()))
				return false;
			foreach (TypeReference i in type.Interfaces) {
				if (i.Namespace == "System.Collections" && i.Name == "IEnumerator")
					return true;
			}
			return false;
		}
コード例 #15
0
 private TypeActionAttribute GetTypeActionAttribute(TypeDefinition provider)
 {
     var attr = provider.GetCustomAttribute<TypeActionAttribute>();
     if (attr != null) {
         return attr;
     }
     switch (ImplicitImports) {
         case ImplicitImportSetting.OnlyCompilerGenerated:
             if (provider.IsCompilerGenerated()) {
                 goto case ImplicitImportSetting.ImplicitByDefault;
             }
             goto case ImplicitImportSetting.NoImplicit;
         case ImplicitImportSetting.ImplicitByDefault:
             return new NewTypeAttribute(true);
         default:
         case ImplicitImportSetting.NoImplicit:
             return null;
     }
 }