views:

54

answers:

0

Hi...I am fairly new to Code Contracts...and I ran into a problem.

I have in a method LINQ query that go something like this:

MyClass[] fields =
            (from p in rType.GetProperties()
             where p.CanRead
             let fAttr = p.GetCustomAttributes(typeof(MyClassAttribute), true).SingleOrDefault() as MyClassAttribute
             where fAttr != null
             select new MyClass(p, fAttr)).ToArray();

And I want to implement Code Contracts in my project. I have done everything OK, until I got to this point. When I run static checker, it suggest to me that I need to add a couple of preconditions (Contract.Requires) regarding variables p and fAttr which are defined in the query. And also, I have a couple of unproven requires.

How can I solve this? Any ideas?

MyClass also contains two preconditions:

internal MyClass(PropertyInfo p, MyClassAttribute att)
    {
        Contract.Requires(p != null);
        Contract.Requires(att != null);
        ...
    }

Thanks in advance :)