0

我计划在我的项目中实现动态类。在针对输入列表执行 Where 条件时,我遇到了这个问题。

我有一个输入字典,我通过解析 jsondocument 存储我的所有数据并使用这些值来设置动态属性。

问题是,如果我通过解析 jsondocument 设置字典值,则不满足条件。相反,如果我将字典值设置为“男性”,那么它工作正常。

下面是我的代码片段。

Dictionary<string, object> inputList = new Dictionary<string, object>();
string EmployeeData = JsonDocument.Parse(EmployeeList).RootElement.GetProperty("gender).ToString();

inputList.Add("gender","Male") --> Working
inputList.Add("gender",EmployeeData) --> not working

List props = new List();

Type type = DynamicClassFactory.CreateType(props,true);

var obj = (DynamicClass) Activator.CreateInstance(type) ;

var typeProps = type.GetProperties().ToDictionary(c => c.Name);

foreach (var dict in inputList)
{
obj.SetDynamicPropertyValue(dict.Key,dict.Value);
}

Var LstOfRecords = new List();
LstOfRecords.Add(obj);
LstOfRecords.AsQueryable().Where("gender == "Male"");
4

0 回答 0