本文整理汇总了C#中System.Reflection.Emit.GenericTypeParameterBuilder.SetGenericParameterAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# GenericTypeParameterBuilder.SetGenericParameterAttributes方法的具体用法?C# GenericTypeParameterBuilder.SetGenericParameterAttributes怎么用?C# GenericTypeParameterBuilder.SetGenericParameterAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.GenericTypeParameterBuilder
的用法示例。
在下文中一共展示了GenericTypeParameterBuilder.SetGenericParameterAttributes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DefineGenericTypeParameter
protected virtual unsafe void DefineGenericTypeParameter(TypeBuilder typeBuilder, GenericTypeParameterBuilder paramBuilder, BCSYM_GenericParam* pParam)
{
paramBuilder.SetGenericParameterAttributes(GetGenericParameterAttributes(pParam));
List<Type> list = new List<Type>();
for (BCSYM_GenericConstraint* constraintPtr = *((BCSYM_GenericConstraint**) (pParam + 0x54)); constraintPtr != null; constraintPtr = *((BCSYM_GenericConstraint**) (constraintPtr + 8)))
{
if (((byte) (*(((byte*) constraintPtr)) == 0x26)) != 0)
{
BCSYM* pSymbol = BCSYM.DigThroughNamedType(*((BCSYM* modopt(IsConst) modopt(IsConst)*) (constraintPtr + 12)));
Type item = this.GetType(typeBuilder, pSymbol);
if (BCSYM.IsInterface(pSymbol))
{
list.Add(item);
}
else
{
paramBuilder.SetBaseTypeConstraint(item);
}
}
}
if (list.Count > 0)
{
paramBuilder.SetInterfaceConstraints(list.ToArray());
}
}
示例2: FinishDefinition
internal void FinishDefinition(GenericTypeParameterBuilder arg)
{
Contracts.Require.IsNotNull("arg", arg);
arg.SetGenericParameterAttributes(Attributes);
if (_baseTypeConstraint != null)
{
arg.SetBaseTypeConstraint(_baseTypeConstraint.Target);
}
if (_interfaceConstraints.Count > 0)
{
arg.SetInterfaceConstraints((from i in _interfaceConstraints
select i.Target).ToArray());
}
}
示例3: DefineGenericParameter
private void DefineGenericParameter(InternalGenericParameter parameter, GenericTypeParameterBuilder builder)
{
// Set base type constraint
if (parameter.BaseType != TypeSystemServices.ObjectType)
{
builder.SetBaseTypeConstraint(GetSystemType(parameter.BaseType));
}
// Set interface constraints
Type[] interfaceTypes = Array.ConvertAll<IType, Type>(
parameter.GetInterfaces(), GetSystemType);
builder.SetInterfaceConstraints(interfaceTypes);
// Set special attributes
GenericParameterAttributes attributes = GenericParameterAttributes.None;
if (parameter.IsClass)
attributes |= GenericParameterAttributes.ReferenceTypeConstraint;
if (parameter.IsValueType)
attributes |= GenericParameterAttributes.NotNullableValueTypeConstraint;
if (parameter.MustHaveDefaultConstructor)
attributes |= GenericParameterAttributes.DefaultConstructorConstraint;
builder.SetGenericParameterAttributes(attributes);
}
示例4: DefineGenericParameterConstraints
private void DefineGenericParameterConstraints(GenericTypeParameterBuilder gpBuilder, Cci.IGenericParameter typeParameter)
{
List<Type> typeConstraints = new List<Type>();
foreach (var constraint in typeParameter.GetConstraints(_context))
{
// generic constraints must be loaded before the declaring type:
var typeConstraint = ResolveType(constraint, dependentType: (TypeBuilder)gpBuilder.DeclaringType, valueTypeDependency: false);
typeConstraints.Add(typeConstraint);
}
// The types actually don't need to be interfaces. Ref.Emit merges them eventually with base type constraint into a single list.
// Besides there might be multiple non-interface constraints applied on the parameter if they are another type parameters.
gpBuilder.SetInterfaceConstraints(typeConstraints.ToArray());
gpBuilder.SetGenericParameterAttributes(GetGenericParameterAttributes(typeParameter));
}
示例5: EmitConstraints
public void EmitConstraints (GenericTypeParameterBuilder builder)
{
var attr = GenericParameterAttributes.None;
if (spec.Variance == Variance.Contravariant)
attr |= GenericParameterAttributes.Contravariant;
else if (spec.Variance == Variance.Covariant)
attr |= GenericParameterAttributes.Covariant;
if (spec.HasSpecialClass)
attr |= GenericParameterAttributes.ReferenceTypeConstraint;
else if (spec.HasSpecialStruct)
attr |= GenericParameterAttributes.NotNullableValueTypeConstraint | GenericParameterAttributes.DefaultConstructorConstraint;
if (spec.HasSpecialConstructor)
attr |= GenericParameterAttributes.DefaultConstructorConstraint;
if (spec.BaseType != TypeManager.object_type)
builder.SetBaseTypeConstraint (spec.BaseType.GetMetaInfo ());
if (spec.InterfacesDefined != null)
builder.SetInterfaceConstraints (spec.InterfacesDefined.Select (l => l.GetMetaInfo ()).ToArray ());
if (spec.TypeArguments != null)
builder.SetInterfaceConstraints (spec.TypeArguments.Select (l => l.GetMetaInfo ()).ToArray ());
builder.SetGenericParameterAttributes (attr);
}
示例6: SetConstraints
public void SetConstraints (GenericTypeParameterBuilder type)
{
GenericParameterAttributes attr = GenericParameterAttributes.None;
if (variance == Variance.Contravariant)
attr |= GenericParameterAttributes.Contravariant;
else if (variance == Variance.Covariant)
attr |= GenericParameterAttributes.Covariant;
if (gc != null) {
if (gc.HasClassConstraint || gc.HasValueTypeConstraint)
type.SetBaseTypeConstraint (gc.EffectiveBaseClass);
attr |= gc.Attributes;
type.SetInterfaceConstraints (gc.InterfaceConstraints);
TypeManager.RegisterBuilder (type, gc.InterfaceConstraints);
}
type.SetGenericParameterAttributes (attr);
}