Files
2026-06-04 11:42:34 +02:00

206 lines
9.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace System.Reflection
{
/// <summary>Provides access to custom attribute data for assemblies, modules, types, members and parameters that are loaded into the reflection-only context.</summary>
// Token: 0x02000239 RID: 569
[ComVisible(true)]
[Serializable]
public sealed class CustomAttributeData
{
// Token: 0x06001DD5 RID: 7637 RVA: 0x0006FCE8 File Offset: 0x0006DEE8
internal CustomAttributeData(ConstructorInfo ctorInfo, object[] ctorArgs, object[] namedArgs)
{
this.ctorInfo = ctorInfo;
this.ctorArgs = Array.AsReadOnly<CustomAttributeTypedArgument>((ctorArgs == null) ? new CustomAttributeTypedArgument[0] : CustomAttributeData.UnboxValues<CustomAttributeTypedArgument>(ctorArgs));
this.namedArgs = Array.AsReadOnly<CustomAttributeNamedArgument>((namedArgs == null) ? new CustomAttributeNamedArgument[0] : CustomAttributeData.UnboxValues<CustomAttributeNamedArgument>(namedArgs));
}
/// <summary>Returns a <see cref="T:System.Reflection.ConstructorInfo" /> object representing the constructor that would have initialized the custom attribute.</summary>
/// <returns>A <see cref="T:System.Reflection.ConstructorInfo" /> object representing the constructor that would have initialized the custom attribute represented by the current instance of the <see cref="T:System.Reflection.CustomAttributeData" /> class.</returns>
// Token: 0x1700055E RID: 1374
// (get) Token: 0x06001DD6 RID: 7638 RVA: 0x0006FD48 File Offset: 0x0006DF48
[ComVisible(true)]
public ConstructorInfo Constructor
{
get
{
return this.ctorInfo;
}
}
/// <summary>Gets the list of positional arguments specified for the attribute instance represented by the <see cref="T:System.Reflection.CustomAttributeData" /> object.</summary>
/// <returns>An <see cref="T:System.Collections.Generic.IList`1" /> of <see cref="T:System.Reflection.CustomAttributeTypedArgument" /> structures representing the positional arguments specified for the custom attribute instance.</returns>
// Token: 0x1700055F RID: 1375
// (get) Token: 0x06001DD7 RID: 7639 RVA: 0x0006FD50 File Offset: 0x0006DF50
[ComVisible(true)]
public IList<CustomAttributeTypedArgument> ConstructorArguments
{
get
{
return this.ctorArgs;
}
}
/// <summary>Gets the list of named arguments specified for the attribute instance represented by the <see cref="T:System.Reflection.CustomAttributeData" /> object.</summary>
/// <returns>An <see cref="T:System.Collections.Generic.IList`1" /> of <see cref="T:System.Reflection.CustomAttributeNamedArgument" /> structures representing the named arguments specified for the custom attribute instance.</returns>
// Token: 0x17000560 RID: 1376
// (get) Token: 0x06001DD8 RID: 7640 RVA: 0x0006FD58 File Offset: 0x0006DF58
public IList<CustomAttributeNamedArgument> NamedArguments
{
get
{
return this.namedArgs;
}
}
/// <summary>Returns a list of <see cref="T:System.Reflection.CustomAttributeData" /> objects representing data about the attributes that have been applied to the target assembly.</summary>
/// <returns>An <see cref="T:System.Collections.Generic.IList`1" /> of <see cref="T:System.Reflection.CustomAttributeData" /> objects representing data about the attributes that have been applied to the target assembly.</returns>
/// <param name="target">The assembly whose custom attribute data is to be retrieved.</param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="target" /> is null.</exception>
// Token: 0x06001DD9 RID: 7641 RVA: 0x0006FD60 File Offset: 0x0006DF60
public static IList<CustomAttributeData> GetCustomAttributes(Assembly target)
{
return MonoCustomAttrs.GetCustomAttributesData(target);
}
/// <summary>Returns a list of <see cref="T:System.Reflection.CustomAttributeData" /> objects representing data about the attributes that have been applied to the target member.</summary>
/// <returns>An <see cref="T:System.Collections.Generic.IList`1" /> of <see cref="T:System.Reflection.CustomAttributeData" /> objects representing data about the attributes that have been applied to the target member.</returns>
/// <param name="target">A <see cref="T:System.Reflection.MemberInfo" /> object representing the member whose attribute data is to be retrieved.</param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="target" /> is null.</exception>
// Token: 0x06001DDA RID: 7642 RVA: 0x0006FD68 File Offset: 0x0006DF68
public static IList<CustomAttributeData> GetCustomAttributes(MemberInfo target)
{
return MonoCustomAttrs.GetCustomAttributesData(target);
}
/// <summary>Returns a list of <see cref="T:System.Reflection.CustomAttributeData" /> objects representing data about the attributes that have been applied to the target module.</summary>
/// <returns>An <see cref="T:System.Collections.Generic.IList`1" /> of <see cref="T:System.Reflection.CustomAttributeData" /> objects representing data about the attributes that have been applied to the target module.</returns>
/// <param name="target">The module whose custom attribute data is to be retrieved.</param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="target" /> is null.</exception>
// Token: 0x06001DDB RID: 7643 RVA: 0x0006FD70 File Offset: 0x0006DF70
public static IList<CustomAttributeData> GetCustomAttributes(Module target)
{
return MonoCustomAttrs.GetCustomAttributesData(target);
}
/// <summary>Returns a list of <see cref="T:System.Reflection.CustomAttributeData" /> objects representing data about the attributes that have been applied to the target parameter.</summary>
/// <returns>An <see cref="T:System.Collections.Generic.IList`1" /> of <see cref="T:System.Reflection.CustomAttributeData" /> objects representing data about the attributes that have been applied to the target parameter.</returns>
/// <param name="target">A <see cref="T:System.Reflection.ParameterInfo" /> object representing the parameter whose attribute data is to be retrieved.</param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="target" /> is null.</exception>
// Token: 0x06001DDC RID: 7644 RVA: 0x0006FD78 File Offset: 0x0006DF78
public static IList<CustomAttributeData> GetCustomAttributes(ParameterInfo target)
{
return MonoCustomAttrs.GetCustomAttributesData(target);
}
/// <summary>Returns a string representation of the custom attribute.</summary>
/// <returns>A string value that represents the custom attribute.</returns>
// Token: 0x06001DDD RID: 7645 RVA: 0x0006FD80 File Offset: 0x0006DF80
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("[" + this.ctorInfo.DeclaringType.FullName + "(");
for (int i = 0; i < this.ctorArgs.Count; i++)
{
stringBuilder.Append(this.ctorArgs[i].ToString());
if (i + 1 < this.ctorArgs.Count)
{
stringBuilder.Append(", ");
}
}
if (this.namedArgs.Count > 0)
{
stringBuilder.Append(", ");
}
for (int j = 0; j < this.namedArgs.Count; j++)
{
stringBuilder.Append(this.namedArgs[j].ToString());
if (j + 1 < this.namedArgs.Count)
{
stringBuilder.Append(", ");
}
}
stringBuilder.AppendFormat(")]", new object[0]);
return stringBuilder.ToString();
}
// Token: 0x06001DDE RID: 7646 RVA: 0x0006FE9C File Offset: 0x0006E09C
private static T[] UnboxValues<T>(object[] values)
{
T[] array = new T[values.Length];
for (int i = 0; i < values.Length; i++)
{
array[i] = (T)((object)values[i]);
}
return array;
}
/// <param name="obj"></param>
// Token: 0x06001DDF RID: 7647 RVA: 0x0006FED8 File Offset: 0x0006E0D8
public override bool Equals(object obj)
{
CustomAttributeData customAttributeData = obj as CustomAttributeData;
if (customAttributeData == null || customAttributeData.ctorInfo != this.ctorInfo || customAttributeData.ctorArgs.Count != this.ctorArgs.Count || customAttributeData.namedArgs.Count != this.namedArgs.Count)
{
return false;
}
for (int i = 0; i < this.ctorArgs.Count; i++)
{
if (this.ctorArgs[i].Equals(customAttributeData.ctorArgs[i]))
{
return false;
}
}
for (int j = 0; j < this.namedArgs.Count; j++)
{
bool flag = false;
for (int k = 0; k < customAttributeData.namedArgs.Count; k++)
{
if (this.namedArgs[j].Equals(customAttributeData.namedArgs[k]))
{
flag = true;
break;
}
}
if (!flag)
{
return false;
}
}
return true;
}
// Token: 0x06001DE0 RID: 7648 RVA: 0x00070000 File Offset: 0x0006E200
public override int GetHashCode()
{
int num = this.ctorInfo.GetHashCode() << 16;
for (int i = 0; i < this.ctorArgs.Count; i++)
{
num += num ^ (7 + this.ctorArgs[i].GetHashCode() << i * 4);
}
for (int j = 0; j < this.namedArgs.Count; j++)
{
num += this.namedArgs[j].GetHashCode() << 5;
}
return num;
}
// Token: 0x04000A21 RID: 2593
private ConstructorInfo ctorInfo;
// Token: 0x04000A22 RID: 2594
private IList<CustomAttributeTypedArgument> ctorArgs;
// Token: 0x04000A23 RID: 2595
private IList<CustomAttributeNamedArgument> namedArgs;
}
}