Exemple #1
0
        /// <summary>
        /// Returns a ReadOnlyEnumerableOfT that is the result of <paramref name="source"/> plus <paramref name="item"/>.
        /// </summary>
        /// <typeparam name="T">The element type of the enumerable.</typeparam>
        /// <param name="source">The source enumerable to concat.</param>
        /// <param name="collectionName">The name of the collection to report in case there's an error.</param>
        /// <param name="item">Item to concat to the source enumerable.</param>
        /// <returns>Returns a ReadOnlyEnumerableOfT that is the result of <paramref name="source"/> plus <paramref name="item"/>.</returns>
        internal static ReadOnlyEnumerable <T> ConcatToReadOnlyEnumerable <T>(this IEnumerable <T> source, string collectionName, T item)
        {
            DebugUtils.CheckNoExternalCallers();

            ReadOnlyEnumerable <T> readOnlyEnumerable = source.GetOrCreateReadOnlyEnumerable(collectionName);

            readOnlyEnumerable.AddToSourceList(item);
            return(readOnlyEnumerable);
        }
Exemple #2
0
        internal static List <T> GetSourceListOfEnumerable <T>(IEnumerable <T> collection, string collectionName)
        {
            ReadOnlyEnumerable <T> enumerable = collection as ReadOnlyEnumerable <T>;

            if (enumerable == null)
            {
                throw new ODataException(Strings.ReaderUtils_EnumerableModified(collectionName));
            }
            return(enumerable.SourceList);
        }
Exemple #3
0
        /// <summary>
        /// Creates a new instance of ATOM feed metadata.
        /// </summary>
        /// <returns>The newly created ATOM feed metadata.</returns>
        internal static AtomFeedMetadata CreateNewAtomFeedMetadata()
        {
            DebugUtils.CheckNoExternalCallers();

            return(new AtomFeedMetadata
            {
                Authors = ReadOnlyEnumerable <AtomPersonMetadata> .Empty(),
                Categories = ReadOnlyEnumerable <AtomCategoryMetadata> .Empty(),
                Contributors = ReadOnlyEnumerable <AtomPersonMetadata> .Empty(),
                Links = ReadOnlyEnumerable <AtomLinkMetadata> .Empty(),
            });
        }
Exemple #4
0
        /// <summary>
        /// Creates a new <see cref="ODataEntry"/> instance to return to the user.
        /// </summary>
        /// <returns>The newly created entry.</returns>
        /// <remarks>The method populates the Properties property with an empty read only enumeration.</remarks>
        internal static ODataEntry CreateNewEntry()
        {
            DebugUtils.CheckNoExternalCallers();

            return(new ODataEntry
            {
                Properties = new ReadOnlyEnumerable <ODataProperty>(),
                AssociationLinks = ReadOnlyEnumerable <ODataAssociationLink> .Empty(),
                Actions = ReadOnlyEnumerable <ODataAction> .Empty(),
                Functions = ReadOnlyEnumerable <ODataFunction> .Empty()
            });
        }
Exemple #5
0
        /// <summary>
        /// Casts an IEnumerableOfT to ReadOnlyEnumerableOfT.
        /// </summary>
        /// <typeparam name="T">The element type of the enumerable.</typeparam>
        /// <param name="source">The source enumerable.</param>
        /// <param name="collectionName">The name of the collection to report in case there's an error.</param>
        /// <returns>The casted ReadOnlyEnumerableOfT.</returns>
        internal static ReadOnlyEnumerable <T> ToReadOnlyEnumerable <T>(this IEnumerable <T> source, string collectionName)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(!String.IsNullOrEmpty(collectionName), "!string.IsNullOrEmpty(collectionName)");

            ReadOnlyEnumerable <T> readonlyCollection = source as ReadOnlyEnumerable <T>;

            if (readonlyCollection == null)
            {
                throw new ODataException(Strings.ReaderUtils_EnumerableModified(collectionName));
            }

            return(readonlyCollection);
        }
Exemple #6
0
        /// <summary>
        /// Given the value of the specified collection as a list which can be modified.
        /// This methods returns the internal List of the collection.
        /// </summary>
        /// <typeparam name="T">The type of the item in the collection get.</typeparam>
        /// <param name="collection">The value of the collection to get the list for.</param>
        /// <param name="collectionName">The name of the collection to report in case there's an error.</param>
        /// <returns>The underlying list to modify.</returns>
        internal static List <T> GetSourceListOfEnumerable <T>(IEnumerable <T> collection, string collectionName)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(collection != null, "collection != null");
            Debug.Assert(!string.IsNullOrEmpty(collectionName), "collectionName must not be null or empty.");

            ReadOnlyEnumerable <T> readonlyCollection = collection as ReadOnlyEnumerable <T>;

            if (readonlyCollection == null)
            {
                throw new ODataException(Strings.ReaderUtils_EnumerableModified(collectionName));
            }

            List <T> collectionList = readonlyCollection.SourceList;

            Debug.Assert(collectionList != null, "collectionList != null");

            return(collectionList);
        }
Exemple #7
0
 /// <summary>
 /// true if <paramref name="source"/> is the same instance as ReadOnlyEnumerableOfT.Empty(). false otherwise.
 /// </summary>
 /// <typeparam name="T">The element type of the enumerable.</typeparam>
 /// <param name="source">The enumerable in question.</param>
 /// <returns>Returns true if <paramref name="source"/> is the empty ReadOnlyEnumerableOfT. false otherwise.</returns>
 internal static bool IsEmptyReadOnlyEnumerable <T>(this IEnumerable <T> source)
 {
     DebugUtils.CheckNoExternalCallers();
     return(ReferenceEquals(source, ReadOnlyEnumerable <T> .Empty()));
 }