BamlLocalization.DefaultAttributes.GetDefaultAttribute C# (CSharp) Метод

GetDefaultAttribute() статический приватный Метод

Get the localizability attribute for a type
static private GetDefaultAttribute ( object type ) : System.Windows.LocalizabilityAttribute
type object
Результат System.Windows.LocalizabilityAttribute
        internal static LocalizabilityAttribute GetDefaultAttribute(object type)
        {
            if (DefinedAttributes.ContainsKey(type))
            {
                LocalizabilityAttribute predefinedAttribute = DefinedAttributes[type];

                // create a copy of the predefined attribute and return the copy
                LocalizabilityAttribute result = new LocalizabilityAttribute(predefinedAttribute.Category);
                result.Readability   = predefinedAttribute.Readability;
                result.Modifiability = predefinedAttribute.Modifiability;
                return result;
            }
            else
            {
                Type targetType = type as Type;
                if ( targetType != null && targetType.IsValueType)
                {
                    // It is looking for the default value of a value type (i.e. struct and enum)
                    // we use this default.
                    LocalizabilityAttribute attribute = new LocalizabilityAttribute(LocalizationCategory.Inherit);
                    attribute.Modifiability           = Modifiability.Unmodifiable;
                    return attribute;
                }
                else
                {
                    return DefaultAttribute;
                }
            }
        }

Usage Example

        /// <summary>
        /// gets the localizabiity attribute of a given the type
        /// </summary>
        private LocalizabilityAttribute GetLocalizabilityFromType(Type type)
        {
            if (type == null)
            {
                return(null);
            }

            // let's get to its localizability attribute.
            object[] locAttributes = type.GetCustomAttributes(
                TypeOfLocalizabilityAttribute, // type of localizability
                true                           // search for inherited value
                );

            if (locAttributes.Length == 0)
            {
                return(DefaultAttributes.GetDefaultAttribute(type));
            }
            else
            {
                Debug.Assert(locAttributes.Length == 1, "Should have only 1 localizability attribute");

                // use the one defined on the class
                return((LocalizabilityAttribute)locAttributes[0]);
            }
        }