static bool IsGenericType (TypeReference type, string nspace, string name)
		{
			if (type.IsNamed (nspace, name))
				return true;

			var type_spec = type as TypeSpecification;
			if (type_spec != null && type_spec.ElementType.IsNamed (nspace, name))
				return true;

			// handle things like ICollection<T>
			GenericInstanceType git = (type as GenericInstanceType);
			if (git == null)
				return false;

			return FindGenericType (git, nspace, name);
		}
		protected override bool IsPrefered (TypeReference type)
		{
			return type.IsNamed ("System", "StringComparison");
		}
		static bool IsSpecificXmlType (TypeReference type)
		{
			if (type.Namespace == "System.Xml") {
				string name = type.Name;
				return ((name == "XmlDocument") || (name == "XmlNode"));
			}
			return type.IsNamed ("System.Xml.XPath", "XPathDocument");
		}
Пример #4
0
 private static bool AreSameElementTypes(TypeReference a, TypeReference b)
 {
     return a.IsGenericParameter || b.IsGenericParameter || b.IsNamed(a.Namespace, a.Name);
 }
		private bool CheckGenericDelegate (TypeReference type)
		{
			if (type.IsNamed ("System", "EventHandler`1"))
				return true;

			Runner.Report (type, Severity.Medium, Confidence.High, "Generic delegates should use EventHandler<TEventArgs>");
			return false;
		}
 private static bool IsIgnoredSuggestionType(TypeReference type)
 {
     return (type.IsNamed ("System", "Object") || IsFromNonGenericCollectionNamespace (type.Namespace));
 }
		protected override bool IsPrefered (TypeReference type)
		{
			return (type.IsNamed ("System", "IFormatProvider") || type.IsNamed ("System.Globalization", "CultureInfo"));
		}
Пример #8
0
		private static bool Match (TypeReference type, string nameSpace, string name)
		{
			int np = name.IndexOf ('/');
			if (np == -1) {
				if (type.IsNamed (nameSpace, name))
					return true;
			} else if (type.IsNested) {
				string tname = type.Name;
				TypeReference dt = type.DeclaringType;
				if ((nameSpace == dt.Namespace) &&
					(String.CompareOrdinal (name, 0, dt.Name, 0, np) == 0) &&
					(String.CompareOrdinal (name, np + 1, tname, 0, tname.Length) == 0))
					return true;
			}
			return false;
		}
		public override RuleResult CheckMethod (MethodDefinition method)
		{
			if (!method.HasBody)
				return RuleResult.DoesNotApply;

			//the rule does not apply to the particular case of ToString()
			//that have its own ToStringShouldNotReturnNullRule
			if (!method.HasParameters && method.Name == "ToString")
				return RuleResult.DoesNotApply;

			//only apply to methods returning string, array, or IEnumerable-impl
			return_type = method.ReturnType;
			string_return_type = return_type.IsNamed ("System", "String");
			array_return_type = return_type.IsArray;
			ienumerable_return_type = return_type.Implements ("System.Collections", "IEnumerable");

			if (!string_return_type && !array_return_type && !ienumerable_return_type)
				return RuleResult.DoesNotApply;

			return base.CheckMethod (method);
		}