Are there any good workarounds for FxCop warning CA1006?

前端 未结 3 1680
死守一世寂寞
死守一世寂寞 2020-12-15 04:44

I am having trouble with FxCop warning CA1006, Microsoft.Design \"DoNotNestGenericTypesInMemberSignatures\". Specifically, I am designing a ReportCollection

相关标签:
3条回答
  • 2020-12-15 04:51

    I would take FxCop's warnings as if they were suggestions from an extremely anal-retentive coworker. It's perfectly ok to ignore (suppress) some of the things it suggests.

    0 讨论(0)
  • 2020-12-15 04:54

    I agree that you can ignore the CA1006 warning in the case of

    Func<IEnumerable<T>>
    

    Also you can simplify your code by using delegates and avoid the CA1006:

    public delegate IEnumerable<T> ChildrenDel<T>( T parent);
    
    // was: GetDescendants<T>( this T item, Func< T, IEnumerable< T > > children )
    
    public static IEnumerable< T > GetDescendants<T>( this T item, ChildrenDel<T> children )
    {
        var stack = new Stack< T >();
        do {
            children( item ).ForEach( stack.Push );
    
            if( stack.Count == 0 )
                break;
    
            item = stack.Pop();
    
            yield return item;
        } while( true );
    }
    
    0 讨论(0)
  • 2020-12-15 04:56

    I agree, another good time to ignore this rule is when you need to say:

    Func<IEnumerable<T>>
    

    of course you could use the non-generic IEnumerable, but then any type can be used as long as it implements IEnumerable (non-generic). The purpose of generics (in part) is to restrict the types that are permisable to a given set of types.

    I think this rule is very stupid. only need it if you have multiple generic types nested. one layer of nesting is more than safe.

    BTW, I think a lot of the LINQ Functions nest generic types as well, so if MS does it, we can too :)

    0 讨论(0)
提交回复
热议问题