本文整理汇总了C#中ITypeParameterSymbol类的典型用法代码示例。如果您正苦于以下问题:C# ITypeParameterSymbol类的具体用法?C# ITypeParameterSymbol怎么用?C# ITypeParameterSymbol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ITypeParameterSymbol类属于命名空间,在下文中一共展示了ITypeParameterSymbol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitTypeParameter
public override void VisitTypeParameter(ITypeParameterSymbol symbol)
{
ReferenceItem.Parts[SyntaxLanguage.CSharp].Add(new LinkItem
{
DisplayName = symbol.Name,
DisplayQualifiedNames = symbol.Name,
});
}
示例2: GenerateTypeParameter
private static TypeParameterSyntax GenerateTypeParameter(ITypeParameterSymbol symbol, CodeGenerationOptions options)
{
var varianceKeyword =
symbol.Variance == VarianceKind.In ? SyntaxFactory.Token(SyntaxKind.InKeyword) :
symbol.Variance == VarianceKind.Out ? SyntaxFactory.Token(SyntaxKind.OutKeyword) : default(SyntaxToken);
return SyntaxFactory.TypeParameter(
AttributeGenerator.GenerateAttributeLists(symbol.GetAttributes(), options),
varianceKeyword,
symbol.Name.ToIdentifierToken());
}
示例3: VisitTypeParameter
public sealed override void VisitTypeParameter(ITypeParameterSymbol symbol)
{
// Using an if, rather than assert condition, to make debugging easier.
if (!_acceptableTypeParameters.Contains(symbol))
{
Debug.Assert(false,
string.Format("Unexpected type parameter {0} owned by {1}", symbol, symbol.ContainingSymbol));
}
foreach (var constraintType in symbol.ConstraintTypes)
{
Visit(constraintType);
}
}
示例4: GetTypeParameter
private SDTypeParameter GetTypeParameter(ITypeParameterSymbol typeParameter)
{
var sdTypeParameter = new SDTypeParameter
{
Name = typeParameter.Name,
HasDefaultConstructorConstraint = typeParameter.HasConstructorConstraint,
HasReferenceTypeConstraint = typeParameter.HasReferenceTypeConstraint,
HasValueTypeConstraint = typeParameter.HasValueTypeConstraint
};
foreach (var constraintType in typeParameter.ConstraintTypes)
{
sdTypeParameter.ConstraintTypes.Add(_typeRefParser.GetParsedTypeReference(constraintType));
}
return sdTypeParameter;
}
示例5: VisitTypeParameter
public override void VisitTypeParameter(ITypeParameterSymbol symbol)
{
if (_visited.Add(symbol))
{
if (symbol.TypeParameterKind == TypeParameterKind.Method || !_onlyMethodTypeParameters)
{
if (!_typeParameters.Contains(symbol))
{
_typeParameters.Add(symbol);
}
}
foreach (var constraint in symbol.ConstraintTypes)
{
constraint.Accept(this);
}
}
}
示例6: AddConstraintClauses
private static void AddConstraintClauses(
List<TypeParameterConstraintClauseSyntax> clauses,
ITypeParameterSymbol typeParameter)
{
var constraints = new List<TypeParameterConstraintSyntax>();
if (typeParameter.HasReferenceTypeConstraint)
{
constraints.Add(SyntaxFactory.ClassOrStructConstraint(SyntaxKind.ClassConstraint));
}
else if (typeParameter.HasValueTypeConstraint)
{
constraints.Add(SyntaxFactory.ClassOrStructConstraint(SyntaxKind.StructConstraint));
}
var constraintTypes =
typeParameter.ConstraintTypes.Where(t => t.TypeKind == TypeKind.Class).Concat(
typeParameter.ConstraintTypes.Where(t => t.TypeKind == TypeKind.Interface).Concat(
typeParameter.ConstraintTypes.Where(t => t.TypeKind != TypeKind.Class && t.TypeKind != TypeKind.Interface)));
foreach (var type in constraintTypes)
{
if (type.SpecialType != SpecialType.System_Object)
{
constraints.Add(SyntaxFactory.TypeConstraint(type.GenerateTypeSyntax()));
}
}
if (typeParameter.HasConstructorConstraint)
{
constraints.Add(SyntaxFactory.ConstructorConstraint());
}
if (constraints.Count == 0)
{
return;
}
clauses.Add(SyntaxFactory.TypeParameterConstraintClause(
typeParameter.Name.ToIdentifierName(),
SyntaxFactory.SeparatedList(constraints)));
}
示例7: CheckTypeParameter
private static bool CheckTypeParameter(ITypeParameterSymbol typeParameter, VarianceKind variance,
INamedTypeSymbol delegateType, ITypeSymbol returnType, ImmutableArray<IParameterSymbol> parameters)
{
var canBe = CheckTypeParameterContraintsInSymbol(typeParameter, variance, delegateType);
if (!canBe)
{
return false;
}
canBe = CanTypeParameterBeVariant(typeParameter, variance, returnType,
true, false, delegateType);
if (!canBe)
{
return false;
}
canBe = CheckTypeParameterInParameters(typeParameter, variance, parameters, delegateType);
return canBe;
}
示例8: CanTypeParameterBeVariant
private static bool CanTypeParameterBeVariant(
ITypeParameterSymbol parameter,
VarianceKind variance,
INamedTypeSymbol namedType,
bool requireOutputSafety,
bool requireInputSafety,
ISymbol context)
{
switch (namedType.TypeKind)
{
case TypeKind.Class:
case TypeKind.Struct:
case TypeKind.Enum:
case TypeKind.Interface:
case TypeKind.Delegate:
case TypeKind.Error:
break;
default:
return true;
}
var currentNamedType = namedType;
while (currentNamedType != null)
{
for (int i = 0; i < currentNamedType.Arity; i++)
{
var typeParam = currentNamedType.TypeParameters[i];
var typeArg = currentNamedType.TypeArguments[i];
if (!typeArg.Equals(parameter))
{
return false;
}
var requireOut = false;
var requireIn = false;
switch (typeParam.Variance)
{
case VarianceKind.Out:
requireOut = requireOutputSafety;
requireIn = requireInputSafety;
break;
case VarianceKind.In:
requireOut = requireInputSafety;
requireIn = requireOutputSafety;
break;
case VarianceKind.None:
requireIn = true;
requireOut = true;
break;
default:
throw new NotSupportedException();
}
if (!CanTypeParameterBeVariant(parameter, variance, typeArg, requireOut, requireIn, context))
{
return false;
}
}
currentNamedType = currentNamedType.ContainingType;
}
return true;
}
示例9: CheckTypeParameterContraintsInSymbol
private static bool CheckTypeParameterContraintsInSymbol(ITypeParameterSymbol typeParameter, VarianceKind variance,
ISymbol context)
{
foreach (ITypeSymbol constraintType in typeParameter.ConstraintTypes)
{
var canBe = CanTypeParameterBeVariant(
typeParameter,
variance,
constraintType,
false,
true,
context);
if (!canBe)
{
return false;
}
}
return true;
}
示例10: CheckTypeParameterInEvent
private static bool CheckTypeParameterInEvent(ITypeParameterSymbol typeParameter, VarianceKind variance,
IEventSymbol @event)
{
return CanTypeParameterBeVariant(
typeParameter, variance,
@event.Type,
false,
true,
@event);
}
示例11: ReportIssue
private static void ReportIssue(ITypeParameterSymbol typeParameter, VarianceKind variance, SyntaxNodeAnalysisContext context)
{
if (!typeParameter.DeclaringSyntaxReferences.Any())
{
return;
}
var location = typeParameter.DeclaringSyntaxReferences.First().GetSyntax().GetLocation();
if (variance == VarianceKind.In)
{
context.ReportDiagnostic(Diagnostic.Create(Rule, location, "in", typeParameter.Name, "contravariant"));
return;
}
if (variance == VarianceKind.Out)
{
context.ReportDiagnostic(Diagnostic.Create(Rule, location, "out", typeParameter.Name, "covariant"));
return;
}
}
示例12: CheckTypeParameterInMethod
private static bool CheckTypeParameterInMethod(ITypeParameterSymbol typeParameter, VarianceKind variance,
IMethodSymbol method)
{
var canBe = CheckTypeParameterContraintsInSymbol(typeParameter, variance, method);
if (!canBe)
{
return false;
}
canBe = CanTypeParameterBeVariant(
typeParameter, variance,
method.ReturnType,
true,
false,
method);
if (!canBe)
{
return false;
}
return CheckTypeParameterInParameters(typeParameter, variance, method.Parameters, method);
}
示例13: HaveSameConstraints
private bool HaveSameConstraints(ITypeParameterSymbol typeParameter1, ITypeParameterSymbol typeParameter2)
{
if (typeParameter1.HasConstructorConstraint != typeParameter2.HasConstructorConstraint ||
typeParameter1.HasReferenceTypeConstraint != typeParameter2.HasReferenceTypeConstraint ||
typeParameter1.HasValueTypeConstraint != typeParameter2.HasValueTypeConstraint)
{
return false;
}
if (typeParameter1.ConstraintTypes.Length != typeParameter2.ConstraintTypes.Length)
{
return false;
}
return typeParameter1.ConstraintTypes.SetEquals(
typeParameter2.ConstraintTypes, this.SignatureTypeEquivalenceComparer);
}
示例14: GetVarianceToken
private static SyntaxToken GetVarianceToken(ITypeParameterSymbol t)
{
if (t.Variance == VarianceKind.In)
return SyntaxFactory.Token(SyntaxKind.InKeyword);
if (t.Variance == VarianceKind.Out)
return SyntaxFactory.Token(SyntaxKind.OutKeyword);
return new SyntaxToken();
}
示例15: TypeParameterHasConstraints
private static bool TypeParameterHasConstraints(ITypeParameterSymbol typeParam)
{
return !typeParam.ConstraintTypes.IsEmpty || typeParam.HasConstructorConstraint ||
typeParam.HasReferenceTypeConstraint || typeParam.HasValueTypeConstraint;
}