static bool IsSpecialCase (TypeReference type)
		{
			return type.Inherits ("System.Security", "PermissionSet");
		}
        private void CheckCallingBaseMethod(TypeReference type, MethodSignature methodSignature)
        {
            MethodDefinition method = type.GetMethod (methodSignature);
            if (method == null)
                return; // Perhaps should report that doesn't exist the method (only with ctor).

            // is there any Call or Callvirt instructions in the method
            if (OpCodeBitmask.Calls.Intersect (OpCodeEngine.GetBitmask (method))) {
                // in this case we check further
                foreach (Instruction instruction in method.Body.Instructions) {
                    if (instruction.OpCode.FlowControl != FlowControl.Call)
                        continue;

                    MethodReference operand = (MethodReference) instruction.Operand;
                    TypeReference tr = operand.DeclaringType;
                    if (methodSignature.Matches (operand) && type.Inherits (tr.Namespace, tr.Name))
                        return;
                }
            }

            Runner.Report (method, Severity.High, Confidence.High);
        }
        static string InheritsOrImplements(TypeReference type, string nameSpace, string name)
        {
            if (type.Inherits (nameSpace, name) || type.Implements (nameSpace, name))
                return String.Empty;

            return String.Format (CultureInfo.InvariantCulture,
                "'{0}' should only be used for types that inherits or implements '{1}.{2}'.",
                type.Name, nameSpace, name);
        }
        static string CheckCollection(TypeReference type)
        {
            if (type.Implements ("System.Collections", "ICollection") ||
                type.Implements ("System.Collections", "IEnumerable") ||
                type.Implements ("System.Collections.Generic", "ICollection`1"))
                return String.Empty;

            if (type.Inherits ("System.Collections", "Queue") || type.Inherits ("System.Collections", "Stack") ||
                type.Inherits ("System.Data", "DataSet") || type.Inherits ("System.Data", "DataTable"))
                return String.Empty;

            return "'Collection' should only be used for implementing ICollection or IEnumerable or inheriting from Queue, Stack, DataSet and DataTable.";
        }
Пример #5
0
		static string InheritsOrImplements (TypeReference type, string subtype)
		{
			if (type.Inherits (subtype) || type.Implements (subtype))
				return String.Empty;
			return String.Format ("'{0}' should only be used for types that inherits or implements {1}.", type.Name, subtype);
		}
		static string InheritFromWeakType (TypeReference type, string nameSpace, string name)
		{
			if (!type.Inherits (nameSpace, name))
				return String.Empty;
			return String.Format (CultureInfo.InvariantCulture, "'{0}' inherits from '{1}.{2}'.", 
				type.GetFullName (), nameSpace, name);
		}