Imported Upstream version 4.0.1

Former-commit-id: 757121caeaad523350be5330f0a3ecc891c70fb8
This commit is contained in:
Jo Shields
2015-04-26 19:10:23 +01:00
parent 7fce50ac98
commit c54b0bda4e
252 changed files with 16715 additions and 1176 deletions

View File

@ -20,10 +20,101 @@ namespace System {
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(_Attribute))]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class Attribute : _Attribute
public abstract partial class Attribute : _Attribute
{
#region Private Statics
#if MONO
static Attribute[] InternalGetCustomAttributes (PropertyInfo element, Type type, bool inherit)
{
return (Attribute []) MonoCustomAttrs.GetCustomAttributes (element, type, inherit);
}
static Attribute[] InternalGetCustomAttributes (EventInfo element, Type type, bool inherit)
{
return (Attribute []) MonoCustomAttrs.GetCustomAttributes (element, type, inherit);
}
static Attribute[] InternalParamGetCustomAttributes (ParameterInfo parameter, Type attributeType, bool inherit)
{
if (parameter.Member.MemberType != MemberTypes.Method)
return null;
var method = (MethodInfo) parameter.Member;
var definition = method.GetBaseDefinition ();
if (method == definition)
return (Attribute []) parameter.GetCustomAttributes (typeof(Attribute), inherit);
var types = new List<Type> ();
var custom_attributes = new List<Attribute> ();
if (attributeType == null)
attributeType = typeof (Attribute);
while (true) {
var param = method.GetParametersInternal () [parameter.Position];
var param_attributes = (Attribute []) param.GetCustomAttributes (attributeType, false);
foreach (var param_attribute in param_attributes) {
var param_type = param_attribute.GetType ();
if (types.Contains (param_type))
continue;
types.Add (param_type);
custom_attributes.Add (param_attribute);
}
var base_method = method.GetBaseMethod ();
if (base_method == method)
break;
method = base_method;
}
var attributes = (Attribute []) Array.CreateInstance (attributeType, custom_attributes.Count);
custom_attributes.CopyTo (attributes, 0);
return attributes;
}
static bool InternalIsDefined (PropertyInfo element, Type attributeType, bool inherit)
{
return MonoCustomAttrs.IsDefined (element, attributeType, inherit);
}
static bool InternalIsDefined (EventInfo element, Type attributeType, bool inherit)
{
return MonoCustomAttrs.IsDefined (element, attributeType, inherit);
}
static bool InternalParamIsDefined (ParameterInfo parameter, Type attributeType, bool inherit)
{
if (parameter.IsDefined (attributeType, inherit))
return true;
if (!inherit)
return false;
var member = parameter.Member;
if (member.MemberType != MemberTypes.Method)
return false;
var method = ((MethodInfo) member).GetBaseMethod ();
while (true) {
var param = method.GetParametersInternal () [parameter.Position];
if (param.IsDefined (attributeType, false))
return true;
var base_method = method.GetBaseMethod ();
if (base_method == method)
break;
method = base_method;
}
return false;
}
#else
#region PropertyInfo
private static Attribute[] InternalGetCustomAttributes(PropertyInfo element, Type type, bool inherit)
{
@ -414,7 +505,7 @@ namespace System {
return (Attribute[])Array.UnsafeCreateInstance(elementType, elementCount);
}
#endregion
#endif
#endregion
#region Public Statics