diff options
author | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 13:02:25 -0700 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 16:13:41 -0700 |
commit | 17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch) | |
tree | b5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Loader/LoaderExtensions.cs | |
download | xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2 xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip |
Initial import
Diffstat (limited to 'Xamarin.Forms.Loader/LoaderExtensions.cs')
-rw-r--r-- | Xamarin.Forms.Loader/LoaderExtensions.cs | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/Xamarin.Forms.Loader/LoaderExtensions.cs b/Xamarin.Forms.Loader/LoaderExtensions.cs new file mode 100644 index 00000000..9c0b91fa --- /dev/null +++ b/Xamarin.Forms.Loader/LoaderExtensions.cs @@ -0,0 +1,126 @@ +using System; +using System.Linq; +using System.Reflection; +using NUnit.Framework; +using Xamarin.Forms.CustomAttributes; + +namespace Xamarin.Forms.Loader +{ + internal static class LoaderExtensions + { + public static bool InheritsFromException(this Type type) + { + if (type.IsSubclassOf(typeof (Exception))) + return true; + return false; + } + + public static bool InheritsFromAttribute(this Type type) + { + if (type.IsSubclassOf(typeof (Attribute))) + return true; + return false; + } + + public static bool IsDelegate(this Type type) + { + // ignore delegates + if (type.BaseType == typeof (MulticastDelegate)) + return true; + return false; + } + + public static bool IsTestFixture(this Type type) + { + var attributes = type.GetCustomAttributes(); + if (attributes.OfType<TestFixtureAttribute>().Any()) + return true; + return false; + } + + public static bool HasTestAttribute(this MemberInfo memberInfo) + { + var attributes = memberInfo.GetCustomAttributes(); + return attributes.Any(attr => attr is UiTestAttribute); + } + + public static bool IsUnitTested(Type type, MemberInfo memberInfo) + { + if (ExemptMembers.UnitTestedTypes.ContainsKey(type)) + { + if (ExemptMembers.UnitTestedTypes[type].Contains(memberInfo.Name)) + return true; + } + return false; + } + + public static bool HasTestExemptAttribute(this MemberInfo memberInfo) + { + var attributes = memberInfo.GetCustomAttributes(); + return attributes.Any(attr => attr is UiTestExemptAttribute); + } + + public static bool IsSetupOrTearDown(this MemberInfo memberInfo) + { + var attributes = memberInfo.GetCustomAttributes(); + return + attributes.Any( + attr => + attr is SetUpAttribute || attr is TearDownAttribute || attr is TestFixtureSetUpAttribute || + attr is TestFixtureTearDownAttribute); + } + + public static bool IsEqualityOverride(this MemberInfo memberInfo) + { + return + memberInfo.Name == "Equals" || + memberInfo.Name == "GetHashCode" || + memberInfo.Name == "GetType"; + } + + public static bool IsToStringOverride(this MemberInfo memberInfo) + { + return memberInfo.Name == "ToString"; + } + + public static bool HasCategoryAttribute(this Type type) + { + var attributes = type.GetCustomAttributes(); + if (attributes.OfType<CategoryAttribute>().Any()) + return true; + //throw new MissingCategoryOnTestFixtureException (type.Name); + return false; + } + + public static bool IsPublic(this MemberInfo memberInfo) + { + var type = memberInfo as Type; + if (type != null) + return type.IsPublic; + + var method = memberInfo as MethodInfo; + if (method != null) + return method.IsPublic; + + var property = memberInfo as PropertyInfo; + if (property != null) + return true; // binding flags determine public + + var evt = memberInfo as EventInfo; + if (evt != null) + return true; // binding flags determine public + + throw new LoaderException(); + } + + public static bool IsCompilerGenerated(this MemberInfo memberInfo) + { + // ignore autogenerated get_ and set_ methods + var method = memberInfo as MethodInfo; + if (method != null && method.IsSpecialName) + return true; + + return false; + } + } +}
\ No newline at end of file |