private void InitProcedureSet() { var properties = this.GetType().GetProperties().Where(t => t.PropertyType.FullName.StartsWith("EntityFrameworkCore.Procedure.ProcedureSet") && t.PropertyType.IsPublic && t.CanWrite && t.CanWrite); foreach (var item in properties) { Type propType = item.PropertyType; try { string tempName = item.Name; string tempSchema = "dbo"; ProcedureAttribute attribute = item.GetCustomAttributes(typeof(ProcedureAttribute), false).FirstOrDefault() as ProcedureAttribute; if (attribute != null) { tempName = attribute.Name; tempSchema = attribute.Schema ?? tempSchema; } item.SetValue(this, Activator.CreateInstance(propType, _context, tempName, tempSchema)); } catch (Exception ex) { throw; } } }
/// <summary> /// Generates a method used for calling the database procedures. /// </summary> /// <param name="methodInfo">The method information</param> /// <param name="classFields">The fields this method has access to</param> /// <param name="typeBuilder">A type builder used for generating the method</param> /// <returns>A builder representing the method</returns> public MethodBuilder GenerateMethod(MethodInfo methodInfo, FieldInfo[] classFields, TypeBuilder typeBuilder) { ProcedureAttribute procedureAttribute = methodInfo.GetCustomAttribute <ProcedureAttribute>(); MethodBuilder methodBuilder = typeBuilder.DefineMethod(methodInfo.Name, MethodAttributes.Public | MethodAttributes.Virtual, methodInfo.ReturnType, GetParameterTypes(methodInfo.GetParameters())); GenerateMethodBody(procedureAttribute.ProcedureName, methodInfo.GetParameters(), methodBuilder.ReturnType, procedureAttribute.ProcedureType, classFields, methodBuilder.GetILGenerator()); return(methodBuilder); }