How to check a hold Instance or Type variable in C #
I have a class Test
public class Test { }
Now I have a variable object1
that contains an instance Test
.
object object2 = new Test();
// some code
object2 = typeof(Test);
object2
will take both a type and an instance of the class Test
in different scenarios. How can I check what value it has. i.e. instance Test
or typeTest
+3
source to share
5 answers
You can also use my library ( link ):
object2.DetermineType()
.When((Test target) => { /* action to do */ })
.When((Type target) => { /* action to do */ })
.Resolve();
or
object2.DetermineType()
.When<Test>(target => { /* action to do */ })
.When<Type>(target => { /* action to do */ })
.Resolve();
But if you need to define the type this way, your design may not be very good.
+1
user2160375
source
to share