Tag:

C#。 使用reflection设置成员对象值

我需要您的帮助,以下代码。 基本上我有一个名为“Job”的类,它有一些公共字段。 我传递给我的方法“ApplyFilter”两个参数“job_in”和“job_filters”。 第一个参数包含实际数据,第二个参数包含指令(如果有)。 我需要遍历“job_in”对象,读取它的数据,通过读取“job_filters”来应用任何指令,修改数据(如果需要)并将其返回到新的“job_out”对象中。 一切正常,直到我需要将我的数据存储在“job_out”对象中: public class Job { public string job_id = “”; public string description = “”; public string address = “”; public string details = “”; } … private Job ApplyFilters(Job job_in, Job job_filters) { Type type = typeof(Job); Job job_out = new Job(); FieldInfo[] fields = type.GetFields(); // iterate through […]

可访问性不一致:字段类型“world”比字段“frmSplashScreen”更难访问

我有一个名为Inconsistent accessibility的错误: 字段类型’world’比字段’frmSplashScreen’更难访问 在我的代码中有一个名为frmSplashScreen的公共部分类 还有一个叫做world的公共课 导致错误的行是: private world currentWorld; 上面的行是在frmSplashScreen类中 是什么导致了这个问题?

通过传递名称来获取和设置字段值

我在类中有一个字段,其随机名称如下: class Foo { public string a2de = “e2” } 我在另一个变量中有这个字段的名称,如: string vari = “a2de” 我可以使用a2de的值来获取或设置字段a2de的值吗? 喜欢: getvar(vari) 要么 setvar(vari) = “e3”