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))
{
...
}
}
以是代码报属性当此处被当做“类型”来使用的错误,请问我要如何实际上面代码的功能

解决方案 »

  1.   

    new A().MethodA<typeof(typeA)>(Convert.ChangeType(PrimaryKeyValue, PrimaryKeyType))这是什么东东?写在方法体外?
      

  2.   

    泛型方法在具体调用的时候不是需要一个类型嘛,我就在class B中定义了一个类型属性,用于调用泛型方法时的具体类型。但这样通不过遍译。
      

  3.   

    你想在哪调用,在哪指定这个T啊。public class B
    {
        public void Foo()
        {
            A a = new A();
            a.MethodA<string>();
        }
    }
      

  4.   


    不好意思,写错了,在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()
      

  5.   

    你这样要么按ls说的,用反射调用。要么在Class B上加上泛型Class B<T>