本文整理汇总了C#中TypeSymbol.IsArray方法的典型用法代码示例。如果您正苦于以下问题:C# TypeSymbol.IsArray方法的具体用法?C# TypeSymbol.IsArray怎么用?C# TypeSymbol.IsArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeSymbol
的用法示例。
在下文中一共展示了TypeSymbol.IsArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsVarianceCast
// Although III.1.8.1.3 seems to imply that verifier understands variance casts.
// It appears that verifier/JIT gets easily confused.
// So to not rely on whether that should work or not we will flag potentially
// "complicated" casts and make them static casts to ensure we are all on
// the same page with what type should be tracked.
private static bool IsVarianceCast(TypeSymbol to, TypeSymbol from)
{
if (to == from)
{
return false;
}
if ((object)from == null)
{
// from unknown type - this could be a variance conversion.
return true;
}
// while technically variance casts, array conversions do not seem to be a problem
// unless the element types are converted via variance.
if (to.IsArray())
{
return IsVarianceCast(((ArrayTypeSymbol)to).ElementType, ((ArrayTypeSymbol)from).ElementType);
}
return (to.IsDelegateType() && to != from) ||
(to.IsInterfaceType() && from.IsInterfaceType() && !from.InterfacesAndTheirBaseInterfacesNoUseSiteDiagnostics.Contains((NamedTypeSymbol)to));
}
示例2: UpperBoundArrayInference
private bool UpperBoundArrayInference(TypeSymbol source, TypeSymbol target, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
{
Debug.Assert((object)source != null);
Debug.Assert((object)target != null);
// SPEC: * Otherwise, if V is an array type Ve[...] and U is an array
// SPEC: type Ue[...] of the same rank, or if V is a one-dimensional array
// SPEC: type Ve[] and U is one of IEnumerable<Ue>, ICollection<Ue> or
// SPEC: IList<Ue> then
// SPEC: * if Ue is known to be a reference type then an upper-bound inference
// SPEC: from Ue to Ve is made.
// SPEC: * otherwise an exact inference from Ue to Ve is made.
if (!target.IsArray())
{
return false;
}
var arrayTarget = (ArrayTypeSymbol)target;
var elementTarget = arrayTarget.ElementType;
var elementSource = GetMatchingElementType(arrayTarget, source, ref useSiteDiagnostics);
if ((object)elementSource == null)
{
return false;
}
if (elementSource.IsReferenceType)
{
UpperBoundInference(elementSource, elementTarget, ref useSiteDiagnostics);
}
else
{
ExactInference(elementSource, elementTarget, ref useSiteDiagnostics);
}
return true;
}
示例3: GetMatchingElementType
private static TypeSymbol GetMatchingElementType(ArrayTypeSymbol source, TypeSymbol target, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
{
Debug.Assert((object)source != null);
Debug.Assert((object)target != null);
// It might be an array of same rank.
if (target.IsArray())
{
var arrayTarget = (ArrayTypeSymbol)target;
if (!arrayTarget.HasSameShapeAs(source))
{
return null;
}
return arrayTarget.ElementType;
}
// Or it might be IEnum<T> and source is rank one.
if (!source.IsSZArray)
{
return null;
}
// Arrays are specified as being convertible to IEnumerable<T>, ICollection<T> and
// IList<T>; we also honor their convertibility to IReadOnlyCollection<T> and
// IReadOnlyList<T>, and make inferences accordingly.
if (!target.IsPossibleArrayGenericInterface())
{
return null;
}
return ((NamedTypeSymbol)target).TypeArgumentWithDefinitionUseSiteDiagnostics(0, ref useSiteDiagnostics);
}
示例4: ExactArrayInference
private bool ExactArrayInference(TypeSymbol source, TypeSymbol target, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
{
Debug.Assert((object)source != null);
Debug.Assert((object)target != null);
// SPEC: * Otherwise, if U is an array type UE[...] and V is an array type VE[...]
// SPEC: of the same rank then an exact inference from UE to VE is made.
if (!source.IsArray() || !target.IsArray())
{
return false;
}
var arraySource = (ArrayTypeSymbol)source;
var arrayTarget = (ArrayTypeSymbol)target;
if (!arraySource.HasSameShapeAs(arrayTarget))
{
return false;
}
ExactInference(arraySource.ElementType, arrayTarget.ElementType, ref useSiteDiagnostics);
return true;
}
示例5: BuildTypeArgumentString
private string BuildTypeArgumentString(TypeSymbol typeArg)
{
Debug.Assert(typeArg.Kind != SymbolKind.TypeParameter); //must be a closed type
string typeArgumentsOpt = null;
string assemblyNameSuffix;
string typeArgString = typeArg.IsArray() ?
BuildArrayTypeString((ArrayTypeSymbol)typeArg, out assemblyNameSuffix) :
BuildTypeString(typeArg, out typeArgumentsOpt, out assemblyNameSuffix);
PooledStringBuilder pool = PooledStringBuilder.GetInstance();
StringBuilder builder = pool.Builder;
builder.Append("[");
builder.Append(typeArgString);
AppendTypeArguments(builder, typeArgumentsOpt);
builder.Append(assemblyNameSuffix);
builder.Append("]");
return pool.ToStringAndFree();
}
示例6: BuildTypeString
/// <summary>
/// Returns qualified name of type (without the full assembly name), with square brackets in place of
/// angle brackets and around type arguments.
/// Full assembly name of the type is stored in <paramref name="assemblyNameSuffix"/>.
/// </summary>
private string BuildTypeString(TypeSymbol symbol, out string typeArgumentsOpt, out string assemblyNameSuffix)
{
Debug.Assert((object)symbol != null);
Debug.Assert(!symbol.IsArray());
if (symbol.TypeKind == TypeKind.DynamicType)
{
return BuildTypeString(this.compilation.GetSpecialType(SpecialType.System_Object), out typeArgumentsOpt, out assemblyNameSuffix);
}
Symbol containing = symbol.ContainingSymbol;
Debug.Assert((object)containing != null);
if (containing.Kind == SymbolKind.Namespace)
{
return BuildNamespaceString((NamespaceSymbol)containing, isContainer: true) + BuildTypeStringHelper(symbol, out typeArgumentsOpt, out assemblyNameSuffix);
}
else
{
Debug.Assert(containing is TypeSymbol);
string outerTypeArgumentsOpt;
string outerAssemblyNameSuffix;
string outer = BuildTypeString((TypeSymbol)containing, out outerTypeArgumentsOpt, out outerAssemblyNameSuffix);
string inner = BuildTypeStringHelper(symbol, out typeArgumentsOpt, out assemblyNameSuffix);
Debug.Assert(outerAssemblyNameSuffix == assemblyNameSuffix);
if (typeArgumentsOpt == null)
{
typeArgumentsOpt = outerTypeArgumentsOpt;
}
else if (outerTypeArgumentsOpt != null)
{
typeArgumentsOpt = outerTypeArgumentsOpt + "," + typeArgumentsOpt;
}
return outer + "+" + inner;
}
}