gpt4 book ai didi

c# - 如何获取 expando 对象的值(value) #

转载 作者:太空狗 更新时间:2023-10-29 22:21:29 31 4
gpt4 key购买 nike

首先,我将 txt 文件读入一个文件夹,然后我使用 expando 对象对对象进行水化处理。

但现在我想从这个对象中获取一些值来填充 ListView (winforms)。

private void Form1_Load(object sender, EventArgs e)
{
string pattern = "FAC*.txt";
var directory = new DirectoryInfo(@"C:\\TestLoadFiles");
var myFile = (from f in directory.GetFiles(pattern)
orderby f.LastWriteTime descending
select f).First();

hydrate_object_from_metadata("FAC",listBox3);
hydrate_object_from_metadata("BL", listBox4);

this.listBox3.MouseDoubleClick += new MouseEventHandler(listBox3_MouseDoubleClick);
this.listBox1.MouseClick += new MouseEventHandler(listBox1_MouseClick);
}

void hydrate_object_from_metadata(string tag, ListBox listBox)
{
SearchAndPopulateTiers(@"C:\TestLoadFiles", tag + "*.txt", tag);
int count = typeDoc.Count(D => D.Key.StartsWith(tag));

for (int i = 0; i < count; i++)
{
object ob = GetObject(tag + i);
///HERE I WOULD LIKE GET DATA VALUE FROM ob object
}
}

Object GetObject(string foo)
{
if (typeDoc.ContainsKey(foo))
return typeDoc[foo];
return null;
}

void SearchAndPopulateTiers(string path, string extention, string tag)
{
DirectoryInfo di = new DirectoryInfo(path);
FileInfo[] files = di.GetFiles(extention);

int i = 0;
foreach (FileInfo file in files)
{
var x = new ExpandoObject() as IDictionary<string, Object>;

string[] strArray;
string s = "";

while ((s = sr.ReadLine()) != null)
{
strArray = s.Split('=');

x.Add(strArray[0],strArray[1]);

}

typeDoc.Add(tag+i,x);
i++;
}
}

那么是否有可能在 expando 对象上获取值?

最佳答案

dynamic eod = eo;

value = eod.Foo;

关于c# - 如何获取 expando 对象的值(value) #,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43546261/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com