Are there any good workarounds for FxCop warning CA1006?

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

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

3条回答
  •  -上瘾入骨i
    2020-12-15 04:54

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

    Func>
    

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

    public delegate IEnumerable ChildrenDel( T parent);
    
    // was: GetDescendants( this T item, Func< T, IEnumerable< T > > children )
    
    public static IEnumerable< T > GetDescendants( this T item, ChildrenDel 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 );
    }
    

提交回复
热议问题