Is it possible to do a [ItemItemNotNull]?

If I have a type that returns a `Task<IEnumerable<object>>`, when I do a `[ItemNotNull]` it specifies that the `.Value` returned from the task will be not null.

Is it possible to annotate that the objects in the IEnumerable will not be null either? Like a

    [ItemNotNull] Task<[ItemNotNull]IEnumerable<object>> Example()

I tried that format and it did not work.

1
1 comment

Thinking about it, the easist way that would be a good solution and would not break backwards compatibility would be to add the property "public bool ApplyToTaskResult { get; set; }" and if ApplyToTaskResult  is "true" then it will only act on the .Result of the task. That task itself is not affected.

 

So all combinations you could use would be:

[ItemNotNull]

public IEnumerable<object> Foo() //No object in the enumerable is null (Existing unchanged behavior)

 

[ItemNotNull(ApplyToTaskResult = true)]

public IEnumerable<object> Foo() //The attribute is effectively ignored.

 

[ItemNotNull]

public Task<IEnumerable<object>> Foo() //The .Result is guaranteed to be not null but items within the IEnumerable may be null. (Existing unchanged behavior)

 

 

[ItemNotNull(ApplyToTaskResult = true)]

public Task<IEnumerable<object>> Foo() //The .Result may be null but items within a IEnumerable instance will never be null.

 

[ItemNotNull(ApplyToTaskResult = true)]

public Task<NotAnIEnumerable> Foo() //The attribute is effectively ignored.

 

[ItemNotNull]

[ItemNotNull(ApplyToTaskResult = true)]

public Task<IEnumerable<object>> Foo() //The .Result is guaranteed to be not null and the items within the IEnumerable will never be null.

 

0

Please sign in to leave a comment.