The given expression is never of the provided warning.
23/01/2011 Leave a comment
When you try to getting type of Generic variable “T” you get this warning.Here is the sample :
class CauseWarning { public void make<T>(T value) { if (typeof(T) is Test) Console.Write("Something"); } } public class Test { }
Here is the solution:
class CauseWarning { public void make<T>(T value) { if (typeof(T).IsAssignableFrom(typeof( Test))) Console.Write("Something"); } } public class Test { }
Type.IsAssignableFrom Method Determines whether an instance of the current Type can be assigned from an instance of the specified Type.true if the c parameter and the current Type represent the same type, or if the current Type is in the inheritance hierarchy of c, or if the current Type is an interface that c supports. false if none of these conditions are the case, or if c is a null reference.