/// <summary>
 /// pass the type and the fetchoptions created to see if for all types with a fetchoption, the fetchoption has been set.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="fetchOptions"></param>
 private void AssertFetchOptionsAreSet(Type type, BigInteger fetchOptions)
 {
     System.Diagnostics.Debug.WriteLine(string.Format("Entering AssertTypeGraph for type {0}", type.Name));
     // this type has not been discovered, get the fetchoptions for this type
     foreach (var prop in type.GetProperties())
     {
         // get property attribute
         var fetchOption = GetFetchOptionAttributes(prop);
         if (fetchOption != FetchOptions.AsBigInteger(FetchOptions.None))
         {
             // attribute exists
             System.Diagnostics.Debug.WriteLine("type {2}, property {0} has fetchoption {1}", prop.Name, FetchOptions.AsString(fetchOption), type.Name);
             // found a reference property with fetchoption attribute
             Assert.IsTrue((fetchOptions & fetchOption) != BigInteger.Zero);
             // get fetch options from this type
             AssertFetchOptionsAreSet(prop.PropertyType, fetchOptions);
         }
     }
     // add to cache
     stopper.Add(type);
     ////return fetchOptions;
 }
        /// <summary>
        /// Returns all the fetch options of an object graph.
        /// </summary>
        private BigInteger GetFetchOptionsForObjectGraph(Type type, BigInteger fetchOptions)
        {
            System.Diagnostics.Debug.WriteLine(string.Format("Entering GetFetchOptionsForObjectGraph for type {0}", type.Name));
            BigInteger retFetchOption = fetchOptions;

            if (cachedFetchOptions.ContainsKey(type))
            {
                // the type has already been cached.
                retFetchOption = retFetchOption | cachedFetchOptions[type];
                return(retFetchOption);
            }
            if (!stopper.Contains(type))
            {
                // this type has not been discovered, get the fetchoptions for this type
                foreach (var prop in type.GetProperties())
                {
                    var fetchOption = GetFetchOptionAttributes(prop);
                    if (fetchOption != FetchOptions.AsBigInteger(FetchOptions.None))
                    {
                        System.Diagnostics.Debug.WriteLine("type {2}, property {0} has fetchoption {1}", prop.Name, FetchOptions.AsString(fetchOption), type.Name);
                        // found a reference property with fetchoption attribute
                        if ((retFetchOption & fetchOption) == BigInteger.Zero)
                        {
                            retFetchOption = retFetchOption | fetchOption;
                        }
                        // stop circular ref
                        stopper.Add(type);
                        // get fetch options from this type
                        retFetchOption = GetFetchOptionsForObjectGraph(prop.PropertyType, retFetchOption);
                    }
                }
                // if the type is a base, then get derived types.
                if (type.IsAbstract)
                {
                    // get derive types
                    IList <Type> derivedTypes;
                    if (backReferences.ContainsKey(type))
                    {
                        derivedTypes = backReferences[type];
                    }
                    else
                    {
                        derivedTypes = type.Assembly.GetTypes().Where(t => t.IsSubclassOf(type)).ToList();
                        backReferences.Add(type, derivedTypes);
                    }
                    // get the fetch options for each derive type
                    foreach (var derivedType in derivedTypes)
                    {
                        // backreferences have not been discovered
                        retFetchOption = GetFetchOptionsForObjectGraph(derivedType, retFetchOption);
                    }
                }
                // add to cache
                cachedFetchOptions.Add(type, retFetchOption);
                return(retFetchOption);
            }
            // this type has not been discovered, get the fetchoptions for this type
            return(retFetchOption);
        }