public IReadOnlyDictionary <char, char> GetBracketCharacterAttributes(Type attributeType) { if (CustomAttributeProvider != null) { object[] attributes = CustomAttributeProvider.GetCustomAttributes(attributeType, false); if (attributes.Length == 0) { return(null); } if (attributeType == typeof(MarkupExtensionBracketCharactersAttribute)) { Dictionary <char, char> bracketCharacterAttributeList = new Dictionary <char, char>(); foreach (object attribute in attributes) { MarkupExtensionBracketCharactersAttribute bracketCharactersAttribute = (MarkupExtensionBracketCharactersAttribute)attribute; bracketCharacterAttributeList.Add(bracketCharactersAttribute.OpeningBracket, bracketCharactersAttribute.ClosingBracket); } return(new ReadOnlyDictionary <char, char>(bracketCharacterAttributeList)); } Debug.Fail("Unexpected attribute type requested: " + attributeType.Name); return(null); } if (attributeType == typeof(MarkupExtensionBracketCharactersAttribute)) { return(TokenizeBracketCharacters(attributeType)); } return(null); }
public Type[] GetAttributeTypes(Type attributeType, int count) { if (CustomAttributeProvider != null) { object[] attributes = CustomAttributeProvider.GetCustomAttributes(attributeType, false); if (attributes.Length == 0) { return(null); } Debug.Assert(attributeType == typeof(XamlDeferLoadAttribute)); Debug.Assert(count == 2); XamlDeferLoadAttribute tca = (XamlDeferLoadAttribute)attributes[0]; Type converterType = XamlNamespace.GetTypeFromFullTypeName(tca.LoaderTypeName); Type contentType = XamlNamespace.GetTypeFromFullTypeName(tca.ContentTypeName); return(new Type[] { converterType, contentType }); } try { CustomAttributeData cad = GetAttribute(attributeType); if (cad == null) { return(null); } return(ExtractTypes(cad, count)); } catch (CustomAttributeFormatException) { CustomAttributeProvider = Member; return(GetAttributeTypes(attributeType, count)); } }
public List<T> GetAllAttributeContents<T>(Type attributeType) { if (CustomAttributeProvider != null) { object[] attributes = CustomAttributeProvider.GetCustomAttributes(attributeType, false); if (attributes.Length == 0) { return null; } List<T> result = new List<T>(); if (attributeType == typeof(ContentWrapperAttribute)) { foreach (ContentWrapperAttribute attribute in attributes) { result.Add((T)(object)attribute.ContentWrapper); } return result; } if (attributeType == typeof(DependsOnAttribute)) { foreach (DependsOnAttribute attribute in attributes) { result.Add((T)(object)attribute.Name); } return result; } Debug.Fail("Unexpected attribute type requested: " + attributeType.Name); return null; } try { List<CustomAttributeData> cads = new List<CustomAttributeData>(); GetAttributes(attributeType, cads); if (cads.Count == 0) { return null; } List<T> types = new List<T>(); foreach (CustomAttributeData cad in cads) { T content = Extract<T>(cad); types.Add((T)(object)content); } return types; } catch (CustomAttributeFormatException) { CustomAttributeProvider = Member; return GetAllAttributeContents<T>(attributeType); } }
protected virtual IList <XamlType> LookupContentWrappers() { if (CustomAttributeProvider == null) { return(null); } var arr = CustomAttributeProvider.GetCustomAttributes(typeof(ContentWrapperAttribute), false); if (arr == null || arr.Length == 0) { return(null); } var l = new XamlType[arr.Length]; for (int i = 0; i < l.Length; i++) { l[i] = SchemaContext.GetXamlType(((ContentWrapperAttribute)arr[i]).ContentWrapper); } return(l); }
public Type GetAttributeType(Type attributeType) { if (CustomAttributeProvider != null) { object[] attributes = CustomAttributeProvider.GetCustomAttributes(attributeType, false); if (attributes.Length == 0) { return(null); } if (attributeType == typeof(TypeConverterAttribute)) { string typeName = ((TypeConverterAttribute)attributes[0]).ConverterTypeName; return(XamlNamespace.GetTypeFromFullTypeName(typeName)); } if (attributeType == typeof(MarkupExtensionReturnTypeAttribute)) { return(((MarkupExtensionReturnTypeAttribute)attributes[0]).ReturnType); } if (attributeType == typeof(ValueSerializerAttribute)) { return(((ValueSerializerAttribute)attributes[0]).ValueSerializerType); } Debug.Fail("Unexpected attribute type requested: " + attributeType.Name); return(null); } try { CustomAttributeData cad = GetAttribute(attributeType); if (cad == null) { return(null); } return(ExtractType(cad)); } catch (CustomAttributeFormatException) { CustomAttributeProvider = Member; return(GetAttributeType(attributeType)); } }
public T?GetAttributeValue <T>(Type attributeType) where T : struct { if (CustomAttributeProvider != null) { object[] attributes = CustomAttributeProvider.GetCustomAttributes(attributeType, false); if (attributes.Length == 0) { return(null); } if (attributeType == typeof(DesignerSerializationVisibilityAttribute)) { DesignerSerializationVisibility result = ((DesignerSerializationVisibilityAttribute)attributes[0]).Visibility; return((T)(object)result); } if (attributeType == typeof(UsableDuringInitializationAttribute)) { bool result = ((UsableDuringInitializationAttribute)attributes[0]).Usable; return((T)(object)result); } Debug.Fail("Unexpected attribute type requested: " + attributeType.Name); return(null); } try { CustomAttributeData cad = GetAttribute(attributeType); if (cad == null) { return(null); } return(Extract <T>(cad)); } catch (CustomAttributeFormatException) { CustomAttributeProvider = Member; return(GetAttributeValue <T>(attributeType)); } }
/// <summary> /// Returns an array of all attributes defined on this member of the given attribute type. /// Returns an empty array if no attributes are defined on this member. /// </summary> /// <param name="inherit">If true, look in base classes for inherited custom attributes.</param> public object[] GetCustomAttributes(Type attributeType, bool inherit) { return(CustomAttributeProvider.GetCustomAttributes(this, attributeType, inherit)); }
// Returns null if attribute wasn't found, string.Empty if attribute string was null or empty public string GetAttributeString(Type attributeType, out bool checkedInherited) { if (CustomAttributeProvider != null) { // Passes inherit=true for reasons explained in comment on XamlType.TryGetAttributeString checkedInherited = true; object[] attributes = CustomAttributeProvider.GetCustomAttributes(attributeType, true /*inherit*/); if (attributes.Length == 0) { return(null); } if (attributeType == typeof(ContentPropertyAttribute)) { return(((ContentPropertyAttribute)attributes[0]).Name); } if (attributeType == typeof(RuntimeNamePropertyAttribute)) { return(((RuntimeNamePropertyAttribute)attributes[0]).Name); } if (attributeType == typeof(DictionaryKeyPropertyAttribute)) { return(((DictionaryKeyPropertyAttribute)attributes[0]).Name); } if (attributeType == typeof(XamlSetMarkupExtensionAttribute)) { return(((XamlSetMarkupExtensionAttribute)attributes[0]).XamlSetMarkupExtensionHandler); } if (attributeType == typeof(XamlSetTypeConverterAttribute)) { return(((XamlSetTypeConverterAttribute)attributes[0]).XamlSetTypeConverterHandler); } if (attributeType == typeof(UidPropertyAttribute)) { return(((UidPropertyAttribute)attributes[0]).Name); } if (attributeType == typeof(XmlLangPropertyAttribute)) { return(((XmlLangPropertyAttribute)attributes[0]).Name); } if (attributeType == typeof(ConstructorArgumentAttribute)) { return(((ConstructorArgumentAttribute)attributes[0]).ArgumentName); } Debug.Fail("Unexpected attribute type requested: " + attributeType.Name); return(null); } try { // CustomAttributeData doesn't have an inherit=true option checkedInherited = false; CustomAttributeData cad = GetAttribute(attributeType); if (cad == null) { return(null); } return(Extract <string>(cad) ?? string.Empty); } catch (CustomAttributeFormatException) { CustomAttributeProvider = Member; return(GetAttributeString(attributeType, out checkedInherited)); } }
/// <summary> /// Returns an array of all attributes defined on this member. /// Returns an empty array if no attributes are defined on this member. /// </summary> /// <param name="inherit">If true, look in base classes for inherited custom attributes.</param> public object[] GetCustomAttributes(bool inherit) { return(CustomAttributeProvider.GetCustomAttributes(EnsureTypeDef(), inherit)); }
public override object[] GetCustomAttributes(bool inherit) { return(_customAttributeProvider.GetCustomAttributes(inherit)); }