0

I have method in factory class

    internal Window GetWindow(int siteId)
    {
        Contract.Requires(siteId > 0);

        Window result;

        //some logic that create specific window

        return result;
    }

Lets assume i have [MyAttribute]

I need postcondition in GetWindow which can prove that method returns object marked with [MyAttribute]

Is it possible?

nuclear sweet
  • 1,079
  • 10
  • 27

1 Answers1

0

I think it is possible with reflection.

I'm assuming that the method you want to test is in the same class.

   Type returnedType = this.GetType().GetMethod("The method you want to test").ReturnType;
   Contract.Requires(returnedType.GetCustomAttributes(typeof(MyAttribute), true).Length > 0);
Guerudo
  • 361
  • 1
  • 7