ContextualParameterInfo
A parameter info with contextual information.
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace Namotion.Reflection
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public class ContextualParameterInfo : ICustomAttributeProvider
{
[System.Runtime.CompilerServices.Nullable(2)]
private string _name;
public ParameterInfo ParameterInfo { get; }
public ContextualType ParameterType { get; }
public Nullability Nullability => ParameterType.Nullability;
public string Name => _name ?? (_name = ParameterInfo.Name);
internal ContextualParameterInfo(ParameterInfo parameterInfo, ref int nullableFlagsIndex, [System.Runtime.CompilerServices.Nullable(2)] byte[] nullableFlags)
{
ParameterInfo = parameterInfo;
NullableFlagsSource[] customAttributeProviders = (!parameterInfo.Member.DeclaringType.IsNested) ? new NullableFlagsSource[2] {
NullableFlagsSource.Create(parameterInfo.Member),
NullableFlagsSource.Create(parameterInfo.Member.DeclaringType, parameterInfo.Member.DeclaringType.GetTypeInfo().Assembly)
} : new NullableFlagsSource[3] {
NullableFlagsSource.Create(parameterInfo.Member),
NullableFlagsSource.Create(parameterInfo.Member.DeclaringType, null),
NullableFlagsSource.Create(parameterInfo.Member.DeclaringType.DeclaringType, parameterInfo.Member.DeclaringType.GetTypeInfo().Assembly)
};
ParameterType = new ContextualType(parameterInfo.ParameterType, this, null, ref nullableFlagsIndex, nullableFlags, customAttributeProviders);
}
public override string ToString()
{
return Name + " (Parameter) - " + base.ToString();
}
public object[] GetCustomAttributes(Type attributeType, bool inherit)
{
return ParameterInfo.GetCustomAttributes(attributeType, inherit);
}
public object[] GetCustomAttributes(bool inherit)
{
return ParameterInfo.GetCustomAttributes(inherit);
}
public bool IsDefined(Type attributeType, bool inherit)
{
return ParameterInfo.IsDefined(attributeType, inherit);
}
}
}