public static bool IsValidationRegistration(Type type) { // TODO -- No open generics return type.IsConcreteTypeOf<IValidationRegistration>() && type.IsConcreteWithDefaultCtor() && !type.IsOpenGeneric(); }
private Type GetLeastSpecificButValidType(Type pluginType, Type type) { if (pluginType.IsGenericTypeDefinition && !type.IsOpenGeneric()) return type.FindFirstInterfaceThatCloses(pluginType); return pluginType; }
public Writer(Type writerType, Type resourceType = null) { if (writerType == null) { throw new ArgumentNullException("writerType"); } if (writerType.IsOpenGeneric()) { if (resourceType == null) { throw new ArgumentNullException("resourceType", "resourceType is required if the writerType is an open generic"); } _resourceType = resourceType; _writerType = writerType.MakeGenericType(resourceType); } else { var @interface = writerType.FindInterfaceThatCloses(typeof (IMediaWriter<>)); if (@interface == null) { throw new ArgumentOutOfRangeException("writerType", "writerType must be assignable to IMediaWriter<>"); } _writerType = writerType; _resourceType = @interface.GetGenericArguments().First(); } }
public OpenGenericRegistration(Type type) { if (!type.IsOpenGeneric()) throw new ArgumentException("A generic type must be specified", "type"); _genericType = type.GetGenericTypeDefinition(); _arguments = type.GetGenericArguments(); }
public GenericConnectionScanner(Type openType) { _openType = openType; if (!_openType.IsOpenGeneric()) { throw new ApplicationException("This scanning convention can only be used with open generic types"); } }
public static bool IsLoaderTypeCandidate(Type type) { if (type.IsOpenGeneric()) return false; if (!type.IsConcreteWithDefaultCtor()) return false; if (type.CanBeCastTo<FubuRegistry>()) return true; return type.CanBeCastTo<IApplicationLoader>(); }
public static bool IsWebFormView(Type type) { return type != typeof(FubuPage) && !type.IsOpenGeneric() && type.CanBeCastTo<Page>() && type.CanBeCastTo<IFubuPage>(); }
public static IEnumerable<Type> GetClosingArguments(this Type type, Type openType) { if (type == null) throw new ArgumentNullException(nameof(type)); if (openType == null) throw new ArgumentNullException(nameof(openType)); if (!openType.IsOpenGeneric()) throw new ArgumentException("The interface type must be an open generic interface: " + openType.Name); if (openType.GetTypeInfo().IsInterface) { if (!openType.IsOpenGeneric()) throw new ArgumentException("The interface type must be an open generic interface: " + openType.Name); var interfaceType = type.GetInterface(openType); if (interfaceType == null) throw new ArgumentException("The interface type is not implemented by: " + type.Name); return interfaceType.GetTypeInfo().GetGenericArguments().Where(x => !x.IsGenericParameter); } var baseType = type; while (baseType != null && baseType != typeof(object)) { var baseTypeInfo = baseType.GetTypeInfo(); if (baseTypeInfo.IsGenericType && baseType.GetGenericTypeDefinition() == openType) return baseTypeInfo.GetGenericArguments().Where(x => !x.IsGenericParameter); if (!baseTypeInfo.IsGenericType && baseType == openType) return baseTypeInfo.GetGenericArguments().Where(x => !x.IsGenericParameter); baseType = baseTypeInfo.BaseType; } throw new ArgumentException("Could not find open type in type: " + type.Name); }
/// <summary> /// Determines if the pluggedType can be upcast to the pluginType /// </summary> /// <param name="pluginType"></param> /// <param name="pluggedType"></param> /// <returns></returns> public static bool CanBeCastTo(this Type pluggedType, Type pluginType) { if (pluggedType == null) return false; if (pluggedType.IsInterface || pluggedType.IsAbstract) { return false; } if (pluginType.IsOpenGeneric()) { return GenericCanBeCast(pluginType, pluggedType); } if (IsOpenGeneric(pluggedType)) { return false; } return pluginType.IsAssignableFrom(pluggedType); }
public static bool IsSystemTypeCandidate(Type type) { return type.CanBeCastTo<ISystem>() && type.IsConcreteWithDefaultCtor() && !type.IsOpenGeneric(); }
public static bool IsFixtureType(Type type) { if (!type.CanBeCastTo<Fixture>()) return false; if (type.HasAttribute<HiddenAttribute>()) return false; if (!type.IsConcreteWithDefaultCtor()) return false; if (type.IsOpenGeneric()) return false; return true; }