public void FindType1() { var typeFinder = new TypeFinder(); var type = typeFinder.FindType("NorthwindDemo.Product", new string[] { }); Assert.IsNotNull(type); }
public virtual DbMigrationsConfiguration FindMigrationsConfiguration( Type contextType, string configurationTypeName, Func <string, Exception> noType = null, Func <string, IEnumerable <Type>, Exception> multipleTypes = null, Func <string, string, Exception> noTypeWithName = null, Func <string, string, Exception> multipleTypesWithName = null) { TypeFinder typeFinder = this._typeFinder; Type baseType; if (!(contextType == (Type)null)) { baseType = typeof(DbMigrationsConfiguration <>).MakeGenericType(contextType); } else { baseType = typeof(DbMigrationsConfiguration); } string typeName = configurationTypeName; Func <IEnumerable <Type>, IEnumerable <Type> > filter = (Func <IEnumerable <Type>, IEnumerable <Type> >)(types => (IEnumerable <Type>)types.Where <Type>((Func <Type, bool>)(t => { if (t.GetPublicConstructor() != (ConstructorInfo)null && !t.IsAbstract()) { return(!t.IsGenericType()); } return(false); })).ToList <Type>()); Func <string, Exception> noType1 = noType; Func <string, IEnumerable <Type>, Exception> multipleTypes1 = multipleTypes; Func <string, string, Exception> noTypeWithName1 = noTypeWithName; Func <string, string, Exception> multipleTypesWithName1 = multipleTypesWithName; Type type = typeFinder.FindType(baseType, typeName, filter, noType1, multipleTypes1, noTypeWithName1, multipleTypesWithName1); try { return(type == (Type)null ? (DbMigrationsConfiguration)null : type.CreateInstance <DbMigrationsConfiguration>(new Func <string, string, string>(Strings.CreateInstance_BadMigrationsConfigurationType), (Func <string, Exception>)(s => (Exception) new MigrationsException(s)))); } catch (TargetInvocationException ex) { ExceptionDispatchInfo.Capture(ex.InnerException).Throw(); throw ex.InnerException; } }
public void FindType2() { var typeFinder = new TypeFinder(); EntitySqlException exc = null; try { typeFinder.FindType("Product", new string[] { }); } catch (EntitySqlException e) { exc = e; } Assert.IsNotNull(exc); AssertException(() => Res.AmbiguousTypeReference, exc); //type = typeFinder.FindType("Product"); }
public virtual DbMigrationsConfiguration FindMigrationsConfiguration( Type contextType, string configurationTypeName, Func <string, Exception> noType = null, Func <string, IEnumerable <Type>, Exception> multipleTypes = null, Func <string, string, Exception> noTypeWithName = null, Func <string, string, Exception> multipleTypesWithName = null) { var configurationType = _typeFinder.FindType( contextType == null ? typeof(DbMigrationsConfiguration) : typeof(DbMigrationsConfiguration <>).MakeGenericType(contextType), configurationTypeName, types => types .Where( t => t.GetConstructor(Type.EmptyTypes) != null && !t.IsAbstract && !t.IsGenericType) .ToList(), noType, multipleTypes, noTypeWithName, multipleTypesWithName); try { return(configurationType == null ? null : configurationType.CreateInstance <DbMigrationsConfiguration>( Strings.CreateInstance_BadMigrationsConfigurationType, s => new MigrationsException(s))); } catch (TargetInvocationException ex) { Debug.Assert(ex.InnerException != null); #if !NET40 ExceptionDispatchInfo.Capture(ex.InnerException).Throw(); #endif throw ex.InnerException; } }