IsDefined() public abstract method

public abstract IsDefined ( Type attributeType, bool inherit ) : bool
attributeType Type
inherit bool
return bool
        protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
        {
            JsonProperty property = base.CreateProperty(member, memberSerialization);

            if (member.IsDefined(typeof(DisableAuditingAttribute)) || member.IsDefined(typeof(JsonIgnoreAttribute)))
            {
                property.ShouldSerialize = instance => false;
            }

            return property;
        }
Example #2
0
 public static string GetOpenTypeDescription(MemberInfo typeElement)
 {
     Type typeToQuery;
      if (typeElement.MemberType == MemberTypes.TypeInfo || typeElement.MemberType == MemberTypes.NestedType)
      {
     typeToQuery = (Type)typeElement;
      }
      else
      {
     typeToQuery = typeElement.DeclaringType;
      }
      if (typeToQuery.IsDefined(typeof(OpenTypeAttribute), true))
      {
     OpenTypeAttribute mappingSpec =
        (OpenTypeAttribute) typeToQuery.GetCustomAttributes(typeof (OpenTypeAttribute), true)[0];
     if (!string.IsNullOrEmpty(mappingSpec.ResourceName))
     {
        ResourceManager manager = new ResourceManager(mappingSpec.ResourceName, typeToQuery.Assembly);
        string descr = manager.GetString(typeElement.Name);
        if (descr == null)
        {
           throw new MissingResourceItemException(typeElement.Name, mappingSpec.ResourceName,
                                                  typeToQuery.Assembly.FullName);
        }
        return descr;
     }
      }
      if (typeElement.IsDefined(typeof(DescriptionAttribute), true))
      {
     DescriptionAttribute descrAttr =
        (DescriptionAttribute) typeElement.GetCustomAttributes(typeof (DescriptionAttribute), true)[0];
     return descrAttr.Description;
      }
      return typeElement.Name;
 }
Example #3
0
 public static string GetOpenTypeName(MemberInfo typeElement)
 {
     if (typeElement.IsDefined(typeof(OpenTypeAttribute), true))
      {
     OpenTypeAttribute mappingSpec =
        (OpenTypeAttribute)typeElement.GetCustomAttributes(typeof(OpenTypeAttribute), true)[0];
     if (!string.IsNullOrEmpty(mappingSpec.MappedName))
     {
        return mappingSpec.MappedName;
     }
      }
      return typeElement.Name;
 }
        protected override Object CreateMemberInstance(Type memberType, MemberInfo memberInfo, ISearchContext searchContext)
        {
            var locator = CreateElementLocator(memberInfo);

            var isCached = memberInfo.IsDefined(typeof (CacheLookupAttribute), true);

            if (memberType.IsWebElement())
            {
                ILoader<IWebElement> elementLoader = _loaderFactory.CreateElementLoader(searchContext, locator, isCached);

                IWebElement elementProxy = 
                    typeof(HtmlFrame).IsAssignableFrom(memberType)
                        ? _proxyFactory.CreateFrameProxy(elementLoader)
                        : _proxyFactory.CreateElementProxy(elementLoader);

                if (typeof (IWebElement) == memberType || typeof (IHtmlElement) == memberType)
                {
                    return new HtmlElement(elementProxy);
                }

                return Create(memberType, elementProxy);
            }

            if (memberType.IsWebElementList())
            {
                var genericArguments = memberType.GetGenericArguments();

                if (genericArguments.Length == 0)
                {
                    return null;
                }

                var elementType = genericArguments[0];

                if (elementType == typeof (IWebElement) || elementType == typeof (IHtmlElement))
                {
                    elementType = typeof (HtmlElement);
                }

                return _proxyFactory.CreateListProxy(
                    elementType, _loaderFactory.CreateListLoader(elementType, searchContext, locator, isCached)
                );
            }

            return null;
        }
 static public int IsDefined(IntPtr l)
 {
     try {
         System.Reflection.MemberInfo self = (System.Reflection.MemberInfo)checkSelf(l);
         System.Type a1;
         checkType(l, 2, out a1);
         System.Boolean a2;
         checkType(l, 3, out a2);
         var ret = self.IsDefined(a1, a2);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #6
0
        private IEnumerable<TransformedName> MyTransformer(MemberInfo member, TransformReason reason) {
            if (member.IsDefined(typeof(OperatorMethodAttribute), false)) {
                Operators op;
                switch(member.Name) {
                    case "Add": op = Operators.Add; break;
                    case "Subtract": op = Operators.Subtract; break;
                    case "Divide": op = Operators.Divide; break;
                    case "Multiply": op = Operators.Multiply; break;
                    default: throw new NotImplementedException();
                }
                yield return new TransformedName(
                    new OperatorMapping(op, false, true, false),
                    ContextId.Empty);
            }

            yield return new TransformedName(member.Name, ContextId.Empty);
        }
        static StackObject *IsDefined_2(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), (CLR.Utils.Extensions.TypeFlags) 0);
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
            System.Reflection.MemberInfo instance_of_this_method = (System.Reflection.MemberInfo) typeof(System.Reflection.MemberInfo).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0);
            __intp.Free(ptr_of_this_method);

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

            __ret->ObjectType = ObjectTypes.Integer;
            __ret->Value      = result_of_this_method ? 1 : 0;
            return(__ret + 1);
        }
