本文整理汇总了C#中ConversionsBase类的典型用法代码示例。如果您正苦于以下问题:C# ConversionsBase类的具体用法?C# ConversionsBase怎么用?C# ConversionsBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConversionsBase类属于命名空间,在下文中一共展示了ConversionsBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckConstraints
/// <summary>
/// Check type parameter constraints for the containing type or method symbol.
/// </summary>
/// <param name="containingSymbol">The generic type or method.</param>
/// <param name="conversions">Conversions instance.</param>
/// <param name="substitution">The map from type parameters to type arguments.</param>
/// <param name="typeParameters">Containing symbol type parameters.</param>
/// <param name="typeArguments">Containing symbol type arguments.</param>
/// <param name="currentCompilation">Improves error message detail.</param>
/// <param name="diagnosticsBuilder">Diagnostics.</param>
/// <param name="skipParameters">Parameters to skip.</param>
/// <param name="useSiteDiagnosticsBuilder"/>
/// <param name="ignoreTypeConstraintsDependentOnTypeParametersOpt">If an original form of a type constraint
/// depends on a type parameter from this set, do not verify this type constraint.</param>
/// <returns>True if the constraints were satisfied, false otherwise.</returns>
public static bool CheckConstraints(
this Symbol containingSymbol,
ConversionsBase conversions,
TypeMap substitution,
ImmutableArray<TypeParameterSymbol> typeParameters,
ImmutableArray<TypeSymbol> typeArguments,
Compilation currentCompilation,
ArrayBuilder<TypeParameterDiagnosticInfo> diagnosticsBuilder,
ref ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder,
BitVector skipParameters = default(BitVector),
HashSet<TypeParameterSymbol> ignoreTypeConstraintsDependentOnTypeParametersOpt = null)
{
Debug.Assert(typeParameters.Length == typeArguments.Length);
Debug.Assert(typeParameters.Length > 0);
int n = typeParameters.Length;
bool succeeded = true;
for (int i = 0; i < n; i++)
{
if (skipParameters[i])
{
continue;
}
var typeArgument = typeArguments[i];
var typeParameter = typeParameters[i];
if (!CheckConstraints(containingSymbol, conversions, substitution, typeParameter, typeArgument, currentCompilation, diagnosticsBuilder, ref useSiteDiagnosticsBuilder,
ignoreTypeConstraintsDependentOnTypeParametersOpt))
{
succeeded = false;
}
}
return succeeded;
}
示例2: CheckTypeConstraints
private static bool CheckTypeConstraints(
NamedTypeSymbol type,
ConversionsBase conversions,
Compilation currentCompilation,
ArrayBuilder<TypeParameterDiagnosticInfo> diagnosticsBuilder,
ref ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder)
{
return CheckConstraints(
type,
conversions,
type.TypeSubstitution,
type.OriginalDefinition.TypeParameters,
type.TypeArgumentsNoUseSiteDiagnostics,
currentCompilation,
diagnosticsBuilder,
ref useSiteDiagnosticsBuilder);
}
示例3: CheckMethodConstraints
private static bool CheckMethodConstraints(
MethodSymbol method,
ConversionsBase conversions,
Compilation currentCompilation,
ArrayBuilder<TypeParameterDiagnosticInfo> diagnosticsBuilder,
ref ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder,
BitVector skipParameters = default(BitVector))
{
return CheckConstraints(
method,
conversions,
method.TypeSubstitution,
((MethodSymbol)method.OriginalDefinition).TypeParameters,
method.TypeArguments,
currentCompilation,
diagnosticsBuilder,
ref useSiteDiagnosticsBuilder,
skipParameters);
}
示例4: IsEncompassedBy
/// <summary>
/// Returns true if type a is encompassed by type b (spec 6.4.3),
/// and returns false otherwise.
/// </summary>
private static bool IsEncompassedBy(ConversionsBase conversions, TypeSymbol a, TypeSymbol b, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
{
Debug.Assert(IsValidEncompassedByArgument(a));
Debug.Assert(IsValidEncompassedByArgument(b));
return conversions.HasIdentityOrImplicitReferenceConversion(a, b, ref useSiteDiagnostics) || conversions.HasBoxingConversion(a, b, ref useSiteDiagnostics);
}
示例5: AfterAddingTypeMembersChecks
internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions, DiagnosticBag diagnostics)
{
base.AfterAddingTypeMembersChecks(conversions, diagnostics);
if ((object)_explicitInterfaceType != null)
{
var explicitInterfaceSpecifier = this.ExplicitInterfaceSpecifier;
Debug.Assert(explicitInterfaceSpecifier != null);
_explicitInterfaceType.CheckAllConstraints(conversions, new SourceLocation(explicitInterfaceSpecifier.Name), diagnostics);
}
}
示例6: CheckAllConstraints
/// <summary>
/// Check all generic constraints on the given type and any containing types
/// (such as A<T> in A<T>.B<U>). This includes checking constraints
/// on generic types within the type (such as B<T> in A<B<T>[]>).
/// </summary>
public static void CheckAllConstraints(
this TypeSymbol type,
ConversionsBase conversions,
Location location,
DiagnosticBag diagnostics)
{
type.VisitType(s_checkConstraintsSingleTypeFunc, new CheckConstraintsArgs(type.DeclaringCompilation, conversions, location, diagnostics));
}
示例7: AfterAddingTypeMembersChecks
internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions, DiagnosticBag diagnostics)
{
// Check constraints on return type and parameters. Note: Dev10 uses the
// method name location for any such errors. We'll do the same for return
// type errors but for parameter errors, we'll use the parameter location.
if ((object)_explicitInterfaceType != null)
{
var syntax = this.GetSyntax();
Debug.Assert(syntax.ExplicitInterfaceSpecifier != null);
_explicitInterfaceType.CheckAllConstraints(conversions, new SourceLocation(syntax.ExplicitInterfaceSpecifier.Name), diagnostics);
}
this.ReturnType.CheckAllConstraints(conversions, this.Locations[0], diagnostics);
foreach (var parameter in this.Parameters)
{
parameter.Type.CheckAllConstraints(conversions, parameter.Locations[0], diagnostics);
}
var implementingPart = this.SourcePartialImplementation;
if ((object)implementingPart != null)
{
PartialMethodChecks(this, implementingPart, diagnostics);
}
}
示例8: CheckEffectiveAndDeducedBaseTypes
private static void CheckEffectiveAndDeducedBaseTypes(ConversionsBase conversions, TypeSymbol effectiveBase, TypeSymbol deducedBase)
{
Debug.Assert((object)deducedBase != null);
Debug.Assert((object)effectiveBase != null);
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
Debug.Assert(deducedBase.IsErrorType() ||
effectiveBase.IsErrorType() ||
conversions.HasIdentityOrImplicitReferenceConversion(deducedBase, effectiveBase, ref useSiteDiagnostics) ||
conversions.HasBoxingConversion(deducedBase, effectiveBase, ref useSiteDiagnostics));
}
示例9: AfterAddingTypeMembersChecks
internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions, DiagnosticBag diagnostics)
{
this.CheckModifiersAndType(diagnostics);
this.Type.CheckAllConstraints(conversions, this.Locations[0], diagnostics);
}
示例10: CheckConstraints
public static bool CheckConstraints(
this MethodSymbol method,
ConversionsBase conversions,
CSharpSyntaxNode syntaxNode,
Compilation currentCompilation,
DiagnosticBag diagnostics,
BitVector skipParameters = default(BitVector))
{
if (!RequiresChecking(method))
{
return true;
}
var diagnosticsBuilder = ArrayBuilder<TypeParameterDiagnosticInfo>.GetInstance();
ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder = null;
var result = CheckMethodConstraints(method, conversions, currentCompilation, diagnosticsBuilder, ref useSiteDiagnosticsBuilder, skipParameters);
if (useSiteDiagnosticsBuilder != null)
{
diagnosticsBuilder.AddRange(useSiteDiagnosticsBuilder);
}
foreach (var pair in diagnosticsBuilder)
{
var location = new SourceLocation(syntaxNode);
diagnostics.Add(new CSDiagnostic(pair.DiagnosticInfo, location));
}
diagnosticsBuilder.Free();
return result;
}
示例11: AfterAddingTypeMembersChecks
internal sealed override void AfterAddingTypeMembersChecks(ConversionsBase conversions, DiagnosticBag diagnostics)
{
// Check constraints on return type and parameters. Note: Dev10 uses the
// method name location for any such errors. We'll do the same for return
// type errors but for parameter errors, we'll use the parameter location.
this.ReturnType.CheckAllConstraints(conversions, this.Locations[0], diagnostics);
foreach (var parameter in this.Parameters)
{
parameter.Type.CheckAllConstraints(conversions, parameter.Locations[0], diagnostics);
}
}
示例12: CheckConstraintsArgs
public CheckConstraintsArgs(CSharpCompilation currentCompilation, ConversionsBase conversions, Location location, DiagnosticBag diagnostics)
{
this.CurrentCompilation = currentCompilation;
this.Conversions = conversions;
this.Location = location;
this.Diagnostics = diagnostics;
}
示例13: SatisfiesConstraintType
private static bool SatisfiesConstraintType(
ConversionsBase conversions,
TypeSymbol typeArgument,
TypeSymbol constraintType,
ref HashSet<DiagnosticInfo> useSiteDiagnostics)
{
if (constraintType.IsErrorType())
{
return false;
}
// Spec 4.4.4 describes the valid conversions from
// type argument A to constraint type C:
// "An identity conversion (6.1.1).
// An implicit reference conversion (6.1.6). ..."
if (conversions.HasIdentityOrImplicitReferenceConversion(typeArgument, constraintType, ref useSiteDiagnostics))
{
return true;
}
// "... A boxing conversion (6.1.7), provided that type A is a non-nullable value type. ..."
// NOTE: we extend this to allow, for example, a conversion from Nullable<T> to object.
if (typeArgument.IsValueType &&
conversions.HasBoxingConversion(typeArgument.IsNullableType() ? ((NamedTypeSymbol)typeArgument).ConstructedFrom : typeArgument, constraintType, ref useSiteDiagnostics))
{
return true;
}
if (typeArgument.TypeKind == TypeKind.TypeParameter)
{
var typeParameter = (TypeParameterSymbol)typeArgument;
// "... An implicit reference, boxing, or type parameter conversion
// from type parameter A to C."
if (conversions.HasImplicitTypeParameterConversion(typeParameter, constraintType, ref useSiteDiagnostics))
{
return true;
}
// TypeBind::SatisfiesBound allows cases where one of the
// type parameter constraints satisfies the constraint.
foreach (var typeArgumentConstraint in typeParameter.ConstraintTypesWithDefinitionUseSiteDiagnostics(ref useSiteDiagnostics))
{
if (SatisfiesConstraintType(conversions, typeArgumentConstraint, constraintType, ref useSiteDiagnostics))
{
return true;
}
}
}
return false;
}
示例14: AfterAddingTypeMembersChecks
internal override void AfterAddingTypeMembersChecks(ConversionsBase conversions, DiagnosticBag diagnostics)
{
// Check constraints on return type and parameters. Note: Dev10 uses the
// property name location for any such errors. We'll do the same for return
// type errors but for parameter errors, we'll use the parameter location.
if ((object)_explicitInterfaceType != null)
{
var explicitInterfaceSpecifier = GetExplicitInterfaceSpecifier(this.CSharpSyntaxNode);
Debug.Assert(explicitInterfaceSpecifier != null);
_explicitInterfaceType.CheckAllConstraints(conversions, new SourceLocation(explicitInterfaceSpecifier.Name), diagnostics);
}
}
示例15: CheckConstraints
public static bool CheckConstraints(
this NamedTypeSymbol type,
ConversionsBase conversions,
CSharpSyntaxNode typeSyntax,
SeparatedSyntaxList<TypeSyntax> typeArgumentsSyntax,
Compilation currentCompilation,
DiagnosticBag diagnostics)
{
Debug.Assert(typeArgumentsSyntax.Count == type.Arity);
if (!RequiresChecking(type))
{
return true;
}
var diagnosticsBuilder = ArrayBuilder<TypeParameterDiagnosticInfo>.GetInstance();
ArrayBuilder<TypeParameterDiagnosticInfo> useSiteDiagnosticsBuilder = null;
var result = CheckTypeConstraints(type, conversions, currentCompilation, diagnosticsBuilder, ref useSiteDiagnosticsBuilder);
if (useSiteDiagnosticsBuilder != null)
{
diagnosticsBuilder.AddRange(useSiteDiagnosticsBuilder);
}
foreach (var pair in diagnosticsBuilder)
{
int ordinal = pair.TypeParameter.Ordinal;
var location = new SourceLocation(typeArgumentsSyntax[ordinal]);
diagnostics.Add(new CSDiagnostic(pair.DiagnosticInfo, location));
}
diagnosticsBuilder.Free();
if (!InterfacesAreDistinct(type))
{
result = false;
diagnostics.Add(ErrorCode.ERR_BogusType, typeSyntax.Location, type);
}
return result;
}