我想在C#中这样做,但我不知道如何:
我有一个类名为-eg的字符串:FooClass我想在这个类上调用(静态)方法:
FooClass.MyMethod();
Run Code Online (Sandbox Code Playgroud)
显然,我需要通过反思找到对类的引用,但是如何?
我需要能够从我的方法中读取我的属性的值,我该怎么做?
[MyAttribute("Hello World")]
public void MyMethod()
{
// Need to read the MyAttribute attribute and get its value
}
Run Code Online (Sandbox Code Playgroud) 我有方法:
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#中做到这一点?
我有类(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)
可能吗?