C# generic cast

Viewed 981

I have an interface called IEditor

public interface IEditor<T> 
    where T: SpecialObject

SpecialObject is an abstract class.

Here´s my problem:

I have a class which inherits from SpecialObject and a view which implements this IEditor interface

public class View : IEditor<Person>

Now, I have to check whether View implements IEditor<SpecialObject>

Boolean isEditor = View is IEditor<SpecialObject>

But IEditor is always false

Is there any possibility to check if View is IEditor<SpecialObject>?

Edit

I have a method which is called when a closing event is raised. The views which are passed to this method can implement IEditor, but they also can implement another interface. In example IView

  void Closing(object sender, MyEventArgs e)
  {
      if(e.Item is IView)
      {
          // DO some closing tasks

          if(e.Item is IEditor<SpecialObject>)          // always false
          {
              // Do some special tasks
              var editor = e.Item as IEditor<SpecialObject>;

              var storedEditObect = editor.StoredObject;

              // more tasks
          }
      } else if(e.Item is ISomeOtherView)
      {}
  }

I have some classes called Person, Address and so on. They all inherits from SpecialObject. In some case e.Item inherits from IEditor or from IEditor Because of that, I have to cast to my base class to access the defaut property fields

2 Answers
Related