Beispiel #1
0
        public void BuildCachePath(Type entityType, String memberToInitialize, CHashSet <AppendableCachePath> cachePaths)
        {
            Type   currentType         = entityType;
            String requestedMemberName = memberToInitialize;
            AppendableCachePath            currentCachePath  = null;
            CHashSet <AppendableCachePath> currentCachePaths = cachePaths;

            while (true)
            {
                IEntityMetaData metaData      = EntityMetaDataProvider.GetMetaData(currentType);
                Member          widenedMember = metaData.GetWidenedMatchingMember(requestedMemberName);
                if (widenedMember == null)
                {
                    throw new ArgumentException("No member found to resolve path " + entityType.FullName + "." + memberToInitialize);
                }
                String widenedMemberName = widenedMember.Name;
                if (widenedMember is PrimitiveMember)
                {
                    if (widenedMemberName.Equals(memberToInitialize))
                    {
                        // this member does not need to be prefetched
                        return;
                    }
                    // widened member has been found but not the full path of the requested member name
                    throw new ArgumentException("No member found to resolve path " + entityType.FullName + "." + memberToInitialize);
                }
                AppendableCachePath childCachePath = null;
                if (currentCachePaths == null)
                {
                    currentCachePaths         = new CHashSet <AppendableCachePath>();
                    currentCachePath.children = currentCachePaths;
                }
                foreach (AppendableCachePath cachePath in currentCachePaths)
                {
                    if (widenedMemberName.Equals(cachePath.memberName))
                    {
                        childCachePath = cachePath;
                        break;
                    }
                }
                if (childCachePath == null)
                {
                    int relationIndex = metaData.GetIndexByRelation(widenedMember);
                    childCachePath = new AppendableCachePath(widenedMember.ElementType, relationIndex, widenedMemberName);
                    currentCachePaths.Add(childCachePath);
                }
                if (widenedMemberName.Equals(requestedMemberName))
                {
                    // we have travered the full path of the requested member name
                    return;
                }
                requestedMemberName = requestedMemberName.Substring(widenedMemberName.Length + 1);
                currentCachePath    = childCachePath;
                currentType         = currentCachePath.memberType;
                currentCachePaths   = currentCachePath.children;
            }
        }