// dnlib: See LICENSE.txt for more info
namespace dnlib.DotNet {
///
/// Generic parameter context
///
public readonly struct GenericParamContext {
///
/// Type context
///
public readonly TypeDef Type;
///
/// Method context
///
public readonly MethodDef Method;
///
/// true if and are both null
///
public bool IsEmpty => Type is null && Method is null;
///
/// Creates a new instance and initializes the
/// field to 's
/// and the field to .
///
/// Method
/// A new instance
public static GenericParamContext Create(MethodDef method) {
if (method is null)
return new GenericParamContext();
return new GenericParamContext(method.DeclaringType, method);
}
///
/// Creates a new instance and initializes the
/// field to and the field
/// to null
///
/// Type
/// A new instance
public static GenericParamContext Create(TypeDef type) => new GenericParamContext(type);
///
/// Constructor
///
/// Type context
public GenericParamContext(TypeDef type) {
Type = type;
Method = null;
}
///
/// Constructor. The field is set to null and NOT to
/// 's . Use
/// if you want that behavior.
///
/// Method context
public GenericParamContext(MethodDef method) {
Type = null;
Method = method;
}
///
/// Constructor
///
/// Type context
/// Method context
public GenericParamContext(TypeDef type, MethodDef method) {
Type = type;
Method = method;
}
}
}