本文整理汇总了C#中GenericParameterAttributes类的典型用法代码示例。如果您正苦于以下问题:C# GenericParameterAttributes类的具体用法?C# GenericParameterAttributes怎么用?C# GenericParameterAttributes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GenericParameterAttributes类属于命名空间,在下文中一共展示了GenericParameterAttributes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenericParamRow
/// <summary>
/// Initializes a new instance of the <see cref="GenericParamRow" /> struct.
/// </summary>
/// <param name="number">The number.</param>
/// <param name="flags">The flags.</param>
/// <param name="owner">The owner.</param>
/// <param name="nameString">The name string.</param>
public GenericParamRow(ushort number, GenericParameterAttributes flags, Token owner, HeapIndexToken nameString)
{
Number = number;
Flags = flags;
Owner = owner;
NameString = nameString;
}
示例2: GenericParameterStructure
public GenericParameterStructure(string name, GenericParameterAttributes attr, IReadOnlyList<CilStructure> constant, Type info = null)
{
GenericAttributes = attr;
Constraints = constant;
Info = info;
base.Initialize(name, 0);
}
示例3: GenericParamRow
/// <summary>
/// Initializes a new instance of the <see cref="GenericParamRow"/> struct.
/// </summary>
/// <param name="number">The number.</param>
/// <param name="flags">The flags.</param>
/// <param name="owner">The owner table idx.</param>
/// <param name="nameStringIdx">The name string idx.</param>
public GenericParamRow(ushort number, GenericParameterAttributes flags, Token owner, HeapIndexToken nameStringIdx)
{
this.number = number;
this.flags = flags;
this.owner = owner;
this.nameStringIdx = nameStringIdx;
}
示例4: GenericParameter
public GenericParameter(string name, ushort index, GenericParameterAttributes attributes, IGenericParamProvider owner)
: base(new MetaDataRow(index, (ushort)attributes, 0U, 0U))
{
this._name = name;
if (string.IsNullOrEmpty(name))
{
this._name = string.Format("{0}{1}", owner.ParamType == GenericParamType.Type ? "!" : "!!", index);
}
this._owner = owner;
}
示例5: SetGenericParameterAttributes
public void SetGenericParameterAttributes(GenericParameterAttributes genericParameterAttributes)
{
TypeBuilder type = Helpers.DynamicType(TypeAttributes.Public);
string[] typeParamNames = new string[] { "TFirst" };
GenericTypeParameterBuilder[] typeParams = type.DefineGenericParameters(typeParamNames);
GenericTypeParameterBuilder firstTypeParam = typeParams[0];
firstTypeParam.SetGenericParameterAttributes(genericParameterAttributes);
Assert.Equal(genericParameterAttributes, firstTypeParam.GenericParameterAttributes);
}
示例6: ReflectionConstraints
private ReflectionConstraints (string name, Type [] constraints, GenericParameterAttributes attrs)
{
this.name = name;
this.attrs = attrs;
if ((constraints.Length > 0) && !constraints [0].IsInterface) {
class_constraint = constraints [0];
iface_constraints = new Type [constraints.Length - 1];
Array.Copy (constraints, 1, iface_constraints, 0, constraints.Length - 1);
} else
iface_constraints = constraints;
if (HasValueTypeConstraint)
base_type = TypeManager.value_type;
else if (class_constraint != null)
base_type = class_constraint;
else
base_type = TypeManager.object_type;
}
示例7: PETypeParameterSymbol
private PETypeParameterSymbol(
PEModuleSymbol moduleSymbol,
Symbol definingSymbol,
ushort ordinal,
GenericParameterHandle handle)
{
Debug.Assert((object)moduleSymbol != null);
Debug.Assert((object)definingSymbol != null);
Debug.Assert(ordinal >= 0);
Debug.Assert(!handle.IsNil);
_containingSymbol = definingSymbol;
GenericParameterAttributes flags = 0;
try
{
moduleSymbol.Module.GetGenericParamPropsOrThrow(handle, out _name, out flags);
}
catch (BadImageFormatException)
{
if ((object)_name == null)
{
_name = string.Empty;
}
//_lazyBoundsErrorInfo = new CSDiagnosticInfo(ErrorCode.ERR_BindToBogus, this);
}
// Clear the '.ctor' flag if both '.ctor' and 'valuetype' are
// set since '.ctor' is redundant in that case.
_flags = ((flags & GenericParameterAttributes.NotNullableValueTypeConstraint) == 0) ? flags : (flags & ~GenericParameterAttributes.DefaultConstructorConstraint);
_ordinal = ordinal;
_handle = handle;
}
示例8: MatchesConstraints
private static bool MatchesConstraints(GenericParameterAttributes attributes, Type[] constraints, Type target)
{
if (constraints.Length == 0 && attributes == GenericParameterAttributes.None)
{
return true;
}
for (int i = 0; i < constraints.Length; i++)
{
if (!constraints[i].IsAssignableFrom(target))
{
return false;
}
}
if (attributes.HasFlag(GenericParameterAttributes.DefaultConstructorConstraint))
{
if (target.GetConstructor(new Type[0]) == null) return false;
}
if (attributes.HasFlag(GenericParameterAttributes.ReferenceTypeConstraint))
{
if (!(target.IsClass || target.IsInterface)) return false;
}
if (attributes.HasFlag(GenericParameterAttributes.NotNullableValueTypeConstraint))
{
if (!(target.IsValueType && !target.IsNullable())) return false;
}
return true;
}
示例9: Read
} // Read
public static uint Read(this NativeReader reader, uint offset, out GenericParameterAttributes value)
{
uint ivalue;
offset = reader.DecodeUnsigned(offset, out ivalue);
value = (GenericParameterAttributes)ivalue;
return offset;
} // Read
示例10: SetGenericParameterAttributes
public void SetGenericParameterAttributes (GenericParameterAttributes genericParameterAttributes)
{
this.attrs = genericParameterAttributes;
}
示例11: SetGenParamAttributes
internal void SetGenParamAttributes(GenericParameterAttributes genericParameterAttributes)
{
m_genParamAttributes = genericParameterAttributes;
}
示例12: ValidateGenericParamTable
public void ValidateGenericParamTable()
{
// AppCS - 7
var expNames = new string[] { "V", "CT", "CO", "T", "CT1", "CO1", "T1" };
var expFlags = new GenericParameterAttributes[]
{
/* 4 */
GenericParameterAttributes.ReferenceTypeConstraint,
/* 6 */ GenericParameterAttributes.ReferenceTypeConstraint | GenericParameterAttributes.Contravariant,
/* 1 */ GenericParameterAttributes.Covariant,
/* 0 */ GenericParameterAttributes.None,
/* 4 */ GenericParameterAttributes.ReferenceTypeConstraint,
/* 0x10 */ GenericParameterAttributes.DefaultConstructorConstraint, // Mask 001C
/* 0 */ GenericParameterAttributes.None
};
var expNumber = new ushort[] { 0, 0, 0, 0, 0, 0, 0 };
var expTypeTokens = new int[] { 0x06000003, 0x02000004, 0x02000005, 0x02000006, 0x02000007, 0x02000008, 0x02000009, };
// ---------------------------------------------------
// ModuleCS01 - 5
var modNames = new string[] { "T", "T", "R", "T", "X" };
var modFlags = new GenericParameterAttributes[]
{
/* 0 */
GenericParameterAttributes.None,
/* 4 */
GenericParameterAttributes.ReferenceTypeConstraint,
/* 4 */ GenericParameterAttributes.ReferenceTypeConstraint,
/* 4 */ GenericParameterAttributes.ReferenceTypeConstraint,
/* 0 */ GenericParameterAttributes.None
};
var modNumber = new ushort[] { 0, 0, 1, 0, 0 };
var modTypeTokens = new int[] { 0x02000006, 0x02000007, 0x02000007, 0x02000008, 0x06000025, };
var reader = GetMetadataReader(NetModule.AppCS);
// Validity Rules
Assert.Equal(expNames.Length, reader.GenericParamTable.NumberOfRows);
for (int i = 0; i < reader.GenericParamTable.NumberOfRows; i++)
{
var handle = GenericParameterHandle.FromRowId(i + 1);
Assert.Equal(expNames[i], reader.GetString(reader.GenericParamTable.GetName(handle)));
Assert.Equal(expFlags[i], reader.GenericParamTable.GetFlags(handle));
Assert.Equal(expNumber[i], reader.GenericParamTable.GetNumber(handle));
Assert.Equal(expTypeTokens[i], reader.GenericParamTable.GetOwner(handle).Token);
}
// =======================================
reader = GetMetadataReader(NetModule.ModuleCS01, true);
// Validity Rules
Assert.Equal(modNames.Length, reader.GenericParamTable.NumberOfRows);
for (int i = 0; i < reader.GenericParamTable.NumberOfRows; i++)
{
var handle = GenericParameterHandle.FromRowId(i + 1);
Assert.Equal(modNames[i], reader.GetString(reader.GenericParamTable.GetName(handle)));
Assert.Equal(modFlags[i], reader.GenericParamTable.GetFlags(handle));
Assert.Equal(modNumber[i], reader.GenericParamTable.GetNumber(handle));
Assert.Equal(modTypeTokens[i], reader.GenericParamTable.GetOwner(handle).Token);
}
}
示例13: Resolve
/// <summary>
/// Resolve the constraints - but only resolve things into Expression's, not
/// into actual types.
/// </summary>
public bool Resolve (IResolveContext ec)
{
if (resolved)
return true;
iface_constraints = new ArrayList (2); // TODO: Too expensive allocation
type_param_constraints = new ArrayList ();
foreach (object obj in constraints) {
if (HasConstructorConstraint) {
Report.Error (401, loc,
"The new() constraint must be the last constraint specified");
return false;
}
if (obj is SpecialConstraint) {
SpecialConstraint sc = (SpecialConstraint) obj;
if (sc == SpecialConstraint.Constructor) {
if (!HasValueTypeConstraint) {
attrs |= GenericParameterAttributes.DefaultConstructorConstraint;
continue;
}
Report.Error (451, loc, "The `new()' constraint " +
"cannot be used with the `struct' constraint");
return false;
}
if ((num_constraints > 0) || HasReferenceTypeConstraint || HasValueTypeConstraint) {
Report.Error (449, loc, "The `class' or `struct' " +
"constraint must be the first constraint specified");
return false;
}
if (sc == SpecialConstraint.ReferenceType)
attrs |= GenericParameterAttributes.ReferenceTypeConstraint;
else
attrs |= GenericParameterAttributes.NotNullableValueTypeConstraint;
continue;
}
int errors = Report.Errors;
FullNamedExpression fn = ((Expression) obj).ResolveAsTypeStep (ec, false);
if (fn == null) {
if (errors != Report.Errors)
return false;
NamespaceEntry.Error_NamespaceNotFound (loc, ((Expression)obj).GetSignatureForError ());
return false;
}
TypeExpr expr;
GenericTypeExpr cexpr = fn as GenericTypeExpr;
if (cexpr != null) {
expr = cexpr.ResolveAsBaseTerminal (ec, false);
} else
expr = ((Expression) obj).ResolveAsTypeTerminal (ec, false);
if ((expr == null) || (expr.Type == null))
return false;
if (!ec.GenericDeclContainer.IsAccessibleAs (fn.Type)) {
Report.SymbolRelatedToPreviousError (fn.Type);
Report.Error (703, loc,
"Inconsistent accessibility: constraint type `{0}' is less accessible than `{1}'",
fn.GetSignatureForError (), ec.GenericDeclContainer.GetSignatureForError ());
return false;
}
TypeParameterExpr texpr = expr as TypeParameterExpr;
if (texpr != null)
type_param_constraints.Add (expr);
else if (expr.IsInterface)
iface_constraints.Add (expr);
else if (class_constraint != null || iface_constraints.Count != 0) {
Report.Error (406, loc,
"The class type constraint `{0}' must be listed before any other constraints. Consider moving type constraint to the beginning of the constraint list",
expr.GetSignatureForError ());
return false;
} else if (HasReferenceTypeConstraint || HasValueTypeConstraint) {
Report.Error (450, loc, "`{0}': cannot specify both " +
"a constraint class and the `class' " +
"or `struct' constraint", expr.GetSignatureForError ());
return false;
} else
class_constraint = expr;
num_constraints++;
}
ArrayList list = new ArrayList ();
foreach (TypeExpr iface_constraint in iface_constraints) {
foreach (Type type in list) {
if (!type.Equals (iface_constraint.Type))
//.........这里部分代码省略.........
示例14: GenericParameterAttrTest
public static bool GenericParameterAttrTest(GenericParameterAttributes parameterAttrs,
GenericParameterAttributes testAttrs)
{
return ((parameterAttrs & testAttrs) == testAttrs);
}
示例15: GetGenericParamProps
[System.Security.SecurityCritical] // auto-generated
public void GetGenericParamProps(
int genericParameter,
out GenericParameterAttributes attributes)
{
int _attributes;
_GetGenericParamProps(m_metadataImport2, genericParameter, out _attributes);
attributes = (GenericParameterAttributes)_attributes;
}