在的GetType静态方法 [英] GetType in static method

查看:355
本文介绍了在的GetType静态方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/2081612/net-determine-the-type-of-this-class-in-its-static-method">.NET:判断这一类的类型在它的静态方法

我怎样才能让的GetType()静态方法进行访问?

How can I make GetType() accessible from a static method?

我有这个抽象基类

abstract class MyBase
{
   public static void MyMethod()
   {
      var myActualType = GetType(); // this is an instance method
      doSomethingWith(myActualType);
   }
}

和那类的实现。 (我可以有多种实现。)

and an implementation of that class. (I could have many implementations.)

class MyImplementation : MyBase 
{
    // stuff
}

我怎样才能获得 myActualType 的typeof(MyImplementation)

推荐答案

这是我使用的模式。

abstract class MyBase
{
   public static void MyMethod(Type type)
   {
      doSomethingWith(type);
   }
}

这篇关于在的GetType静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