Esempio n. 1
0
 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));
     }
 }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        public UnitOfWorkInfo Build()
        {
            var attribute = CustomAttributeProvider.Attribute <UnitOfWorkAttribute>();

            var name = attribute != null && !string.IsNullOrWhiteSpace(attribute.Name)
                           ? attribute.Name
                           : GetUowName();

            var allow = CustomAttributeProvider.Attribute <AllowAsyncAttribute>();

            var notAllow = CustomAttributeProvider.Attribute <NotAsyncAttribute>();

            var async = Nails.Configuration.DefaultAsyncMode;

            if (Nails.Configuration.AllowAsyncExecution)
            {
                if (!AllowAsync)
                {
                    //only void methods can be invoked Async automatically.
                    async = false;
                }
                else
                {
                    //negotiate with the default value.
                    if (allow != null)
                    {
                        async = true;
                    }
                    else if (notAllow != null)
                    {
                        async = false;
                    }
                }
            }
            else
            {
                async = false;
            }


            var transactionMode = attribute != null
                                      ? attribute.TransactionMode
                                      : Nails.Configuration.DefaultTransactionMode;

            var uowinfo = new UnitOfWorkInfo(isTransactional: transactionMode != TransactionMode.NoTransaction,
                                             isAsync: async);

            return(uowinfo);
        }
Esempio n. 5
0
 public bool IsAttributePresent(Type attributeType)
 {
     if (CustomAttributeProvider != null)
     {
         return(CustomAttributeProvider.IsDefined(attributeType, false));
     }
     try
     {
         CustomAttributeData cad = GetAttribute(attributeType);
         return(cad != null);
     }
     catch (CustomAttributeFormatException)
     {
         CustomAttributeProvider = Member;
         return(IsAttributePresent(attributeType));
     }
 }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
 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));
     }
 }
Esempio n. 8
0
 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));
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Are one or more attributes of the given type defined on this member.
 /// </summary>
 /// <param name="attributeType">The type of the custom attribute</param>
 /// <param name="inherit">If true, look in base classes for inherited custom attributes.</param>
 public bool IsDefined(Type attributeType, bool inherit)
 {
     return(CustomAttributeProvider.IsDefined(this, attributeType, inherit));
 }
Esempio n. 10
0
 /// <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));
 }
Esempio n. 11
0
        // 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));
            }
        }
Esempio n. 12
0
 public AssemblyNode(TypeNodeProvider provider, TypeNodeListProvider listProvider,
   CustomAttributeProvider provideCustomAttributes, ResourceProvider provideResources, string directory)
     : base(provider, listProvider, provideCustomAttributes, provideResources)
 {
     this.Directory = directory;
     this.NodeType = NodeType.Assembly;
     this.ContainingAssembly = this;
 }
Esempio n. 13
0
 public Module(TypeNodeProvider provider, TypeNodeListProvider listProvider, CustomAttributeProvider provideCustomAttributes, ResourceProvider provideResources)
     : base(NodeType.Module)
 {
     this.provideCustomAttributes = provideCustomAttributes;
     this.provideResources = provideResources;
     this.provideTypeNode = provider;
     this.provideTypeNodeList = listProvider;
     this.IsNormalized = true;
 }
Esempio n. 14
0
 /// <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));
 }