// <summary>
        // Flattens composite transient type down to nominal type leafs.
        // </summary>
        internal static IEnumerable <TypeUsage> FlattenType(TypeUsage type)
        {
            Func <TypeUsage, bool> isLeaf = t => !Helper.IsTransientType(t.EdmType);

            Func <TypeUsage, IEnumerable <TypeUsage> > getImmediateSubNodes =
                t =>
            {
                if (Helper.IsCollectionType(t.EdmType) ||
                    Helper.IsRefType(t.EdmType))
                {
                    return(new[] { TypeHelpers.GetElementTypeUsage(t) });
                }
                else if (Helper.IsRowType(t.EdmType))
                {
                    return(((RowType)t.EdmType).Properties.Select(p => p.TypeUsage));
                }
                else
                {
                    Debug.Fail("cannot enumerate subnodes of a leaf node");
                    return(new TypeUsage[] { });
                }
            };

            return(Helpers.GetLeafNodes(type, isLeaf, getImmediateSubNodes));
        }
Beispiel #2
0
        internal static IEnumerable <TypeUsage> FlattenType(TypeUsage type)
        {
            Func <TypeUsage, bool> isLeaf = (Func <TypeUsage, bool>)(t => !Helper.IsTransientType(t.EdmType));
            Func <TypeUsage, IEnumerable <TypeUsage> > getImmediateSubNodes = (Func <TypeUsage, IEnumerable <TypeUsage> >)(t =>
            {
                if (Helper.IsCollectionType((GlobalItem)t.EdmType) || Helper.IsRefType((GlobalItem)t.EdmType))
                {
                    return (IEnumerable <TypeUsage>) new TypeUsage[1]
                    {
                        TypeHelpers.GetElementTypeUsage(t)
                    }
                }
                ;
                if (Helper.IsRowType((GlobalItem)t.EdmType))
                {
                    return(((RowType)t.EdmType).Properties.Select <EdmProperty, TypeUsage>((Func <EdmProperty, TypeUsage>)(p => p.TypeUsage)));
                }
                return((IEnumerable <TypeUsage>) new TypeUsage[0]);
            });

            return(Helpers.GetLeafNodes <TypeUsage>(type, isLeaf, getImmediateSubNodes));
        }