private TResult MaterializeStoredProcedureResult <TResult>(IDataReader reader) { Type tresult = typeof(TResult); if (!tresult.IsGenericType) { throw new InvalidOperationException(Resources.ResultMustBeGenericIEnumerable); } if (_nonGenericMaterializeMethod == null) { _nonGenericMaterializeMethod = _modelBuilder.GetType().GetMethod( nameof(IModelBuilder.Materialize), new Type[] { typeof(IDataReader) }); if (_nonGenericMaterializeMethod == null) { string modelBuilderType = _modelBuilder.GetType().FullName; const string methodName = nameof(IModelBuilder.Materialize); const string methodArg = nameof(IDataReader); throw new InvalidOperationException( string.Format(Resources.MissongMethodInModelBuilder, modelBuilderType, methodName, methodArg)); } } MethodInfo materializeMethod = _nonGenericMaterializeMethod.MakeGenericMethod(tresult.GenericTypeArguments[0]); return((TResult)materializeMethod.Invoke(_modelBuilder, new object[] { reader })); }
private TResult MaterializeStoredProcedureResult <TResult>(IDataReader reader) { Type tresult = typeof(TResult); if (!tresult.IsGenericType) { throw new InvalidOperationException("Result type must be generic: IEnumerable<T>"); } if (_nonGenericMaterializeMethod == null) { _nonGenericMaterializeMethod = _modelBuilder.GetType().GetMethod( nameof(IModelBuilder.Materialize), new Type[] { typeof(IDataReader) }); if (_nonGenericMaterializeMethod == null) { string modelBuilderType = _modelBuilder.GetType().FullName; string methodName = nameof(IModelBuilder.Materialize); throw new InvalidOperationException( $"ModelBuilder instance ({modelBuilderType}) does not have method {methodName}(IDataReader)."); } } MethodInfo materializeMethod = _nonGenericMaterializeMethod.MakeGenericMethod(tresult.GenericTypeArguments[0]); return((TResult)materializeMethod.Invoke(_modelBuilder, new object[] { reader })); }
/// <summary> /// /// </summary> /// <param name="root"></param> /// <returns></returns> private List <string> GetModelBuilderChildren(IModelBuilder root) { var innerBuilders = new List <string> { root.GetType().FullName }; var builder = GetInnerBuilder(root); do { innerBuilders.Add(builder.GetType().FullName); builder = GetInnerBuilder(builder); }while (builder != null); return(innerBuilders); }