public class A
{
public void MethodA<T>(T paramter)
{
....
}
}public class B
{
protected Type typeA
{
get;
set;
}protected string PrimaryKeyType
{
get;
set;
}
new A().MethodA<typeof(typeA)>(Convert.ChangeType(PrimaryKeyValue, PrimaryKeyType))
{
...
}
}
以是代码报属性当此处被当做“类型”来使用的错误,请问我要如何实际上面代码的功能
{
public void Foo()
{
A a = new A();
a.MethodA<string>();
}
}
不好意思,写错了,在Class B中应该有一个方法。public class B
{
public B(Type _type)
{
typeA=_type;
}protected Type typeA
{
get;
set;
}protected string PrimaryKeyType
{
get;
set;
}public void MethodB()
{
new A().MethodA<typeof(typeA)>(Convert.ChangeType(PrimaryKeyValue, PrimaryKeyType))
{
...
}
}
}在调用Class B后给typeA赋一个具体的类型。
然后再调用Class B中的MethodB()