相关疑难解决方法(0)

C#反思:如何从字符串中获取类引用?

我想在C#中这样做,但我不知道如何:

我有一个类名为-eg的字符串:FooClass我想在这个类上调用(静态)方法:

FooClass.MyMethod();
Run Code Online (Sandbox Code Playgroud)

显然,我需要通过反思找到对类的引用,但是如何?

c# reflection

82
推荐指数
4
解决办法
13万
查看次数

读取方法属性的值

我需要能够从我的方法中读取我的属性的值,我该怎么做?

[MyAttribute("Hello World")]
public void MyMethod()
{
    // Need to read the MyAttribute attribute and get its value
}
Run Code Online (Sandbox Code Playgroud)

.net c# reflection methods attributes

60
推荐指数
3
解决办法
4万
查看次数

如何动态调用c#中的函数

我有方法:

  add(int x,int y)
Run Code Online (Sandbox Code Playgroud)

我也有:

int a=5;
int b=6;
string s="add";
Run Code Online (Sandbox Code Playgroud)

是否可以使用字符串s调用add(a,b)?我怎么能在c#中做到这一点?

c#

28
推荐指数
4
解决办法
5万
查看次数

字符串到变量名称

我有类(Customer),它包含200多个字符串变量作为属性.我正在使用带有键和值参数的方法.我试图从xml文件提供密钥和值.为此,必须使用Customer类的属性(字符串变量)替换值.

即

Customer
{
  public string Name{return _name};

  public string Address{return _address};
}


CallInput
{
  StringTempelate tempelate = new StringTempelate();
  foreach(item in items)
  tempelate .SetAttribure(item.key, item.Value -->   //Say this value is Name, so it has to substitute Customer.Name
}
Run Code Online (Sandbox Code Playgroud)

可能吗?

c#

15
推荐指数
3
解决办法
4万
查看次数

标签 统计

c# ×4

reflection ×2

.net ×1

attributes ×1

methods ×1