Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Underlying type of a mock object

Tags:

.net

mocking

moq

I need to check the type of a mock object and want to get the underlying type. For instance, for an object such as Mock is there anything on here I can call to get the type, "Foo"? I am using moq.

Mock<Foo> myFoo = new Mock<Foo>
myFoo.Object.?
myFoo.?
like image 856
Joe Cartano Avatar asked Oct 22 '25 14:10

Joe Cartano


1 Answers

Type t = myFoo.GetType().GetGenericArguments().First();
like image 74
TrueWill Avatar answered Oct 25 '25 04:10

TrueWill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!