1
This commit is contained in:
19
EquipMgr/Tnb.EquipMgr.Entities/Dto/MaintainPlanCrInput.cs
Normal file
19
EquipMgr/Tnb.EquipMgr.Entities/Dto/MaintainPlanCrInput.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tnb.EquipMgr.Entities.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// 生成保养计划输入参数
|
||||
/// </summary>
|
||||
public class MaintainPlanCrInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 规则id
|
||||
/// </summary>
|
||||
public string rule_id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -23,5 +23,15 @@ namespace Tnb.EquipMgr.Entities.Dto
|
||||
/// 模具名称
|
||||
/// </summary>
|
||||
public string mold_name { get; set; }
|
||||
/// <summary>
|
||||
/// 项目组Id
|
||||
/// </summary>
|
||||
public string item_group_id { get; set; }
|
||||
/// <summary>
|
||||
/// 项目名称
|
||||
/// </summary>
|
||||
public string item_group_name { get; set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tnb.EquipMgr.Entities.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// 模具规则选择列表输出类
|
||||
/// </summary>
|
||||
public class MoldRuleSelectorListOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 模具Id
|
||||
/// </summary>
|
||||
public string mold_id { get; set; }
|
||||
/// <summary>
|
||||
/// 模具编号
|
||||
/// </summary>
|
||||
public string mold_code { get; set; }
|
||||
/// <summary>
|
||||
/// 模具名称
|
||||
/// </summary>
|
||||
public string mold_name { get; set; }
|
||||
/// <summary>
|
||||
/// 项目组列表
|
||||
/// </summary>
|
||||
public List<MaintainItemGroupItem> groupItems { get; set; }
|
||||
}
|
||||
|
||||
public class MaintainItemGroupItem
|
||||
{
|
||||
/// <summary>
|
||||
/// 保养项目组Id
|
||||
/// </summary>
|
||||
public string item_group_id { get; set; }
|
||||
public string name { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,33 @@ namespace Tnb.EquipMgr.Entities.Dto
|
||||
/// <summary>
|
||||
/// 模具规则定义,关键模具输入参数
|
||||
/// </summary>
|
||||
public class RelevanceMoldInput : BaseMoldMaintainInput
|
||||
public class RelevanceMoldInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 规则Id
|
||||
/// </summary>
|
||||
public string? rule_id { get; set; }
|
||||
public string rule_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 行id 包含模具id,项目组Id
|
||||
/// </summary>
|
||||
public List<RowIdItem> rowIds { get; set; }
|
||||
/// <summary>
|
||||
/// 模具Ids
|
||||
/// </summary>
|
||||
public List<string> ids { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class RowIdItem
|
||||
{
|
||||
/// <summary>
|
||||
/// 模具id
|
||||
/// </summary>
|
||||
public string mold_id { get; set; }
|
||||
/// <summary>
|
||||
/// 项目组id
|
||||
/// </summary>
|
||||
public string group_id { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tnb.EquipMgr.Entities
|
||||
{
|
||||
using global::Tnb.Common.Contracts;
|
||||
using JNPF.Common.Contracts;
|
||||
using JNPF.Common.Security;
|
||||
using SqlSugar;
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarTable("tool_mold_maintain_plan")]
|
||||
public partial class ToolMoldMaintainPlan : BaseEntity<string>
|
||||
{
|
||||
public ToolMoldMaintainPlan()
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId();
|
||||
}
|
||||
/// <summary>
|
||||
/// 计划单号
|
||||
/// </summary>
|
||||
public string? plan_code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 保养方式
|
||||
/// </summary>
|
||||
public string? mode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 计划状态
|
||||
/// </summary>
|
||||
public string? status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 计划开始时间
|
||||
/// </summary>
|
||||
public DateTime? plan_start_date { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 计划完成时间
|
||||
/// </summary>
|
||||
public DateTime? plan_end_date { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string? remark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 制定人
|
||||
/// </summary>
|
||||
public string? create_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 制定时间
|
||||
/// </summary>
|
||||
public DateTime? create_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改人
|
||||
/// </summary>
|
||||
public string? modify_id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修改时间
|
||||
/// </summary>
|
||||
public DateTime? modify_time { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JNPF.Common.Security;
|
||||
using SqlSugar;
|
||||
using Tnb.Common.Contracts;
|
||||
|
||||
namespace Tnb.EquipMgr.Entities
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarTable("tool_mold_maintain_plan_relation")]
|
||||
public partial class ToolMoldMaintainPlanRelation : BaseEntity<string>
|
||||
{
|
||||
public ToolMoldMaintainPlanRelation()
|
||||
{
|
||||
id = SnowflakeIdHelper.NextId();
|
||||
}
|
||||
/// <summary>
|
||||
/// 保养计划id
|
||||
/// </summary>
|
||||
public string maintain_plan_id { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 模具Id
|
||||
/// </summary>
|
||||
public string mold_id { get; set; } = string.Empty;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,21 +11,25 @@ namespace Tnb.EquipMgr.Entities
|
||||
///模具保养规则与模具关联
|
||||
///</summary>
|
||||
[SugarTable("tool_mold_maintain_rule_relation")]
|
||||
public partial class ToolMoldMaintainRuleRelation:BaseEntity<string>
|
||||
public partial class ToolMoldMaintainRuleRelation : BaseEntity<string>
|
||||
{
|
||||
/// <summary>
|
||||
/// Desc:保养规则id
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string rule_id {get;set;} = string.Empty;
|
||||
/// <summary>
|
||||
/// Desc:保养规则id
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string rule_id { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Desc:模具id
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string mold_id {get;set;} = string.Empty;
|
||||
/// <summary>
|
||||
/// Desc:模具id
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public string mold_id { get; set; } = string.Empty;
|
||||
/// <summary>
|
||||
/// 项目组id
|
||||
/// </summary>
|
||||
public string item_group_id { get; set; } = string.Empty;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Tnb.EquipMgr.Interfaces
|
||||
{
|
||||
public interface IToolMoldMaintainPlanService
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ using Tnb.EquipMgr.Entities.Dto;
|
||||
using Tnb.EquipMgr.Entities;
|
||||
using Tnb.EquipMgr.Utils;
|
||||
using Mapster;
|
||||
using Tnb.Common.Extension;
|
||||
|
||||
namespace Tnb.EquipMgr
|
||||
{
|
||||
@@ -47,18 +48,8 @@ namespace Tnb.EquipMgr
|
||||
var pk = id;
|
||||
TDest entity = new();
|
||||
entity.id = SnowflakeIdHelper.NextId();
|
||||
if (!PropertySet<TDest>.ValueFactories.TryGetValue(mColumnName, out Action<object, object>? setGroupIdAction))
|
||||
{
|
||||
setGroupIdAction = PropertySet<TDest>.CreateSetPropertyValueAction(mColumnName);
|
||||
PropertySet<TDest>.ValueFactories.Add(mColumnName, setGroupIdAction);
|
||||
}
|
||||
setGroupIdAction(entity, input.item_group_id);
|
||||
if (!PropertySet<TDest>.ValueFactories.TryGetValue(name, out Action<object, object>? setAction))
|
||||
{
|
||||
setAction = PropertySet<TDest>.CreateSetPropertyValueAction(name);
|
||||
PropertySet<TDest>.ValueFactories.Add(name, setAction);
|
||||
}
|
||||
setAction(entity, pk);
|
||||
entity.PropertySetValue<TDest>(mColumnName, input.item_group_id);
|
||||
entity.PropertySetValue<TDest>(name,pk);
|
||||
entities.Add(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\BasicData\Tnb.BasicData.Interfaces\Tnb.BasicData.Interfaces.csproj" />
|
||||
<ProjectReference Include="..\..\visualdev\Tnb.VisualDev.Engine\Tnb.VisualDev.Engine.csproj" />
|
||||
<ProjectReference Include="..\Tnb.EquipMgr.Interfaces\Tnb.EquipMgr.Interfaces.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
59
EquipMgr/Tnb.EquipMgr/ToolMoldMaintainPlanService.cs
Normal file
59
EquipMgr/Tnb.EquipMgr/ToolMoldMaintainPlanService.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Aspose.Cells.Drawing;
|
||||
using JNPF.Common.Dtos.VisualDev;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
using JNPF.Logging;
|
||||
using JNPF.VisualDev;
|
||||
using JNPF.VisualDev.Entitys;
|
||||
using JNPF.VisualDev.Interfaces;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
using Tnb.BasicData;
|
||||
using Tnb.EquipMgr.Entities;
|
||||
using Tnb.EquipMgr.Interfaces;
|
||||
|
||||
namespace Tnb.EquipMgr
|
||||
{
|
||||
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
||||
[Route("api/[area]/[controller]/[action]")]
|
||||
[OverideVisualDev(ModuleId)]
|
||||
public class ToolMoldMaintainPlanService : IOverideVisualDevService, IToolMoldMaintainPlanService, IDynamicApiController, ITransient
|
||||
{
|
||||
private const string ModuleId = "26165768858389";
|
||||
private readonly ISqlSugarClient _db;
|
||||
private readonly IRunService _runService;
|
||||
private readonly IVisualDevService _visualDevService;
|
||||
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
||||
public ToolMoldMaintainPlanService(ISqlSugarRepository<ToolMoldMaintainPlan> repository, IRunService runService, IVisualDevService visualDevService)
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
_runService = runService;
|
||||
_visualDevService = visualDevService;
|
||||
OverideFuncs.CreateAsync = Create;
|
||||
|
||||
}
|
||||
|
||||
private async Task<dynamic> Create(VisualDevModelDataCrInput visualDevModelDataCrInput)
|
||||
{
|
||||
try
|
||||
{
|
||||
visualDevModelDataCrInput.data[nameof(ToolMoldMaintainPlan.plan_code)] = $"JHDM{DateTime.Now:yyyyMMddmmss}";
|
||||
visualDevModelDataCrInput.data[nameof(ToolMoldMaintainPlan.status)] = DictConst.UnMaintainStatusCode;
|
||||
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
|
||||
await _runService.Create(templateEntity, visualDevModelDataCrInput);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("新增时出错", ex);
|
||||
}
|
||||
return await Task.FromResult("ok");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,17 +3,23 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Aop.Api.Domain;
|
||||
using Aspose.Cells.Drawing;
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Enums;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
using JNPF.FriendlyException;
|
||||
using JNPF.Logging;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using SqlSugar;
|
||||
using Tnb.BasicData;
|
||||
using Tnb.EquipMgr.Entities;
|
||||
using Tnb.EquipMgr.Entities.Dto;
|
||||
using Tnb.EquipMgr.Entities.Entity;
|
||||
using Tnb.EquipMgr.Interfaces;
|
||||
|
||||
namespace Tnb.EquipMgr
|
||||
@@ -23,12 +29,14 @@ namespace Tnb.EquipMgr
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
||||
[Route("api/[area]/[controller]/[action]")]
|
||||
public class ToolMoldMaintainRuleService : BaseMoldMaintainService, IToolMoldMaintainRuleService, IDynamicApiController, ITransient
|
||||
public class ToolMoldMaintainRuleService : IToolMoldMaintainRuleService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly ISqlSugarClient _db;
|
||||
public ToolMoldMaintainRuleService(ISqlSugarRepository<ToolMoldMaintainRule> repository) : base(repository.AsSugarClient())
|
||||
private readonly IUserManager _userManager;
|
||||
public ToolMoldMaintainRuleService(ISqlSugarRepository<ToolMoldMaintainRule> repository, IUserManager userManager)
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
_userManager = userManager;
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据规则Id获取匹配的模具列表
|
||||
@@ -44,10 +52,33 @@ namespace Tnb.EquipMgr
|
||||
{
|
||||
var ids = list.Select(it => it.mold_id).ToList();
|
||||
result = await _db.Queryable<ToolMolds>().Where(it => ids.Contains(it.id))
|
||||
.Select(it => new MaintainRuleMoldListOutput { mold_id = it.id }, true).ToListAsync();
|
||||
.Select(it => new MaintainRuleMoldListOutput { mold_id = it.id, item_group_id = list.First().item_group_id }, true)
|
||||
.Mapper
|
||||
(
|
||||
it => it.item_group_name = _db.Queryable<ToolMoldMaintainGroup>().First(x => x.id == list.First().item_group_id).name!
|
||||
)
|
||||
.ToListAsync();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取模具选择列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<dynamic> GetMoldRuleSelectorList()
|
||||
{
|
||||
return await _db.Queryable<ToolMolds>().Select(it => new MoldRuleSelectorListOutput
|
||||
{
|
||||
mold_id = it.id,
|
||||
}, true)
|
||||
.Mapper(it =>
|
||||
{
|
||||
var itemGroupIds = _db.Queryable<ToolMoldMaintainGroupRelation>().Where(x => x.mold_id == it.mold_id).Select(x => x.item_group_id).Distinct().ToList();
|
||||
it.groupItems = _db.Queryable<ToolMoldMaintainGroup>().Where(x => itemGroupIds.Contains(x.id)).Select(x => new MaintainItemGroupItem { item_group_id = x.id, name = x.name }).ToList();
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关联模具
|
||||
@@ -56,8 +87,26 @@ namespace Tnb.EquipMgr
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
[HttpPost]
|
||||
public async Task RelevanceMold(RelevanceMoldInput input) =>
|
||||
await Relevance<RelevanceMoldInput, ToolMoldMaintainRuleRelation>(input, nameof(ToolMoldMaintainRuleRelation.rule_id), nameof(ToolMoldMaintainRuleRelation.mold_id), it => it.rule_id == input.rule_id);
|
||||
public async Task RelevanceMold(RelevanceMoldInput input)
|
||||
{
|
||||
if (input == null) throw new ArgumentNullException(nameof(input));
|
||||
if (input.rowIds?.Count > 0)
|
||||
{
|
||||
List<ToolMoldMaintainRuleRelation> entities = new();
|
||||
foreach (var item in input.rowIds)
|
||||
{
|
||||
ToolMoldMaintainRuleRelation entity = new();
|
||||
entity.id = SnowflakeIdHelper.NextId();
|
||||
entity.rule_id = input.rule_id;
|
||||
entity.mold_id = item.mold_id;
|
||||
entity.item_group_id = item.group_id;
|
||||
|
||||
entities.Add(entity);
|
||||
}
|
||||
var row = await _db.Insertable(entities).ExecuteCommandAsync();
|
||||
if (row < 1) throw Oops.Oh(ErrorCode.COM1000);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除模具信息
|
||||
/// </summary>
|
||||
@@ -66,8 +115,56 @@ namespace Tnb.EquipMgr
|
||||
[HttpPost]
|
||||
public async Task DeleteMoldRelevance(RelevanceMoldInput input)
|
||||
{
|
||||
var row = await _db.Deleteable<ToolMoldMaintainRuleRelation>().Where(it => it.rule_id == input.rule_id && input.ids.Contains(it.mold_id)).ExecuteCommandAsync();
|
||||
if (row < 1) throw Oops.Oh(ErrorCode.COM1002);
|
||||
if (input.ids?.Count > 0)
|
||||
{
|
||||
var row = await _db.Deleteable<ToolMoldMaintainRuleRelation>().Where(it => it.rule_id == input.rule_id && input.ids.Contains(it.mold_id)).ExecuteCommandAsync();
|
||||
if (row < 1) throw Oops.Oh(ErrorCode.COM1002);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 生成模具保养计划
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task GenMaintainPlan(MaintainPlanCrInput input)
|
||||
{
|
||||
if (input == null) throw new ArgumentNullException("input");
|
||||
|
||||
try
|
||||
{
|
||||
await _db.Ado.BeginTranAsync();
|
||||
|
||||
var maintainRule = await _db.Queryable<ToolMoldMaintainRule>().FirstAsync(it => it.id == input.rule_id);
|
||||
if (maintainRule is not null)
|
||||
{
|
||||
if (maintainRule.cycle.HasValue && maintainRule.cycle.Value > 0)
|
||||
{
|
||||
ToolMoldMaintainPlan maintainPlan = new();
|
||||
maintainPlan.plan_code = $"JHDM{DateTime.Now:yyyyMMddmmss}";
|
||||
maintainPlan.mode = maintainRule.mode;
|
||||
maintainPlan.status = DictConst.UnMaintainStatusCode;
|
||||
maintainPlan.plan_start_date = DateTime.Now;
|
||||
maintainPlan.plan_end_date = DateTime.Now.AddDays(maintainRule.cycle.Value);
|
||||
maintainPlan.create_id = _userManager.UserId;
|
||||
maintainPlan.create_time = DateTime.Now;
|
||||
|
||||
await _db.Insertable(maintainPlan).ExecuteCommandAsync();
|
||||
|
||||
ToolMoldMaintainPlanRelation maintainPlanReation = new();
|
||||
maintainPlanReation.maintain_plan_id = maintainPlan.id;
|
||||
maintainPlanReation.mold_id = (await _db.Queryable<ToolMoldMaintainRuleRelation>().FirstAsync(it => it.rule_id == maintainRule.id))?.mold_id!;
|
||||
|
||||
await _db.Insertable(maintainPlanReation).ExecuteCommandAsync();
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("生成保养计划失败", ex);
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
|
||||
namespace Tnb.EquipMgr.Utils
|
||||
{
|
||||
public class PropertySet<T>
|
||||
{
|
||||
public static Dictionary<string, Action<object, object>> ValueFactories = new Dictionary<string, Action<object, object>>(StringComparer.OrdinalIgnoreCase);
|
||||
//public class PropertySet<T>
|
||||
//{
|
||||
// public static Dictionary<string, Action<object, object>> ValueFactories = new Dictionary<string, Action<object, object>>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public static Action<object, object> CreateSetPropertyValueAction(string propertyName)
|
||||
{
|
||||
var property = typeof(T).GetProperty(propertyName);
|
||||
var target = Expression.Parameter(typeof(object));
|
||||
var propertyValue = Expression.Parameter(typeof(object));
|
||||
var castTarget = Expression.Convert(target, typeof(T));
|
||||
var castPropertyValue = Expression.Convert(propertyValue, property!.PropertyType);
|
||||
var setPropertyValue = Expression.Call(castTarget, property.GetSetMethod()!, castPropertyValue);
|
||||
return Expression.Lambda<Action<object, object>>(setPropertyValue, target, propertyValue).Compile();
|
||||
}
|
||||
// public static Action<object, object> CreateSetPropertyValueAction(string propertyName)
|
||||
// {
|
||||
// var property = typeof(T).GetProperty(propertyName);
|
||||
// var target = Expression.Parameter(typeof(object));
|
||||
// var propertyValue = Expression.Parameter(typeof(object));
|
||||
// var castTarget = Expression.Convert(target, typeof(T));
|
||||
// var castPropertyValue = Expression.Convert(propertyValue, property!.PropertyType);
|
||||
// var setPropertyValue = Expression.Call(castTarget, property.GetSetMethod()!, castPropertyValue);
|
||||
// return Expression.Lambda<Action<object, object>>(setPropertyValue, target, propertyValue).Compile();
|
||||
// }
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user