本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Symbols.TypeMap.SubstituteTypesDistinctWithoutModifiers方法的典型用法代码示例。如果您正苦于以下问题:C# TypeMap.SubstituteTypesDistinctWithoutModifiers方法的具体用法?C# TypeMap.SubstituteTypesDistinctWithoutModifiers怎么用?C# TypeMap.SubstituteTypesDistinctWithoutModifiers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Symbols.TypeMap
的用法示例。
在下文中一共展示了TypeMap.SubstituteTypesDistinctWithoutModifiers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckConstraints
// See TypeBind::CheckSingleConstraint.
private static bool CheckConstraints(
Symbol containingSymbol,
ConversionsBase conversions,
TypeMap substitution,
TypeParameterSymbol typeParameter,
TypeSymbol typeArgument,
Compilation currentCompilation,
ArrayBuilder<TypeParameterDiagnosticInfo> diagnosticsBuilder,
ref ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder,
HashSet<TypeParameterSymbol> ignoreTypeConstraintsDependentOnTypeParametersOpt)
{
Debug.Assert(substitution != null);
// The type parameters must be original definitions of type parameters from the containing symbol.
Debug.Assert(ReferenceEquals(typeParameter.ContainingSymbol, containingSymbol.OriginalDefinition));
if (typeArgument.IsErrorType())
{
return true;
}
if (typeArgument.IsPointerType() || typeArgument.IsRestrictedType() || typeArgument.SpecialType == SpecialType.System_Void)
{
// "The type '{0}' may not be used as a type argument"
diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new CSDiagnosticInfo(ErrorCode.ERR_BadTypeArgument, typeArgument)));
return false;
}
if (typeArgument.IsStatic)
{
// "'{0}': static types cannot be used as type arguments"
diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new CSDiagnosticInfo(ErrorCode.ERR_GenericArgIsStaticClass, typeArgument)));
return false;
}
if (typeParameter.HasReferenceTypeConstraint && !typeArgument.IsReferenceType)
{
// "The type '{2}' must be a reference type in order to use it as parameter '{1}' in the generic type or method '{0}'"
diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new CSDiagnosticInfo(ErrorCode.ERR_RefConstraintNotSatisfied, containingSymbol.ConstructedFrom(), typeParameter, typeArgument)));
return false;
}
if (typeParameter.HasValueTypeConstraint && !typeArgument.IsNonNullableValueType())
{
// "The type '{2}' must be a non-nullable value type in order to use it as parameter '{1}' in the generic type or method '{0}'"
diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new CSDiagnosticInfo(ErrorCode.ERR_ValConstraintNotSatisfied, containingSymbol.ConstructedFrom(), typeParameter, typeArgument)));
return false;
}
// The type parameters for a constructed type/method are the type parameters of
// the ConstructedFrom type/method, so the constraint types are not substituted.
// For instance with "class C<T, U> where T : U", the type parameter for T in "C<object, int>"
// has constraint "U", not "int". We need to substitute the constraints from the
// original definition of the type parameters using the map from the constructed symbol.
var constraintTypes = ArrayBuilder<TypeSymbol>.GetInstance();
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
substitution.SubstituteTypesDistinctWithoutModifiers(typeParameter.ConstraintTypesWithDefinitionUseSiteDiagnostics(ref useSiteDiagnostics), constraintTypes,
ignoreTypeConstraintsDependentOnTypeParametersOpt);
bool hasError = false;
foreach (var constraintType in constraintTypes)
{
if (SatisfiesConstraintType(conversions, typeArgument, constraintType, ref useSiteDiagnostics))
{
continue;
}
ErrorCode errorCode;
if (typeArgument.IsReferenceType)
{
errorCode = ErrorCode.ERR_GenericConstraintNotSatisfiedRefType;
}
else if (typeArgument.IsNullableType())
{
errorCode = constraintType.IsInterfaceType() ? ErrorCode.ERR_GenericConstraintNotSatisfiedNullableInterface : ErrorCode.ERR_GenericConstraintNotSatisfiedNullableEnum;
}
else if (typeArgument.TypeKind == TypeKind.TypeParameter)
{
errorCode = ErrorCode.ERR_GenericConstraintNotSatisfiedTyVar;
}
else
{
errorCode = ErrorCode.ERR_GenericConstraintNotSatisfiedValType;
}
SymbolDistinguisher distinguisher = new SymbolDistinguisher(currentCompilation, constraintType, typeArgument);
diagnosticsBuilder.Add(new TypeParameterDiagnosticInfo(typeParameter, new CSDiagnosticInfo(errorCode, containingSymbol.ConstructedFrom(), distinguisher.First, typeParameter, distinguisher.Second)));
hasError = true;
}
if (AppendUseSiteDiagnostics(useSiteDiagnostics, typeParameter, ref useSiteDiagnosticsBuilder))
{
hasError = true;
}
constraintTypes.Free();
// Check the constructor constraint.
if (typeParameter.HasConstructorConstraint && !SatisfiesConstructorConstraint(typeArgument))
//.........这里部分代码省略.........