I know there are a few questions on this already but I can't seem to get this to work.
I have a class like this;
public class TopLocation<T> : ILocation
{
public string name { get; set; }
public string address { get; set; }
}
When I create the class I specify whether it's an IRestaurant
or IClub
. No problem so far.
However, how do I test to see whether it's an IClub
or IRestaurant
in an if
statement?
This fails;
if (item.trendItem is ILocation<ITopRestaurant>)
and this returns null
Type myInterfaceType = item.trendItem.GetType().GetInterface(
typeof(ITopRestaurant).Name);
The reason I'd like this in an if
statement is because it's sitting within an ascx page in an MVC application and I am trying to render the correct partial view.
edit
in response to the comment;
public interface ITopClub{}
public interface ITopRestaurant { }
public interface ILocation{}