本文整理汇总了C#中IGenericParameter类的典型用法代码示例。如果您正苦于以下问题:C# IGenericParameter类的具体用法?C# IGenericParameter怎么用?C# IGenericParameter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IGenericParameter类属于命名空间,在下文中一共展示了IGenericParameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenericMapping
/// <summary>
/// Constrcuts a new GenericMapping for a specific mapping of generic parameters to type arguments.
/// </summary>
/// <param name="parameters">The generic parameters that should be mapped.</param>
/// <param name="arguments">The type arguments to map generic parameters to.</param>
protected GenericMapping(IGenericParameter[] parameters, IType[] arguments)
{
for (int i = 0; i < parameters.Length; i++)
{
_map.Add(parameters[i], arguments[i]);
}
}
示例2: GenericMapping
/// <summary>
/// Constrcuts a new GenericMapping for a specific mapping of generic parameters to type arguments.
/// </summary>
/// <param name="parameters">The generic parameters that should be mapped.</param>
/// <param name="arguments">The type arguments to map generic parameters to.</param>
protected GenericMapping(TypeSystemServices tss, IGenericParameter[] parameters, IType[] arguments)
{
_tss = tss;
for (int i = 0; i < parameters.Length; i++)
{
_map.Add(parameters[i], arguments[i]);
}
}
示例3: GetInferredType
public IType GetInferredType(IGenericParameter gp)
{
if (InferredTypes.ContainsKey(gp))
{
return InferredTypes[gp].ResultingType;
}
else
{
return null;
}
}
示例4: WriteGenericParameter
private void WriteGenericParameter(IGenericParameter param)
{
switch (param.Variance)
{
case TypeParameterVariance.Contravariant:
WriteKeyword("in"); break;
case TypeParameterVariance.Covariant:
WriteKeyword("out"); break;
}
WriteTypeName(param, noSpace: true);
}
示例5: GetConstraints
private IEnumerable<string> GetConstraints(IGenericParameter parameter)
{
if (parameter.MustBeValueType)
yield return "struct";
else
{
if (parameter.MustBeReferenceType)
yield return "class";
if (parameter.MustHaveDefaultConstructor)
yield return "new()";
}
foreach (var constraint in parameter.Constraints)
{
// Skip valuetype becaue we should get it above.
if (TypeHelper.TypesAreEquivalent(constraint, constraint.PlatformType.SystemValueType) && parameter.MustBeValueType)
continue;
yield return constraint.FullName();
}
}
示例6: GetConstraints
private IEnumerable<Action> GetConstraints(IGenericParameter parameter)
{
if (parameter.MustBeValueType)
yield return () => WriteKeyword("struct", noSpace: true);
else
{
if (parameter.MustBeReferenceType)
yield return () => WriteKeyword("class", noSpace: true);
}
foreach (var constraint in parameter.Constraints)
{
// Skip valuetype becaue we should get it below.
if (TypeHelper.TypesAreEquivalent(constraint, constraint.PlatformType.SystemValueType) && parameter.MustBeValueType)
continue;
yield return () => WriteTypeName(constraint, noSpace: true);
}
// new constaint cannot be put on structs and needs to be the last constraint
if (!parameter.MustBeValueType && parameter.MustHaveDefaultConstructor)
yield return () => { WriteKeyword("new", noSpace: true); WriteSymbol("("); WriteSymbol(")"); };
}
示例7: GenericArgumentMustBeValueType
public static CompilerError GenericArgumentMustBeValueType(Node node, IGenericParameter parameter, IType argument)
{
return new CompilerError("BCE0147", SafeLexicalInfo(node), argument, parameter);
}
示例8: TraverseChildren
/// <summary>
/// Traverses the children of the generic parameter.
/// </summary>
public virtual void TraverseChildren(IGenericParameter genericParameter)
{
Contract.Requires(genericParameter != null);
this.TraverseChildren((INamedTypeDefinition)genericParameter);
if (this.stopTraversal) return;
this.Traverse(genericParameter.Constraints);
}
示例9: Visit
/// <summary>
/// Performs some computation with the given generic parameter.
/// </summary>
public virtual void Visit(IGenericParameter genericParameter)
{
this.Visit((INamedTypeDefinition)genericParameter);
}
示例10: NoteGenericParameterFlow
private void NoteGenericParameterFlow(ITypeDefinition actual, IGenericParameter formal) {
if (createInstanceStrategy == TypeVariableCreateInstanceStrategy.ConstructAllConcreteParameters) {
if (!(actual is IGenericParameter)) {
// actual is concrete
ITypeDefinition unspecializedConcreteType = GarbageCollectHelper.UnspecializeAndResolveTypeReference(actual);
unspecializedTypesPassedAsTypeVariables.Add(unspecializedConcreteType);
if (GarbageCollectHelper.TypeIsConstructable(unspecializedConcreteType)) {
// t-devinc: We should associate a reason with this construction found
ConstructionFound(unspecializedConcreteType);
IMethodDefinition defaultConstructor = TypeHelper.GetMethod(unspecializedConcreteType, wholeProgram.Host().NameTable.GetNameFor(".ctor"));
if (!(defaultConstructor is Dummy)) {
// t-devinc: Add reason for this
NotePotentialNonVirtualMethodReachedForReason(defaultConstructor, null);
}
}
}
}
}
示例11: Visit
/// <summary>
/// Performs some computation with the given generic parameter.
/// </summary>
public void Visit(IGenericParameter genericParameter)
{
this.Visit((INamedTypeDefinition)genericParameter);
Hashtable constraintTable = null;
foreach (var constraint in genericParameter.Constraints) {
if (constraint.TypeCode == PrimitiveTypeCode.Void)
this.ReportError(MetadataError.ConstraintMayNotBeVoid, constraint, genericParameter);
if (constraintTable == null) constraintTable = new Hashtable();
var key = constraint.InternedKey;
if (constraintTable.Find(key) == 0)
constraintTable.Add(key, key);
else
this.ReportError(MetadataError.DuplicateConstraint, constraint, genericParameter);
}
}
示例12: ViolatesParameterConstraints
/// <summary>
/// Checks if a specified type argument violates the constraints
/// declared on a specified type paramter.
/// </summary>
public bool ViolatesParameterConstraints(IGenericParameter parameter, IType argument)
{
// Ensure argument is a valid type
if (argument == null || TypeSystemServices.IsError(argument))
{
return false;
}
bool valid = true;
// Check type semantics constraints
if (parameter.IsClass && !argument.IsClass)
{
Errors.Add(CompilerErrorFactory.GenericArgumentMustBeReferenceType(ConstructionNode, parameter, argument));
valid = false;
}
if (parameter.IsValueType && !argument.IsValueType)
{
Errors.Add(CompilerErrorFactory.GenericArgumentMustBeValueType(ConstructionNode, parameter, argument));
valid = false;
}
if (parameter.MustHaveDefaultConstructor && !HasDefaultConstructor(argument))
{
Errors.Add(CompilerErrorFactory.GenericArgumentMustHaveDefaultConstructor(ConstructionNode, parameter, argument));
valid = false;
}
// Check base type constraints
IType[] baseTypes = parameter.GetTypeConstraints();
if (baseTypes != null)
{
foreach (IType baseType in baseTypes)
{
// Don't check for System.ValueType supertype constraint
// if parameter also has explicit value type constraint
if (baseType == _tss.ValueTypeType && parameter.IsValueType)
continue;
if (!baseType.IsAssignableFrom(argument))
{
Errors.Add(CompilerErrorFactory.GenericArgumentMustHaveBaseType(ConstructionNode, parameter, argument, baseType));
valid = false;
}
}
}
return !valid;
}
示例13: GenericArgumentMustHaveBaseType
public static CompilerError GenericArgumentMustHaveBaseType(Node node, IGenericParameter parameter, IType argument, IType baseType)
{
return Instantiate("BCE0149", node, argument, baseType, parameter, parameter.DeclaringEntity);
}
示例14: DeclareGenericParameters
public void DeclareGenericParameters(INodeWithGenericParameters node, IGenericParameter[] parameters, int parameterIndexDelta)
{
for (int i=0; i < parameters.Length; ++i)
{
var prototype = parameters[i];
var newParameter = CreateGenericParameterDeclaration(parameterIndexDelta + i, prototype.Name);
node.GenericParameters.Add(newParameter);
}
}
示例15: RecordClosureDependency
private void RecordClosureDependency(BlockExpression closure, IGenericParameter genericParameter)
{
if (!_closureDependencies.ContainsKey(closure))
{
_closureDependencies.Add(closure, new List<InferredType>());
}
_closureDependencies[closure].AddUnique(InferredTypes[genericParameter]);
}