示例#1
0
        /// <summary>
        /// Loads a dictionary of string to string with the given name from the given resource manager.
        /// </summary>
        /// <param name="source">The <see cref="ResourceSet"/> to load from.</param>
        /// <param name="name">The resource name.</param>
        /// <returns>The <see cref="IDictionary{TKey,TValue}"/> or null if there is no such resource.</returns>
        private static IDictionary <string, string> LoadDictionary(ResourceSet source, string name)
        {
            Preconditions.CheckNotNull(source, "source");
            var bytes = source.GetObject(name) as byte[];

            if (bytes != null)
            {
                using (var stream = new MemoryStream(bytes))
                {
                    var reader = new LegacyDateTimeZoneReader(stream, null);
                    return(reader.ReadDictionary());
                }
            }
            return(null);
        }
示例#2
0
        /// <inheritdoc />
        public DateTimeZone CreateZone(string id, string canonicalId)
        {
            object obj = source.GetObject(NormalizeAsResourceName(canonicalId));

            // We should never be asked for time zones which don't exist.
            Preconditions.CheckArgument(obj != null, "canonicalId", "ID is not one of the recognized time zone identifiers within this resource");
            if (!(obj is byte[]))
            {
                throw new InvalidNodaDataException("Resource key for time zone for ID " + canonicalId + " is not a byte array");
            }
            byte[] bytes = (byte[])obj;
            using (var stream = new MemoryStream(bytes))
            {
                var reader = new LegacyDateTimeZoneReader(stream, null);
                return(reader.ReadTimeZone(id));
            }
        }