Exemple #1
0
    static void ValidateHidden(ICustomAttributeProvider attributeProvider)
    {
        var customAttributes = attributeProvider.GetCustomAttributes(typeof(EditorBrowsableAttribute), false);
        var attribute        = (EditorBrowsableAttribute)customAttributes.First();

        Assert.Equal(EditorBrowsableState.Advanced, attribute.State);
    }
Exemple #2
0
        /// <summary>
        /// 获取自定义Attribute列表
        /// </summary>
        /// <param name="customAttributeProvider"></param>
        /// <param name="type">特性类型, instance is type。</param>
        /// <param name="inherit">如果为 true,则指定还在 element 的祖先中搜索自定义特性。</param>
        /// <returns></returns>
        public static System.Collections.IList GetCustomAttributes(
#if !net20
            this
#endif
            System.Reflection.ICustomAttributeProvider customAttributeProvider, System.Type type, bool inherit)
        {
            if (customAttributeProvider == null || type == null)
            {
                return(CreateList(type));
            }

            System.Collections.IList list;
            string key = string.Concat(GetKeyBefore(customAttributeProvider), "_", type.AssemblyQualifiedName);

            if (!_list_key.TryGetValue(key, out list))
            {
                ThreadHelper.Block(_list_key, () => {
                    if (!_list_key.TryGetValue(key, out list))
                    {
                        list = CreateList(type);
                        foreach (var item in customAttributeProvider.GetCustomAttributes(inherit))
                        {
                            if (item.GetType() == type || TypeExtensions.IsInheritFrom(item.GetType(), type))
                            {
                                list.Add(item);
                            }
                        }
                        _list_key.TryAdd(key, list);
                    }
                });
            }

            return(list);
        }
Exemple #3
0
 static ExportParameterKind GetExportKind(System.Reflection.ICustomAttributeProvider p)
 {
     foreach (ExportParameterAttribute a in p.GetCustomAttributes(typeof(ExportParameterAttribute), false))
     {
         return(a.Kind);
     }
     return(ExportParameterKind.Unspecified);
 }
        private static ExpectedStackAnalysisResultAttribute ExpectedStackAnalysisResultFor(ICustomAttributeProvider method)
        {
            foreach (Attribute attribute in method.GetCustomAttributes(false))
            {
                if (attribute.GetType() == typeof(ExpectedStackAnalysisResultAttribute))
                {
                    return((ExpectedStackAnalysisResultAttribute)attribute);
                }
            }

            return(new ExpectedStackAnalysisResultAttribute());
        }
Exemple #5
0
        /// <summary>
        /// returns all instances of the given custom attribute on a given object
        /// </summary>
        /// <param name="objectToGetAttributeFrom"></param>
        /// <param name="customAttribute"></param>
        /// <returns></returns>
        public static Attribute GetCustomAttribute(object objectToGetAttributeFrom, Type customAttribute)
        {
            //first, see if the object implemented this interface to override standard behavior
            System.Reflection.ICustomAttributeProvider attribProvider = objectToGetAttributeFrom as System.Reflection.ICustomAttributeProvider;
            if (attribProvider == null)
            {
                //if not, get it from its type
                attribProvider = (System.Reflection.ICustomAttributeProvider)objectToGetAttributeFrom.GetType();
            }

            object[] attribs = attribProvider.GetCustomAttributes(customAttribute, true);
            if (attribs != null && attribs.Length > 0)
            {
                //NOTE: important that we'll always use the first one in collection.
                //Our implementation of ICustomAttributeProvider knows about that and
                //relies on this behavior
                return(attribs[0] as Attribute);
            }

            return(null);
        }
Exemple #6
0
        static StackObject *GetCustomAttributes_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 3);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Boolean @inherit = ptr_of_this_method->Value == 1;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.Type @attributeType = (System.Type) typeof(System.Type).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
            System.Reflection.ICustomAttributeProvider instance_of_this_method = (System.Reflection.ICustomAttributeProvider) typeof(System.Reflection.ICustomAttributeProvider).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.GetCustomAttributes(@attributeType, @inherit);

            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Exemple #7
0
    static ObsoleteAttribute ReadAttribute(ICustomAttributeProvider attributeProvider)
    {
        var customAttributes = attributeProvider.GetCustomAttributes(typeof(ObsoleteAttribute), false);

        return((ObsoleteAttribute)customAttributes.First());
    }
Exemple #8
0
 static void ValidateHidden(ICustomAttributeProvider attributeProvider)
 {
     var customAttributes = attributeProvider.GetCustomAttributes(typeof(EditorBrowsableAttribute), false);
     var attribute = (EditorBrowsableAttribute) customAttributes.First();
     Assert.AreEqual(EditorBrowsableState.Advanced, attribute.State);
 }
Exemple #9
0
 static ObsoleteAttribute ReadAttribute(ICustomAttributeProvider attributeProvider)
 {
     var customAttributes = attributeProvider.GetCustomAttributes(typeof(ObsoleteAttribute), false);
     return (ObsoleteAttribute) customAttributes.First();
 }
		private static ExpectedStackAnalysisResultAttribute ExpectedStackAnalysisResultFor(ICustomAttributeProvider method)
		{
			foreach(Attribute attribute in method.GetCustomAttributes(false))
			{
				if (attribute.GetType() == typeof(ExpectedStackAnalysisResultAttribute))
				{
					return (ExpectedStackAnalysisResultAttribute) attribute;
				}
			}

			return new ExpectedStackAnalysisResultAttribute();
		}