Example #8
0
		public static bool HasIgnoreAttribute( MemberInfo member )
		{
			return member.IsDefined( IgnoreType, false );
		}
		bool ExpandProperty(MemberInfo memberInfo)
		{
			return (memberInfo.IsDefined(typeof(Debugger.Tests.ExpandAttribute), true)) ||
			       ListContains(expandProperties, memberInfo);
		}
	void OutlineMemberAttribute (MemberInfo mi)
	{
		if (!mi.IsDefined (typeof (System.ObsoleteAttribute), false))
			return;
		var oa = mi.GetCustomAttributes (typeof (System.ObsoleteAttribute), false) [0] as ObsoleteAttribute;
		var msg = oa.Message;
		o.WriteLine ("[Obsolete{0}]", msg == null || msg == "" ? "" : string.Format ("(\"{0}\")", msg));
	}
        protected ColumnAttribute GetColumnAttribute(MemberInfo member)
        {
            if (member.IsDefined(typeof(ColumnAttribute), false))
            {
                return (ColumnAttribute)member.GetCustomAttributes(typeof(ColumnAttribute), false)[0];
            }

            return null;
        }
Example #12
0
        public static bool IsDefined(MemberInfo element, Type attributeType, bool inherit)
        {
            // Returns true if a custom attribute subclass of attributeType class/interface with inheritance walk
            if (element == null)
                throw new ArgumentNullException(nameof(element));

            if (attributeType == null)
                throw new ArgumentNullException(nameof(attributeType));
            
            if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
                throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass"));
            Contract.EndContractBlock();

            switch(element.MemberType)
            {
                case MemberTypes.Property:  
                    return InternalIsDefined((PropertyInfo)element, attributeType, inherit);

                case MemberTypes.Event: 
                    return InternalIsDefined((EventInfo)element, attributeType, inherit);

                default:
                    return element.IsDefined(attributeType, inherit);
            }

        }
Example #13
0
        /// <summary>
        /// Gets the collection of all specified object attributes for type as specified by type with option to serach parent
        /// </summary>
        /// <param name="attributeType">The attribute Type for which the custom attributes are to be returned.</param>
        /// <param name="type">the type on which the specified attribute is defined</param>
        /// <param name="searchParent">The attribute Type for which the custom attribute is to be returned.</param>
        /// <returns>
        /// Attribute as Object or null if not found.
        /// </returns>
        public static object[] GetAttributes(Type attributeType, MemberInfo type, bool searchParent)
        {
            if (type == null)
            {
                return null;
            }

            if (attributeType == null)
            {
                return null;
            }

            if (!(attributeType.IsSubclassOf(typeof(Attribute))))
            {
                return null;
            }

            if (type.IsDefined(attributeType, false))
            {
                return type.GetCustomAttributes(attributeType, searchParent);
            }

            return null;
        }
 internal static bool IsDefined(MemberInfo target, Type caType, bool inherit) {
   // JScript implements subclasses of MemberInfo which throw an exception when Module is
   // accessed. We know that none of these are from a ReflectionOnly assembly.
   Type t = target.GetType();
   if (t.Assembly == typeof(CustomAttribute).Assembly || !target.Module.Assembly.ReflectionOnly)
     return target.IsDefined(caType, inherit);
   return CustomAttribute.CheckForCustomAttribute(CustomAttributeData.GetCustomAttributes(target), caType);
 }
