<commit_before>﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ContextExtensions.cs" company="Quartz Software SRL">
//   Copyright (c) Quartz Software SRL. All rights reserved.
// </copyright>
// <summary>
//   Implements the context extensions class.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Kephas.Data.InMemory
{
    using System.Collections.Generic;

    using Kephas.Data.Capabilities;
    using Kephas.Diagnostics.Contracts;
    using Kephas.Services;

    /// <summary>
    /// Extension methods for <see cref="IContext"/>.
    /// </summary>
    public static class ContextExtensions
    {
        /// <summary>
        /// Gets the initial data.
        /// </summary>
        /// <param name="context">The context to act on.</param>
        /// <returns>
        /// An enumeration of entity information.
        /// </returns>
        public static IEnumerable<IEntityInfo> GetInitialData(this IContext context)
        {
            Requires.NotNull(context, nameof(context));

            return context[nameof(InMemoryDataContextConfiguration.InitialData)] as IEnumerable<IEntityInfo>;
        }

        /// <summary>
        /// Sets the initial data.
        /// </summary>
        /// <param name="context">The context to act on.</param>
        /// <param name="initialData">The initial data.</param>
        public static void SetInitialData(this IContext context, IEnumerable<IEntityInfo> initialData)
        {
            Requires.NotNull(context, nameof(context));

            context[nameof(InMemoryDataContextConfiguration.InitialData)] = initialData;
        }
    }
}<commit_msg>Allow context to be null when querying for initial data.<commit_after>﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ContextExtensions.cs" company="Quartz Software SRL">
//   Copyright (c) Quartz Software SRL. All rights reserved.
// </copyright>
// <summary>
//   Implements the context extensions class.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Kephas.Data.InMemory
{
    using System.Collections.Generic;

    using Kephas.Data.Capabilities;
    using Kephas.Diagnostics.Contracts;
    using Kephas.Services;

    /// <summary>
    /// Extension methods for <see cref="IContext"/>.
    /// </summary>
    public static class ContextExtensions
    {
        /// <summary>
        /// Gets the initial data.
        /// </summary>
        /// <param name="context">The context to act on.</param>
        /// <returns>
        /// An enumeration of entity information.
        /// </returns>
        public static IEnumerable<IEntityInfo> GetInitialData(this IContext context)
        {
            return context?[nameof(InMemoryDataContextConfiguration.InitialData)] as IEnumerable<IEntityInfo>;
        }

        /// <summary>
        /// Sets the initial data.
        /// </summary>
        /// <param name="context">The context to act on.</param>
        /// <param name="initialData">The initial data.</param>
        public static void SetInitialData(this IContext context, IEnumerable<IEntityInfo> initialData)
        {
            Requires.NotNull(context, nameof(context));

            context[nameof(InMemoryDataContextConfiguration.InitialData)] = initialData;
        }
    }
}
{'fraction_non_alphanumeric': 0.24047817625799278, 'fraction_numerical': 0.0, 'mean_word_length': 1.568165596002855, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4432094', 'n_tokens_mistral': 835, 'n_tokens_neox': 822, 'n_words': 211}