ItemNotNullAttribute has problems?
Hi,
I'd like to comfirm that ItemNotNullAttrbute still has problems of null-cheking.
https://youtrack.jetbrains.com/issue/RSRP-466093
https://youtrack.jetbrains.com/issue/RSRP-462951
If so, I have an idea of substitution for ItemNotNullAttribute.
To use the following wrapper class instead of List<T> class.
public class ItemNotNullList<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>
{
[NotNull]
private readonly List<T> list = new List<T>();
[NotNull]
public T this[int i]
{
get
{
System.Diagnostics.Debug.Assert(list[i] != null);
return list[i];
}
set
{
list[i] = value;
}
}
public void Add([NotNull]T item)
{
list.Add(item);
}
...
}
It seems to work well.
Please sign in to leave a comment.