Example #15
0
 private static void AssertIsDeprecated(MemberInfo member)
 {
     Assert.NotNull(member);
     Assert.IsTrue(member.IsDefined(typeof(ObsoleteAttribute), false), "Member not obsolete: " + member);
 }
 public bool ShouldInject(MemberInfo member)
 {
     return member.IsDefined(typeof(PropertyInjection), true);
 }
        private AuthorizeAsAttribute GetAuthorizeAs(MemberInfo action)
        {
            if (!action.IsDefined(typeof(AuthorizeAsAttribute), false))
                return null;

            return action.GetCustomAttribute<AuthorizeAsAttribute>(false);
        }
		private static bool IsXmlSerializationDataMember(MemberInfo t)
		{
			if (t.IsDefined(typeof (XmlIgnoreAttribute), false))
				return false;

			if (t.MemberType != MemberTypes.Property)
				return false;

			var pi = t as PropertyInfo;
			if (pi != null && (!pi.CanRead || !pi.CanWrite))
				return false;

			return true;
		}
		bool IgnoreProperty(MemberInfo memberInfo)
		{
			return (memberInfo.IsDefined(typeof(Debugger.Tests.IgnoreAttribute), true)) ||
			       ListContains(ignoreProperties, memberInfo);
		}
 private bool IsExtensionMethod(MemberInfo memberInfo)
 {
     return memberInfo.IsDefined(typeof (ExtensionAttribute), true);
 }
Example #21
0
        /// <summary>
        /// Gets the specified object attributes for type as specified by type with option to serach parent
        /// </summary>
        /// <param name="attributeType">The attribute Type for which the custom attributes are to be returned.</param>
        /// <param name="type">the type on which the specified attribute is defined</param>
        /// <param name="searchParent">if set to <see langword="true"/> [search parent].</param>
        /// <returns>
        /// Attribute as Object or null if not found.
        /// </returns>
        public static object GetAttribute(Type attributeType, MemberInfo type, bool searchParent)
        {
            if (attributeType == null)
            {
                return null;
            }

            if (type == null)
            {
                return null;
            }

            if (!(attributeType.IsSubclassOf(typeof(Attribute))))
            {
                return null;
            }

            if (type.IsDefined(attributeType, searchParent))
            {
                object[] attributes = type.GetCustomAttributes(attributeType, searchParent);

                if (attributes.Length > 0)
                {
                    return attributes[0];
                }
            }

            return null;
        }
		private bool IsXmlIgnore(MemberInfo member) {
			return member.IsDefined(typeof(XmlIgnoreAttribute), false);
		}
Example #23
0
        /// <summary>
        /// Get The Type Description using Description Attribute and 
        /// objects to format the Description.
        /// </summary>
        /// <param name="member"> Specified Member for which Info is Required</param>
        /// <param name="args">An Object array containing zero or more objects to format.</param>
        /// <returns>return <see cref="String.Empty"/> if DescriptionAttribute is 
        /// not found or return type description</returns>
        public static string GetDescription(MemberInfo member, params object[] args)
        {
            string text1;

            if (member == null)
            {
                throw new ArgumentNullException("member");
            }

            if (member.IsDefined(typeof(DescriptionAttribute), false))
            {
                DescriptionAttribute[] attributes =
                    (DescriptionAttribute[])member.GetCustomAttributes(typeof(DescriptionAttribute), false);
                text1 = attributes[0].Description;
            }
            else
            {
                return String.Empty;
            }

            if ((args != null) && (args.Length > 0))
            {
                return String.Format(null, text1, args);
            }
            return text1;
        }
 public static bool IsDefined(MemberInfo element, Type attributeType, bool inherit)
 {
     if (element == null)
     {
         throw new ArgumentNullException("element");
     }
     if (attributeType == null)
     {
         throw new ArgumentNullException("attributeType");
     }
     if (!attributeType.IsSubclassOf(typeof(Attribute)) && (attributeType != typeof(Attribute)))
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_MustHaveAttributeBaseClass"));
     }
     MemberTypes memberType = element.MemberType;
     if (memberType != MemberTypes.Event)
     {
         if (memberType == MemberTypes.Property)
         {
             return InternalIsDefined((PropertyInfo) element, attributeType, inherit);
         }
         return element.IsDefined(attributeType, inherit);
     }
     return InternalIsDefined((EventInfo) element, attributeType, inherit);
 }
 public static bool IsDefined(MemberInfo methodInfo, Type attributeType, bool inherit)
 {
     return methodInfo.IsDefined(attributeType, inherit);
 }
Example #26
0
        public static MemberTracker FromMemberInfo(MemberInfo member, Type extending) {
            ContractUtils.RequiresNotNull(member, "member");

            lock (_trackers) {
                MemberTracker res;
                MemberKey key = new MemberKey(member, extending);
                if (_trackers.TryGetValue(key, out res)) return res;

                switch (member.MemberType) {
                    case MemberTypes.Constructor: res = new ConstructorTracker((ConstructorInfo)member); break;
                    case MemberTypes.Event: res = new EventTracker((EventInfo)member); break;
                    case MemberTypes.Field: res = new FieldTracker((FieldInfo)member); break;
                    case MemberTypes.Method:
                        MethodInfo mi = (MethodInfo)member;
                        if (extending != null) {
                            res = new ExtensionMethodTracker(mi, member.IsDefined(typeof(StaticExtensionMethodAttribute), false), extending);
                        } else {
                            res = new MethodTracker(mi);
                        }
                        break;
                    case MemberTypes.TypeInfo:
                    case MemberTypes.NestedType: res = new NestedTypeTracker((Type)member); break;
                    case MemberTypes.Property: res = new ReflectedPropertyTracker((PropertyInfo)member); break;
                    default: throw Error.UnknownMemberType(member.MemberType);
                }

                _trackers[key] = res;
                return res;
            }
        }
Example #27
0
 /// <summary>
 /// Returns true if given method has UnitOfWorkAttribute attribute.
 /// </summary>
 /// <param name="methodInfo">Method info to check</param>
 public static bool HasUnitOfWorkAttribute(MemberInfo methodInfo)
 {
     return methodInfo.IsDefined(typeof(RepositoryAOPAttribute), true);
 }
Example #28
0
		public static bool HasExplicitAttribute(MemberInfo member)
		{
			return member.IsDefined( ExplicitType, false );
		}
        protected RelationshipAttribute GetRelationshipAttribute(MemberInfo member)
        {
            if (member.IsDefined(typeof(RelationshipAttribute), false))
            {
                return (RelationshipAttribute)member.GetCustomAttributes(typeof(RelationshipAttribute), false)[0];
            }

            return null;
        }
Example #30
0
		public static bool HasCategoryAttribute(MemberInfo member) 
		{
			return member.IsDefined( CategoryType, false );
		}
	bool ShowMember (MemberInfo mi)
	{
		if (mi.MemberType == MemberTypes.Constructor && ((MethodBase) mi).IsStatic)
			return false;
		
		if (show_private)
			return true;

		if (filter_obsolete && mi.IsDefined (typeof (ObsoleteAttribute), false))
			return false;
		
		switch (mi.MemberType) {
		case MemberTypes.Constructor:
		case MemberTypes.Method:
			MethodBase mb = mi as MethodBase;
		
			if (mb.IsFamily || mb.IsPublic || mb.IsFamilyOrAssembly)
				return true;
			
			if (MethodIsExplicitIfaceImpl (mb))
				return true;
					
			return false;
		
		
		case MemberTypes.Field:
			FieldInfo fi = mi as FieldInfo;
		
			if (fi.IsFamily || fi.IsPublic || fi.IsFamilyOrAssembly)
				return true;
			
			return false;
		
		
		case MemberTypes.NestedType:
		case MemberTypes.TypeInfo:
			Type t = mi as Type;
		
			switch (t.Attributes & TypeAttributes.VisibilityMask){
			case TypeAttributes.Public:
			case TypeAttributes.NestedPublic:
			case TypeAttributes.NestedFamily:
			case TypeAttributes.NestedFamORAssem:
				return true;
			}
			
			return false;
		}
		
		// What am I !!!
		return true;
	}
 /// <summary>
 /// Returns true if the property has the SerializableProperty attribute
 /// </summary>
 /// <param name="prop">Property to check</param>
 /// <returns>True if the property has the attribute</returns>
 public static bool HasAttribute(MemberInfo prop)
 {
     return prop.IsDefined(typeof(SerializablePropertyAttribute), true);
 }