コード例 #1
0
        public static bool IsSetAssert(this DescriptionOptions opts, DescriptionOptions flag, MemberInfo member)
        {
            if ((opts.IsSet(DescriptionOptions.PluralDescription) || opts.IsSet(DescriptionOptions.Gender)) && !opts.IsSet(DescriptionOptions.Description))
                throw new InvalidOperationException("{0} has {1} set also requires {2}".Formato(member.Name, opts, DescriptionOptions.Description));

            if ((member is PropertyInfo || member is FieldInfo) &&
                (opts.IsSet(DescriptionOptions.PluralDescription) ||
                 opts.IsSet(DescriptionOptions.Gender) ||
                 opts.IsSet(DescriptionOptions.Members)))
                throw new InvalidOperationException("Member {0} has {1} set".Formato(member.Name, opts));

            return opts.IsSet(flag);
        }
コード例 #2
0
        public static bool IsSetAssert(this DescriptionOptions opts, DescriptionOptions flag, MemberInfo member)
        {
            if ((opts.IsSet(DescriptionOptions.PluralDescription) || opts.IsSet(DescriptionOptions.Gender)) && !opts.IsSet(DescriptionOptions.Description))
            {
                throw new InvalidOperationException("{0} has {1} set also requires {2}".FormatWith(member.Name, opts, DescriptionOptions.Description));
            }

            if ((member is PropertyInfo || member is FieldInfo) &&
                (opts.IsSet(DescriptionOptions.PluralDescription) ||
                 opts.IsSet(DescriptionOptions.Gender) ||
                 opts.IsSet(DescriptionOptions.Members)))
            {
                throw new InvalidOperationException("Member {0} has {1} set".FormatWith(member.Name, opts));
            }

            return(opts.IsSet(flag));
        }
コード例 #3
0
        internal static LocalizedType ImportXml(Type type, DescriptionOptions opts, LocalizedAssembly assembly, XElement x)
        {
            string?description = !opts.IsSetAssert(DescriptionOptions.Description, type) ? null :
                                 (x == null || x.Attribute("Name").Value != type.Name ? null : x.Attribute("Description")?.Value) ??
                                 (!assembly.IsDefault ? null : DescriptionManager.DefaultTypeDescription(type));

            var xMembers = x?.Elements("Member")
                           .Select(m => KeyValuePair.Create(m.Attribute("Name").Value, m.Attribute("Description").Value))
                           .Distinct(m => m.Key)
                           .ToDictionary();

            LocalizedType result = new LocalizedType
            {
                Type     = type,
                Options  = opts,
                Assembly = assembly,

                Description       = description,
                PluralDescription = !opts.IsSetAssert(DescriptionOptions.PluralDescription, type) ? null :
                                    ((x == null || x.Attribute("Name").Value != type.Name ? null : x.Attribute("PluralDescription")?.Value) ??
                                     (!assembly.IsDefault ? null : type.GetCustomAttribute <PluralDescriptionAttribute>()?.PluralDescription) ??
                                     (description == null ? null : NaturalLanguageTools.Pluralize(description, assembly.Culture))),

                Gender = !opts.IsSetAssert(DescriptionOptions.Gender, type) ? null :
                         ((x?.Attribute("Gender")?.Value.Single()) ??
                          (!assembly.IsDefault ? null : type.GetCustomAttribute <GenderAttribute>()?.Gender) ??
                          (description == null ? null : NaturalLanguageTools.GetGender(description, assembly.Culture))),

                Members = !opts.IsSetAssert(DescriptionOptions.Members, type) ? null :
                          (from m in GetMembers(type)
                           where DescriptionManager.OnShouldLocalizeMember(m)
                           let value = xMembers?.TryGetC(m.Name) ?? (!assembly.IsDefault ? null : DescriptionManager.DefaultMemberDescription(m))
                                       where value != null
                                       select KeyValuePair.Create(m.Name, value))
                          .ToDictionary()
            };

            return(result);
        }
コード例 #4
0
 public static bool IsSet(this DescriptionOptions opts, DescriptionOptions flag)
 {
     return((opts & flag) == flag);
 }
コード例 #5
0
 public DescriptionOptionsAttribute(DescriptionOptions options)
 {
     this.Options = options;
 }
コード例 #6
0
 public static bool IsSet(this DescriptionOptions opts, DescriptionOptions flag)
 {
     return (opts & flag) == flag;
 }
コード例 #7
0
        internal static LocalizedType ImportXml(Type type, DescriptionOptions opts, LocalizedAssembly assembly, XElement x)
        {
            string name = !opts.IsSetAssert(DescriptionOptions.Description, type) ? null :
                (x == null ? null : x.Attribute("Description").Try(xa => xa.Value)) ??
                (!assembly.IsDefault ? null : DescriptionManager.DefaultTypeDescription(type));

            var xMembers = x == null ? null : x.Elements("Member")
                .Select(m => KVP.Create(m.Attribute("Name").Value, m.Attribute("Description").Value))
                .Distinct(m => m.Key)
                .ToDictionary();

            LocalizedType result = new LocalizedType
            {
                Type = type,
                Options = opts,
                Assembly = assembly,

                Description = name,
                PluralDescription = !opts.IsSetAssert(DescriptionOptions.PluralDescription, type) ? null :
                             ((x == null ? null : x.Attribute("PluralDescription").Try(xa => xa.Value)) ??
                             (!assembly.IsDefault ? null : type.SingleAttribute<PluralDescriptionAttribute>().Try(t => t.PluralDescription)) ??
                             (name == null ? null : NaturalLanguageTools.Pluralize(name, assembly.Culture))),

                Gender = !opts.IsSetAssert(DescriptionOptions.Gender, type) ? null :
                         ((x == null ? null : x.Attribute("Gender").Try(xa => xa.Value.Single())) ??
                         (!assembly.IsDefault ? null : type.SingleAttribute<GenderAttribute>().Try(t => t.Gender)) ??
                         (name == null ? null : NaturalLanguageTools.GetGender(name, assembly.Culture))),

                Members = !opts.IsSetAssert(DescriptionOptions.Members, type) ? null :
                          (from m in GetMembers(type)
                           where DescriptionManager.OnShouldLocalizeMember(m)
                           let value = xMembers.TryGetC(m.Name) ?? (!assembly.IsDefault ? null : DescriptionManager.DefaultMemberDescription(m))
                           where value != null
                           select KVP.Create(m.Name, value))
                           .ToDictionary()
            };

            return result;
        }
コード例 #8
0
 public DescriptionOptionsAttribute(DescriptionOptions options)
 {
     this.Options = options;
 }