Esempio n. 1
0
            private static IHeaderArray Create <TValue>(JObject jObject, HeaderArrayType type) where TValue : IEquatable <TValue>
            {
                IEnumerable <KeyValuePair <string, IImmutableList <string> > > sets    = ParseSets(jObject["Sets"]);
                IEnumerable <KeyValuePair <KeySequence <string>, TValue> >     entries = ParseEntries(jObject["Entries"]);

                IImmutableSequenceDictionary <string, TValue> sequenceDictionary = new ImmutableSequenceDictionary <string, TValue>(sets, entries);

                return
                    (new HeaderArray <TValue>(
                         jObject["Header"].Value <string>(),
                         jObject["Coefficient"].Value <string>(),
                         jObject["Description"].Value <string>(),
                         type,
                         jObject["Dimensions"].Values <int>().ToImmutableArray(),
                         sequenceDictionary));

                IEnumerable <KeyValuePair <KeySequence <string>, TValue> > ParseEntries(JToken jsonEntries)
                {
                    return
                        (JsonConvert.DeserializeObject <IDictionary <string, TValue> >(jsonEntries.ToString())
                         .Select(
                             x =>
                             new KeyValuePair <KeySequence <string>, TValue>(
                                 KeySequence <string> .Parse(x.Key),
                                 x.Value)));
                }

                IEnumerable <KeyValuePair <string, IImmutableList <string> > > ParseSets(JToken jsonSets)
                {
                    return
                        (jsonSets.Values <JToken>()
                         .Select(
                             x =>
                             new KeyValuePair <string, IImmutableList <string> >(
                                 x.Value <string>("Key"),
                                 x.Value <JArray>("Value")
                                 .Values <string>()
                                 .ToImmutableArray())));
                }
            }
Esempio n. 2
0
        /// <summary>
        /// Creates an <see cref="IHeaderArray{TValue}"/> from one entry from a Header Array (HAR) file.
        /// </summary>
        /// <param name="header">
        /// The four character identifier for this <see cref="HeaderArray{TValue}"/>.
        /// </param>
        /// <param name="coefficient">
        /// The coefficient related to the <see cref="HeaderArray{TValue}"/>
        /// </param>
        /// <param name="description">
        /// The long name description of the <see cref="HeaderArray{TValue}"/>.
        /// </param>
        /// <param name="type">
        /// The type of element stored in the array.
        /// </param>
        /// <param name="dimensions">
        /// The dimensions of the array.
        /// </param>
        /// <param name="entries">
        /// The data in the array.
        /// </param>
        public static IHeaderArray <TValue> Create([NotNull] string header, [NotNull] string coefficient, [CanBeNull] string description, HeaderArrayType type, [NotNull] IEnumerable <int> dimensions, [NotNull] IEnumerable <TValue> entries)
        {
            if (header is null)
            {
                throw new ArgumentNullException(nameof(header));
            }
            if (coefficient is null)
            {
                throw new ArgumentNullException(nameof(coefficient));
            }
            if (dimensions is null)
            {
                throw new ArgumentNullException(nameof(dimensions));
            }
            if (entries is null)
            {
                throw new ArgumentNullException(nameof(entries));
            }

            return(new HeaderArray <TValue>(header, coefficient, description, type, dimensions, ImmutableSequenceDictionary <string, TValue> .Create(entries)));
        }