c# - Extension method to check if an object is sub class of T -


I am trying to write an extension method which is a sub class of an object t.

This has not been accepted by Visual Studio, but it has not been accepted.

  Public Static Bull eSilff & Lt; T & G; (This object is OBJ) {Return (type (oBJ). ISBNs (typef (t)); } [Test ()] Public Zero IschildOfTest () {var dog = new dog (); Var isnimal = dog.IsChildOf & lt; Animals & gt; (); Assert.That (isAnimal); }   

Any ideas how can I write it?

You can just use but note That is, is as it is like IsSubclassOf . See Jep's fantastic comment for details and I also have an example.

On the one side note, I do not think Java allows equivalent instanceof in such a general case for some reason, but it's OK in C # .:

  Public Static Bull Eshilpf & Lt; T & gt; (This object obg) {return is oz t; }   

Then it makes this so insignificant that readers are more confused to use an extension method than is if you used it directly Your test then appears:

  [test ()] Public Zero Ishichoffast () {var dog = new dog (); Var is Animal = Dog Animals; Assert.That (isAnimal); }   

An example of one of the differences between and IsSubclassOf :

  [test ]] Public Zero IschildOfTest () {var dog = new dog (); Assert.False (dog.GetType () IsSubclassOf (typeof (dog)).); Responsibility Truth (dog is dog); }    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -