2 Copyright (C) 2009 Jeroen Frijters
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
26 using System.Collections.Generic;
29 namespace IKVM.Reflection
31 // disable warnings that complain about us having == and != operators without also overriding Equals/GetHashCode,
32 // this is intentional because most subtypes use reference equality
33 #pragma warning disable 660, 661
34 public abstract class MemberInfo : ICustomAttributeProvider
36 public abstract string Name { get; }
37 public abstract Type DeclaringType { get; }
38 public abstract MemberTypes MemberType { get; }
40 public virtual int MetadataToken
42 get { throw new NotSupportedException(); }
45 public abstract Module Module
50 public bool IsDefined(Type attributeType, bool inherit)
52 return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit).Count != 0;
55 public IList<CustomAttributeData> __GetCustomAttributes(Type attributeType, bool inherit)
57 return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit);
60 public static bool operator ==(MemberInfo m1, MemberInfo m2)
62 return ReferenceEquals(m1, m2) || (!ReferenceEquals(m1, null) && m1.Equals(m2));
65 public static bool operator !=(MemberInfo m1, MemberInfo m2)
70 internal virtual IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
72 return this.Module.GetCustomAttributes(this.MetadataToken, attributeType);
75 internal static bool BindingFlagsMatch(bool state, BindingFlags flags, BindingFlags trueFlag, BindingFlags falseFlag)
77 return (state && (flags & trueFlag) == trueFlag)
78 || (!state && (flags & falseFlag) == falseFlag);