3

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.?
JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
Joe Cartano
  • 2,997
  • 3
  • 22
  • 40

1 Answers1

7
Type t = myFoo.GetType().GetGenericArguments().First();
TrueWill
  • 25,132
  • 10
  • 101
  • 150
  • Is there anything that will work on the object? I want to pass in a Func to a method that takes an object of type Foo so it would be a little more convenient to do it that way? – Joe Cartano Nov 22 '10 at 19:20
  • Mock.Get(obj) will return the mock object for the instance. – TrueWill Nov 23 '10 at 15:21