本文整理汇总了C#中TypeSymbol类的典型用法代码示例。如果您正苦于以下问题:C# TypeSymbol类的具体用法?C# TypeSymbol怎么用?C# TypeSymbol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeSymbol类属于命名空间,在下文中一共展示了TypeSymbol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetInferredType
public BoundLocal SetInferredType(TypeSymbol type, bool success)
{
Debug.Assert(type != null);
var syntaxNode = (SingleVariableDesignationSyntax)this.Syntax;
Binder.DeclareLocalVariable((SourceLocalSymbol)this.LocalSymbol, syntaxNode.Identifier, type);
return new BoundLocal(syntaxNode, this.LocalSymbol, constantValueOpt: null, type: type, hasErrors: this.HasErrors || !success);
}
示例2: StructDependsClosure
private static void StructDependsClosure(TypeSymbol type, HashSet<Symbol> partialClosure, NamedTypeSymbol on)
{
if ((object)type == null)
{
return;
}
var nt = type as NamedTypeSymbol;
if ((object)nt != null && ReferenceEquals(nt.OriginalDefinition, on))
{
// found a possibly expanding cycle, for example
// struct X<T> { public T t; }
// struct W<T> { X<W<W<T>>> x; }
// while not explicitly forbidden by the spec, it should be.
partialClosure.Add(on);
return;
}
if ((object)nt != null && partialClosure.Add(nt))
{
foreach (var member in type.GetMembersUnordered())
{
var field = member as FieldSymbol;
if ((object)field == null || field.Type.TypeKind != TypeKind.Struct || field.IsStatic)
{
continue;
}
StructDependsClosure(field.Type, partialClosure, on);
}
}
}
示例3: ClassifyConversionFromExpression
public Conversion ClassifyConversionFromExpression(TypeSymbol source, TypeSymbol destination, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
{
Debug.Assert((object)source != null);
Debug.Assert((object)destination != null);
return ClassifyConversionFromExpression(null, source, destination, ref useSiteDiagnostics);
}
示例4: TempLocalSymbol
internal TempLocalSymbol(TypeSymbol type, RefKind refKind, MethodSymbol containingMethod) : base(containingMethod, type, null)
{
this.refKind = refKind;
#if TEMPNAMES
this.name = "_" + Interlocked.Increment(ref nextName);
#endif
}
示例5: CreateMask
public static TypeRefMask CreateMask(TypeRefContext ctx, TypeSymbol t)
{
Contract.ThrowIfNull(t);
switch (t.SpecialType)
{
case SpecialType.System_Void: return 0;
case SpecialType.System_Int64: return ctx.GetLongTypeMask();
case SpecialType.System_String: return ctx.GetStringTypeMask();
case SpecialType.System_Double: return ctx.GetDoubleTypeMask();
case SpecialType.System_Boolean: return ctx.GetBooleanTypeMask();
case SpecialType.None:
var containing = t.ContainingAssembly;
if (containing != null && containing.IsPchpCorLibrary)
{
if (t.Name == "PhpValue") return TypeRefMask.AnyType;
if (t.Name == "PhpAlias") return TypeRefMask.AnyType.WithRefFlag;
if (t.Name == "PhpNumber") return ctx.GetNumberTypeMask();
if (t.Name == "PhpString") return ctx.GetWritableStringTypeMask();
if (t.Name == "PhpArray") return ctx.GetArrayTypeMask();
if (t.Name == "IPhpCallable") return ctx.GetCallableTypeMask();
}
break;
}
return CreateMask(ctx, CreateTypeRef(ctx, t));
}
示例6: IsSameType
/// <summary>
/// Logical equality on anonymous types that ignores custom modifiers and/or the object/dynamic distinction.
/// Differs from IsSameType for arrays, pointers, and generic instantiations.
/// </summary>
internal static bool IsSameType(TypeSymbol type1, TypeSymbol type2, bool ignoreCustomModifiers, bool ignoreDynamic)
{
Debug.Assert(type1.IsAnonymousType);
Debug.Assert(type2.IsAnonymousType);
if (ignoreCustomModifiers || ignoreDynamic)
{
AnonymousTypeDescriptor left = ((AnonymousTypePublicSymbol)type1).TypeDescriptor;
AnonymousTypeDescriptor right = ((AnonymousTypePublicSymbol)type2).TypeDescriptor;
if (left.Key != right.Key)
{
return false;
}
int count = left.Fields.Length;
Debug.Assert(right.Fields.Length == count);
for (int i = 0; i < count; i++)
{
if (!left.Fields[i].Type.Equals(right.Fields[i].Type, ignoreCustomModifiers, ignoreDynamic))
{
return false;
}
}
return true;
}
else
{
return type1 == type2;
}
}
示例7: EELocalSymbol
public EELocalSymbol(
MethodSymbol method,
ImmutableArray<Location> locations,
string nameOpt,
int ordinal,
LocalDeclarationKind declarationKind,
TypeSymbol type,
RefKind refKind,
bool isPinned,
bool isCompilerGenerated,
bool canScheduleToStack)
{
Debug.Assert(method != null);
Debug.Assert(ordinal >= -1);
Debug.Assert(!locations.IsDefault);
Debug.Assert(type != null);
_method = method;
_locations = locations;
_nameOpt = nameOpt;
_ordinal = ordinal;
_declarationKind = declarationKind;
_type = type;
_refKind = refKind;
_isPinned = isPinned;
_isCompilerGenerated = isCompilerGenerated;
_canScheduleToStack = canScheduleToStack;
}
示例8: CopyTypeCustomModifiers
/// <param name="sourceType">Type that already has custom modifiers.</param>
/// <param name="destinationType">Same as <paramref name="sourceType"/>, but without custom modifiers. May differ in object/dynamic.</param>
/// <param name="refKind"><see cref="RefKind"/> of the parameter of which this is the type (or <see cref="RefKind.None"/> for a return type.</param>
/// <param name="containingAssembly">The assembly containing the signature referring to the destination type.</param>
/// <returns><paramref name="destinationType"/> with custom modifiers copied from <paramref name="sourceType"/>.</returns>
internal static TypeSymbol CopyTypeCustomModifiers(TypeSymbol sourceType, TypeSymbol destinationType, RefKind refKind, AssemblySymbol containingAssembly)
{
Debug.Assert(sourceType.Equals(destinationType, TypeCompareKind.AllIgnoreOptions));
// NOTE: overrides can differ by object/dynamic. If they do, we'll need to tweak newType before
// we can use it in place of this.Type. We do so by computing the dynamic transform flags that
// code gen uses and then passing them to the dynamic type decoder that metadata reading uses.
ImmutableArray<bool> flags = CSharpCompilation.DynamicTransformsEncoder.EncodeWithoutCustomModifierFlags(destinationType, refKind);
TypeSymbol typeWithDynamic = DynamicTypeDecoder.TransformTypeWithoutCustomModifierFlags(sourceType, containingAssembly, refKind, flags);
TypeSymbol resultType;
if (destinationType.ContainsTuple() && !sourceType.Equals(destinationType, TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds | TypeCompareKind.IgnoreDynamic))
{
// We also preserve tuple names, if present and different
ImmutableArray<string> names = CSharpCompilation.TupleNamesEncoder.Encode(destinationType);
resultType = TupleTypeDecoder.DecodeTupleTypesIfApplicable(typeWithDynamic, containingAssembly, names);
}
else
{
resultType = typeWithDynamic;
}
Debug.Assert(resultType.Equals(sourceType, TypeCompareKind.IgnoreDynamicAndTupleNames)); // Same custom modifiers as source type.
Debug.Assert(resultType.Equals(destinationType, TypeCompareKind.IgnoreCustomModifiersAndArraySizesAndLowerBounds)); // Same object/dynamic and tuple names as destination type.
return resultType;
}
示例9: MakeLiteral
private BoundExpression MakeLiteral(CSharpSyntaxNode syntax, ConstantValue constantValue, TypeSymbol type, BoundLiteral oldNodeOpt = null)
{
Debug.Assert(constantValue != null);
if (constantValue.IsDecimal)
{
// Rewrite decimal literal
Debug.Assert((object)type != null);
Debug.Assert(type.SpecialType == SpecialType.System_Decimal);
return MakeDecimalLiteral(syntax, constantValue);
}
else if (constantValue.IsDateTime)
{
// C# does not support DateTime constants but VB does; we might have obtained a
// DateTime constant by calling a method with an optional parameter with a DateTime
// for its default value.
Debug.Assert((object)type != null);
Debug.Assert(type.SpecialType == SpecialType.System_DateTime);
return MakeDateTimeLiteral(syntax, constantValue);
}
else if (oldNodeOpt != null)
{
return oldNodeOpt.Update(constantValue, type);
}
else
{
return new BoundLiteral(syntax, constantValue, type, hasErrors: constantValue.IsBad);
}
}
示例10: MetadataTypeAdapter
/// <summary>
/// </summary>
/// <param name="typeDef">
/// </param>
/// <param name="isByRef">
/// </param>
internal MetadataTypeAdapter(TypeSymbol typeDef, bool isByRef = false, bool isPinned = false)
{
Debug.Assert(typeDef != null);
this.typeDef = typeDef;
this.IsByRef = isByRef;
this.IsPinned = isPinned;
var def = typeDef as ByRefReturnErrorTypeSymbol;
if (def != null)
{
this.typeDef = def.ReferencedType;
this.IsByRef = true;
}
Debug.Assert(this.typeDef.TypeKind != TypeKind.Error);
this.lazyName = new Lazy<string>(this.CalculateName);
this.lazyFullName = new Lazy<string>(this.CalculateFullName);
this.lazyMetadataName = new Lazy<string>(this.CalculateMetadataName);
this.lazyMetadataFullName = new Lazy<string>(this.CalculateMetadataFullName);
this.lazyNamespace = new Lazy<string>(this.CalculateNamespace);
this.lazyBaseType = new Lazy<IType>(this.CalculateBaseType);
this.lazyAssemblyQualifiedName = new Lazy<string>(this.CalculateAssemblyQualifiedName);
this.lazyToString = new Lazy<string>(this.CalculateToString);
}
示例11: MakeFieldAccess
private BoundExpression MakeFieldAccess(
CSharpSyntaxNode syntax,
BoundExpression rewrittenReceiver,
FieldSymbol fieldSymbol,
ConstantValue constantValueOpt,
LookupResultKind resultKind,
TypeSymbol type,
BoundFieldAccess oldNodeOpt = null)
{
if (fieldSymbol.IsTupleField)
{
return MakeTupleFieldAccess(syntax, fieldSymbol, rewrittenReceiver, constantValueOpt, resultKind);
}
BoundExpression result = oldNodeOpt != null ?
oldNodeOpt.Update(rewrittenReceiver, fieldSymbol, constantValueOpt, resultKind, type) :
new BoundFieldAccess(syntax, rewrittenReceiver, fieldSymbol, constantValueOpt, resultKind, type);
if (fieldSymbol.IsFixed)
{
// a reference to a fixed buffer is translated into its address
result = new BoundConversion(syntax,
new BoundAddressOfOperator(syntax, result, syntax != null && SyntaxFacts.IsFixedStatementExpression(syntax), type, false),
new Conversion(ConversionKind.PointerToPointer), false, false, default(ConstantValue), type, false);
}
return result;
}
示例12: GetImplicitTupleLiteralConversion
protected override Conversion GetImplicitTupleLiteralConversion(BoundTupleLiteral source, TypeSymbol destination, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
{
var arguments = source.Arguments;
// check if the type is actually compatible type for a tuple of given cardinality
if (!destination.IsTupleOrCompatibleWithTupleOfCardinality(arguments.Length))
{
return Conversion.NoConversion;
}
ImmutableArray<TypeSymbol> targetElementTypes = destination.GetElementTypesOfTupleOrCompatible();
Debug.Assert(arguments.Length == targetElementTypes.Length);
// check arguments against flattened list of target element types
var argumentConversions = ArrayBuilder<Conversion>.GetInstance(arguments.Length);
for (int i = 0; i < arguments.Length; i++)
{
var argument = arguments[i];
var result = ClassifyImplicitConversionFromExpression(argument, targetElementTypes[i], ref useSiteDiagnostics);
if (!result.Exists)
{
argumentConversions.Free();
return Conversion.NoConversion;
}
argumentConversions.Add(result);
}
return new Conversion(ConversionKind.ImplicitTupleLiteral, argumentConversions.ToImmutableAndFree());
}
示例13: SynthesizedEntryPointSymbol
internal SynthesizedEntryPointSymbol(NamedTypeSymbol containingType, TypeSymbol returnType, DiagnosticBag diagnostics)
{
Debug.Assert((object)containingType != null);
this.containingType = containingType;
if (containingType.ContainingAssembly.IsInteractive)
{
var interactiveSessionType = this.DeclaringCompilation.GetWellKnownType(WellKnownType.Microsoft_CSharp_RuntimeHelpers_Session);
var useSiteDiagnostic = interactiveSessionType.GetUseSiteDiagnostic();
if (useSiteDiagnostic != null)
{
Symbol.ReportUseSiteDiagnostic(useSiteDiagnostic, diagnostics, NoLocation.Singleton);
}
this.parameters = ImmutableArray.Create<ParameterSymbol>(new SynthesizedParameterSymbol(this, interactiveSessionType, 0, RefKind.None, "session"));
this.name = "<Factory>";
}
else
{
this.parameters = ImmutableArray<ParameterSymbol>.Empty;
this.name = "<Main>";
}
this.returnType = returnType;
}
示例14: SourceStrictComplexParameterSymbol
internal SourceStrictComplexParameterSymbol(
DiagnosticBag diagnostics,
Binder binder,
Symbol owner,
int ordinal,
TypeSymbol parameterType,
RefKind refKind,
string name,
ImmutableArray<Location> locations,
SyntaxReference syntaxRef,
ConstantValue defaultSyntaxValue,
bool isParams,
bool isExtensionMethodThis)
: base(
owner: owner,
ordinal: ordinal,
parameterType: parameterType,
refKind: refKind,
name: name,
locations: locations,
syntaxRef: syntaxRef,
defaultSyntaxValue: defaultSyntaxValue,
isParams: isParams,
isExtensionMethodThis: isExtensionMethodThis)
{
_tempBinder = binder;
var unused = GetAttributesBag(diagnostics);
_lazyDefaultSyntaxValue = MakeDefaultExpression(diagnostics, binder);
_tempBinder = null; // no need to keep it around anymore, just uses up a lot of memory
}
示例15: SynthesizedImplementationMethod
public SynthesizedImplementationMethod(
MethodSymbol interfaceMethod,
NamedTypeSymbol implementingType,
string name = null,
bool debuggerHidden = false,
PropertySymbol associatedProperty = null,
MethodSymbol asyncKickoffMethod = null)
{
//it does not make sense to add methods to substituted types
Debug.Assert(implementingType.IsDefinition);
this.name = name ?? ExplicitInterfaceHelpers.GetMemberName(interfaceMethod.Name, interfaceMethod.ContainingType, aliasQualifierOpt: null);
this.interfaceMethod = interfaceMethod;
this.implementingType = implementingType;
this.debuggerHidden = debuggerHidden;
this.associatedProperty = associatedProperty;
this.explicitInterfaceImplementations = ImmutableArray.Create<MethodSymbol>(interfaceMethod);
this.asyncKickoffMethod = asyncKickoffMethod;
// alpha-rename to get the implementation's type parameters
var typeMap = interfaceMethod.ContainingType.TypeSubstitution ?? TypeMap.Empty;
typeMap.WithAlphaRename(interfaceMethod, this, out this.typeParameters);
var substitutedInterfaceMethod = interfaceMethod.ConstructIfGeneric(this.typeParameters.Cast<TypeParameterSymbol, TypeSymbol>());
this.returnType = substitutedInterfaceMethod.ReturnType;
this.parameters = SynthesizedParameterSymbol.DeriveParameters(substitutedInterfaceMethod, this);
}