private void CreateLogicByType(LogicManagerBase <TContext> logicManager, Type type) { if (!Maps.ContainsKey(type)) { throw new NotSupportedException($"Not support type {type.Name}"); } //建構組件 AssemblyBuilder tempAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName() { Name = "TempAssembly_" + Guid.NewGuid().ToString().Replace('-', '_') }, AssemblyBuilderAccess.RunAndCollect); //建構模組 ModuleBuilder tempModuleBuilder = tempAssemblyBuilder .DefineDynamicModule("TempModule_" + Guid.NewGuid().ToString().Replace('-', '_')); var logicType = typeof(LogicBase <, ,>).MakeGenericType(typeof(TContext), type, type.GetProperty(Maps[type]).PropertyType); //建構實作介面類別 TypeBuilder tempTypeBuilder = tempModuleBuilder.DefineType( $"Anon_{Guid.NewGuid().ToString().Replace("-", "_")}", TypeAttributes.Class, logicType, Type.EmptyTypes); CreatePassThroughConstructors(tempTypeBuilder, logicType); var tempType = tempTypeBuilder.CreateTypeInfo(); var ctor = tempType.GetConstructors().Single(x => x.GetParameters().Length > 1 && x.GetParameters()[1].ParameterType == typeof(string)); runtimeLogicMaps[type] = ctor.Invoke(new object[] { logicManager, Maps[type] }); }
/// <summary> /// 基礎邏輯操作器基礎建構子 /// </summary> /// <param name="logicManager">資料庫操作邏輯管理器實例</param> /// <param name="identityPropertyName">唯一識別號屬性選擇器</param> public LogicBase(LogicManagerBase <TContext> logicManager, string identityPropertyName) { this.Manager = logicManager; var idProperties = typeof(TEntity).GetProperties().Where(x => x.PropertyType == typeof(TId)); if (idProperties.Count() == 0) { throw new InvalidOperationException("在指定類型中找不到指定的主鍵類型"); } var idProperty = idProperties.FirstOrDefault(x => x.Name.ToLower() == identityPropertyName); if (idProperty == null) { idProperty = idProperties.FirstOrDefault(x => x.Name.ToLower() == (typeof(TEntity).Name + identityPropertyName).ToLower()); } if (idProperty == null && idProperties.Count() == 1) { idProperty = idProperties.First(); } if (idProperties == null) { throw new InvalidOperationException("在指定類型中找不到名稱為Id的屬性作為預設主鍵"); } this.IdentityPropertyName = identityPropertyName; }
/// <summary> /// 取得或建立指定型別的Logic /// </summary> /// <param name="logicManager">邏輯管理器</param> /// <param name="type">型別</param> /// <returns>指定型別的Logic實例</returns> public object GetLogicByType(LogicManagerBase <TContext> logicManager, Type type) { if (!runtimeLogicMaps.ContainsKey(type)) { CreateLogicByType(logicManager, type); } return(runtimeLogicMaps[type]); }
public DisableCascadeScope(LogicManagerBase <TContext> manager) : base(manager) { }
/// <summary> /// 基礎邏輯操作器基礎建構子 /// </summary> /// <param name="logicManager">資料庫操作邏輯管理器實例</param> /// <param name="identitySelector">唯一識別號屬性選擇器</param> public LogicBase(LogicManagerBase <TContext, object[]> logicManager, Expression <Func <TEntity, TId> > identitySelector) : base(logicManager, identitySelector) { }
/// <summary> /// 基礎邏輯操作器基礎建構子 /// </summary> /// <param name="logicManager">資料庫操作邏輯管理器實例</param> /// <param name="identityPropertyName">唯一識別號屬性選擇器</param> public LogicBase(LogicManagerBase <TContext, object[]> logicManager, string identityPropertyName) : base(logicManager, identityPropertyName) { }
/// <summary> /// 基礎邏輯操作器基礎建構子,預設的主鍵為Id /// </summary> /// <param name="logicManager">資料庫操作邏輯管理器實例</param> public LogicBase(LogicManagerBase <TContext, object[]> logicManager) : base(logicManager, "Id") { }
/// <summary> /// 基礎邏輯操作器基礎建構子 /// </summary> /// <param name="logicManager">資料庫操作邏輯管理器實例</param> /// <param name="identitySelector">唯一識別號屬性選擇器</param> public LogicBase(LogicManagerBase <TContext> logicManager, Expression <Func <TEntity, TId> > identitySelector) { this.Manager = logicManager; this.IdentityPropertyName = (identitySelector.Body as MemberExpression).Member.Name; }
/// <summary> /// 基礎邏輯操作器基礎建構子,預設的主鍵為Id /// </summary> /// <param name="logicManager">資料庫操作邏輯管理器實例</param> public LogicBase(LogicManagerBase <TContext> logicManager) : this(logicManager, "Id") { }
public SafeRemoveCascadeScope( LogicManagerBase <TContext> manager, params Type[] types) : base(manager, types) { }