public T GetValue(object culture)
        {
            var cultureKey = CultureKey.Parse(culture);

            ResourceLanguage language;

            if (!_languages.TryGetValue(cultureKey, out language))
            {
                return(default(T));
            }

            Contract.Assume(language != null);

            return(_getter(language));
        }
        private static IEnumerable <CultureKey> CastLanguages(object languages)
        {
            var obj = languages.PsObjectCast <object>();

            switch (obj)
            {
            case string str:
                return(new[] { CultureKey.Parse(str) });

            case IEnumerable enumerable:
                return(enumerable.PsCast <object>().Select(CultureKey.Parse).ToArray());

            default:
                return(new[] { CultureKey.Parse(obj.PsObjectCast <object>()) });
            }
        }
        public bool SetValue(object culture, T value)
        {
            var cultureKey = CultureKey.Parse(culture);

            ResourceLanguage language;

            if (!_languages.TryGetValue(cultureKey, out language))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.LanguageNotDefinedError, cultureKey.Culture));
            }

            if (!_setter(language, value))
            {
                return(false);
            }

            OnValueChanged();
            return(true);
        }
Ejemplo n.º 4
0
        private static IEnumerable <CultureKey> CastLanguages(object languages)
        {
            IEnumerable <CultureKey> resourceLanguages = null;

            switch (languages.PsObjectCast <object>())
            {
            case string str:
                resourceLanguages = new[] { CultureKey.Parse(str) };
                break;

            case IEnumerable enumerable:
                resourceLanguages = enumerable.PsCast <object>().Select(CultureKey.Parse).ToArray();
                break;

            case object obj:
                resourceLanguages = new[] { CultureKey.Parse(obj.PsObjectCast <object>()) };
                break;
            }

            return(resourceLanguages);
        }
Ejemplo n.º 5
0
        public ResourceScope([NotNull] object entries, [NotNull] object languages, [NotNull] object comments)
        {
            Contract.Requires(entries != null);
            Contract.Requires(languages != null);
            Contract.Requires(comments != null);

            // ReSharper disable AssignNullToNotNullAttribute
            Entries = entries.PsObjectCast <object>().TryCast().Returning <IEnumerable <ResourceTableEntry> >()
                      .When <IEnumerable>(item => item.PsCast <ResourceTableEntry>().ToArray())
                      .When <object>(item => new[] { item.PsObjectCast <ResourceTableEntry>() })
                      .Result;

            if (Entries == null)
            {
                throw new ArgumentException("Invalid input", nameof(entries));
            }

            Languages = languages.PsObjectCast <object>().TryCast().Returning <IEnumerable <CultureKey> >()
                        .When <string>(item => new[] { CultureKey.Parse(item) })
                        .When <IEnumerable>(item => item.PsCast <object>().Select(CultureKey.Parse).ToArray())
                        .When <object>(item => new[] { CultureKey.Parse(item.PsObjectCast <object>()) })
                        .Result;

            if (Languages == null)
            {
                throw new ArgumentException("Invalid input", nameof(languages));
            }

            Comments = comments.PsObjectCast <object>().TryCast().Returning <IEnumerable <CultureKey> >()
                       .When <string>(item => new[] { CultureKey.Parse(item) })
                       .When <IEnumerable>(item => item.PsCast <object>().Select(CultureKey.Parse).ToArray())
                       .When <object>(item => new[] { CultureKey.Parse(item.PsObjectCast <object>()) })
                       .Result;
            // ReSharper restore AssignNullToNotNullAttribute

            if (Comments == null)
            {
                throw new ArgumentException("Invalid input", nameof(comments));
            }
        }