public static bool Is(this Type t1, Type t2, TypeFilterConstraints constraint) { switch (constraint) { case TypeFilterConstraints.Default: return(t2.GetTypeInfo().IsAssignableFrom(t1.GetTypeInfo())); case TypeFilterConstraints.Strict: return(t1 == t2); case TypeFilterConstraints.Derived: return(t1 != t2 && t2.GetTypeInfo().IsAssignableFrom(t1.GetTypeInfo())); default: throw new ArgumentOutOfRangeException(nameof(constraint), constraint, null); } }
public static bool Is(this object o, Type t, TypeFilterConstraints constraint) { switch (constraint) { case TypeFilterConstraints.Default: return(o.GetType().IsInstanceOfType(t)); case TypeFilterConstraints.Strict: return(o.GetType() == t); case TypeFilterConstraints.Derived: return(o.GetType() != t && o.IsInstanceOfType(t)); default: throw new ArgumentOutOfRangeException(nameof(constraint), constraint, null); } }
public static bool Is <T>(this object o, TypeFilterConstraints constraint) { switch (constraint) { case TypeFilterConstraints.Default: return(o is T); case TypeFilterConstraints.Strict: return(o.GetType() == typeof(T)); case TypeFilterConstraints.Derived: return(!(o is T) && o.GetType() == typeof(T)); default: throw new ArgumentOutOfRangeException(nameof(constraint), constraint, null); } }
public static bool TypeMatch(this IEnumerable <Type> types, Type type, TypeFilterConstraints constraint) { return(types.Any(t => type.Is(t, constraint))); }
public static IEnumerable <TResult> OfType <TResult>(this IEnumerable source, TypeFilterConstraints constraint) { if (source == null) { throw new NullReferenceException(nameof(source)); } switch (constraint) { case TypeFilterConstraints.Default: return(source.OfType <TResult>()); case TypeFilterConstraints.Strict: return(OfTypeStrictIterator <TResult>(source)); case TypeFilterConstraints.Derived: return(OfTypeDerivedIterator <TResult>(source)); default: throw new ArgumentOutOfRangeException(nameof(constraint), constraint, null); } }