Esempio n. 1
0
		private bool DoBaseFailed(TypeDefinition type)
		{
			bool failed = false;
			
			if (type.BaseType != null)
				Log.DebugLine(this, "base name: {0}", type.BaseType.FullName);				

			if (type.IsSubclassOf("System.Attribute", Cache))
				failed = DoCheckSuffix(type, "Attribute");
			
			else if (type.IsSubclassOf("System.EventArgs", Cache))
				failed = DoCheckSuffix(type, "EventArgs");
			
			else if (type.IsSubclassOf("System.Exception", Cache))
				failed = DoCheckSuffix(type, "Exception");
			
			else if (type.IsSubclassOf("System.Collections.Queue", Cache))
				failed = DoCheckSuffix(type, "Collection", "Queue");
			
			else if (type.IsSubclassOf("System.Collections.Stack", Cache))
				failed = DoCheckSuffix(type, "Collection", "Stack");
			
			else if (type.IsSubclassOf("System.Data.DataSet", Cache))
				failed = DoCheckSuffix(type, "DataSet");
			
			else if (type.IsSubclassOf("System.Data.DataTable", Cache))
				failed = DoCheckSuffix(type, "Collection", "DataTable");
			
			else if (type.IsSubclassOf("System.IO.Stream", Cache))
				failed = DoCheckSuffix(type, "Stream");
									
			return failed;
		}
Esempio n. 2
0
		public void VisitType(TypeDefinition type)
		{				
			if (!type.IsAbstract)
			{
				Log.DebugLine(this, "-----------------------------------"); 
				Log.DebugLine(this, "checking {0}", type);				
	
				if (type.BaseType != null)
				{			
					bool passed = !type.IsSubclassOf("System.Attribute", Cache);
	
					for (int i = 0; i < type.CustomAttributes.Count && !passed; ++i)
					{
						string name = type.CustomAttributes[i].Constructor.ToString();
						if (name.Contains("System.AttributeUsageAttribute"))
						{
							passed = true;
						}
					}
					
					if (!passed)
					{
						Log.DebugLine(this, "{0} has no usage attribute", type.Name); 
						Reporter.TypeFailed(type, CheckID, string.Empty);
					}
				}
			}
		}
Esempio n. 3
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);
					}
				}
			}
		}
Esempio n. 4
0
		public void VisitType(TypeDefinition type)
		{						
			Log.DebugLine(this, "-----------------------------------"); 
			Log.DebugLine(this, "checking {0}", type);				

			if (type.IsSubclassOf("System.ApplicationException", Cache))
			{
				Log.DebugLine(this, "descends from ApplicationException"); 
				Reporter.TypeFailed(type, CheckID, string.Empty);
			}
		}
Esempio n. 5
0
		private bool DoTypeFailed(TypeDefinition type)
		{
			bool failed = false;
			
			if (DoCheckSuffix(type, "Attribute"))
				failed = !type.IsSubclassOf("System.Attribute", Cache);
				
			else if (DoCheckSuffix(type, "Queue"))
				failed = !type.IsSubclassOf("System.Collections.Queue", Cache);

			else if (DoCheckSuffix(type, "Dictionary"))
				failed = !type.TypeOrBaseImplements("System.Collections.IDictionary", Cache);

			else if (DoCheckSuffix(type, "Stack"))
				failed = !type.IsSubclassOf("System.Collections.Stack", Cache);				

			else if (DoCheckSuffix(type, "Collection"))
				failed = !type.IsSubclassOf("System.Collections.Queue", Cache) &&
					!type.IsSubclassOf("System.Collections.Stack", Cache) &&
					!type.IsSubclassOf("System.Data.DataSet", Cache) &&
					!type.IsSubclassOf("System.Data.DataTable", Cache) &&
					!type.TypeOrBaseImplements("System.Collections.ICollection", Cache) &&
					!type.TypeOrBaseImplements("System.Collections.IEnumerable", Cache) &&
					!type.TypeOrBaseImplements("System.Collections.Generic.ICollection", Cache);
				
			else if (DoCheckSuffix(type, "EventArgs"))
				failed = !type.IsSubclassOf("System.EventArgs", Cache);
				
			else if (DoCheckSuffix(type, "Exception"))
				failed = !type.IsSubclassOf("System.Exception", Cache);
				
			else if (DoCheckSuffix(type, "Stream"))
				failed = !type.IsSubclassOf("System.IO.Stream", Cache);				
													
			else if (DoCheckSuffix(type, "Permission"))
				failed = !type.TypeOrBaseImplements("System.Security.IPermission", Cache);

			return failed;
		}
Esempio n. 6
0
		public void VisitType(TypeDefinition type)
		{
			if (type.BaseType != null && type.IsSubclassOf("System.Attribute", Cache))
			{			
				Log.DebugLine(this, "-----------------------------------"); 
				Log.DebugLine(this, "checking {0}", type);		
				
				if (!type.IsSealed && !type.IsAbstract)
				{
					if (type.ExternallyVisible(Cache))
					{
						Log.DebugLine(this, "{0} has no usage attribute", type.Name); 
						Reporter.TypeFailed(type, CheckID, string.Empty);
					}
				}
			}
		}
		public void VisitType(TypeDefinition type)
		{
			if (type.IsSubclassOf("System.Exception", Cache))
			{
				Log.DebugLine(this, "-----------------------------------"); 
				Log.DebugLine(this, "{0}", type);
				
				if (DoHasNonStaticField(type.Fields))
				{
					MethodDefinition[] methods = type.Methods.GetMethod("GetObjectData"); 
					if (methods == null || methods.Length == 0)
					{
						Log.DebugLine(this, "no GetObjectData"); 
						Reporter.TypeFailed(type, CheckID, string.Empty);
					}
				}
			}
		}
Esempio n. 8
0
		private bool DoSuffixFailed(TypeDefinition type)
		{
			bool failed = false;
			
			if (DoCheckSuffix(type, "Delegate"))
				failed = true;
				
			else if (DoCheckSuffix(type, "Enum"))
				failed = true;
				
			else if (DoCheckSuffix(type, "Flags"))
				failed = type.IsSubclassOf("System.Enum", Cache);
				
			else if (DoCheckSuffix(type, "Impl"))
				failed = true;

			return failed;
		}
Esempio n. 9
0
		private bool DoValidType(TypeDefinition type)
		{
			if (type.IsEnum)
			{
				Log.DebugLine(this, "   enum");
				return false;
			}
			else if (type.IsAbstract)
			{
				Log.DebugLine(this, "   abstract");
				return false;
			}
			else if (type.IsSubclassOf("System.Delegate", Cache) || type.IsSubclassOf("System.MulticastDelegate", Cache))
			{
				Log.DebugLine(this, "   delegate");
				return false;
			}	
			else if (type.IsSubclassOf("System.Attribute", Cache))
			{
				Log.DebugLine(this, "   attribute");
				return false;
			}	
			else if (DoAnyDisablesRule(type))
			{
				Log.DebugLine(this, "   disabled");
				return false;
			}	
			else if (type.CustomAttributes.Has("CompilerGeneratedAttribute"))
			{
				Log.DebugLine(this, "   compiler generated");
				return false;
			}
				
//			foreach (MethodDefinition method in type.Methods)
//			{
//				if (!method.IsStatic)
//				{
					Log.DebugLine(this, "   valid type");
//					return true;
//				}
//			}

			return true;
		}
 bool MightNeedFix(TypeDefinition type)
 {
     return !type.IsAbstract && type.IsSubclassOf ("Java.Lang.Object");
 }