private PropertySymbol?VisitPropertySymbol(PropertySymbol?property) { if (property is null) { return(null); } if (!property.ContainingType.IsAnonymousType) { // Property of a regular type return(((PropertySymbol)property.OriginalDefinition) .AsMember((NamedTypeSymbol)TypeMap.SubstituteType(property.ContainingType).AsTypeSymbolOnly())); } // Method of an anonymous type var newType = (NamedTypeSymbol)TypeMap.SubstituteType(property.ContainingType).AsTypeSymbolOnly(); if (ReferenceEquals(newType, property.ContainingType)) { // Anonymous type symbol was not rewritten return(property); } // get a new property by name foreach (var member in newType.GetMembers(property.Name)) { if (member.Kind == SymbolKind.Property) { return((PropertySymbol)member); } } throw ExceptionUtilities.Unreachable; }
protected override SourcePropertyAccessorSymbol CreateExpressionBodiedAccessor( ArrowExpressionClauseSyntax syntax, PropertySymbol?explicitlyImplementedPropertyOpt, string?aliasQualifierOpt, bool isExplicitInterfaceImplementation, DiagnosticBag diagnostics) { // There should be no expression-bodied synthesized record properties throw ExceptionUtilities.Unreachable; }
/// <summary> /// If the property has a SetMethod, return that. Otherwise check the overridden /// property, if any. Repeat for each overridden property. /// </summary> public static MethodSymbol?GetOwnOrInheritedSetMethod(this PropertySymbol?property) { while ((object?)property != null) { MethodSymbol setMethod = property.SetMethod; if ((object?)setMethod != null) { return(setMethod); } property = property.OverriddenProperty; } return(null); }
private bool GetAwaitableExpressionInfo( BoundExpression expression, BoundExpression getAwaiterArgument, out bool isDynamic, out BoundExpression?getAwaiter, out PropertySymbol?isCompleted, out MethodSymbol?getResult, out BoundExpression?getAwaiterGetResultCall, SyntaxNode node, DiagnosticBag diagnostics) { Debug.Assert(TypeSymbol.Equals(expression.Type, getAwaiterArgument.Type, TypeCompareKind.ConsiderEverything)); isDynamic = false; getAwaiter = null; isCompleted = null; getResult = null; getAwaiterGetResultCall = null; if (!ValidateAwaitedExpression(expression, node, diagnostics)) { return(false); } if (expression.HasDynamicType()) { isDynamic = true; return(true); } if (!GetGetAwaiterMethod(getAwaiterArgument, node, diagnostics, out getAwaiter)) { return(false); } TypeSymbol awaiterType = getAwaiter.Type !; return(GetIsCompletedProperty(awaiterType, node, expression.Type !, diagnostics, out isCompleted) && AwaiterImplementsINotifyCompletion(awaiterType, node, diagnostics) && GetGetResultMethod(getAwaiter, node, expression.Type !, diagnostics, out getResult, out getAwaiterGetResultCall)); }
protected override SourcePropertyAccessorSymbol?CreateAccessorSymbol( bool isGet, CSharpSyntaxNode?syntax, PropertySymbol?explicitlyImplementedPropertyOpt, string?aliasQualifierOpt, bool isAutoPropertyAccessor, bool isExplicitInterfaceImplementation, DiagnosticBag diagnostics) { if (!isGet) { return(null); } Debug.Assert(syntax is object); return(SourcePropertyAccessorSymbol.CreateAccessorSymbol( ContainingType, this, _modifiers, ContainingType.Locations[0], syntax, diagnostics)); }
public SynthesizedRecordGetHashCode(SourceMemberContainerTypeSymbol containingType, PropertySymbol?equalityContract, int memberOffset, BindingDiagnosticBag diagnostics) : base(containingType, WellKnownMemberNames.ObjectGetHashCode, memberOffset, isReadOnly: containingType.IsRecordStruct, diagnostics) { Debug.Assert(containingType.IsRecordStruct == equalityContract is null); _equalityContract = equalityContract; }
/// <summary> /// Finds the IsCompleted property of an Awaiter type. /// </summary> /// <remarks> /// Spec 7.7.7.1: /// An Awaiter A has an accessible, readable instance property IsCompleted of type bool. /// </remarks> private bool GetIsCompletedProperty(TypeSymbol awaiterType, SyntaxNode node, TypeSymbol awaitedExpressionType, DiagnosticBag diagnostics, [NotNullWhen(true)] out PropertySymbol?isCompletedProperty) { var receiver = new BoundLiteral(node, ConstantValue.Null, awaiterType); var name = WellKnownMemberNames.IsCompleted; var qualified = BindInstanceMemberAccess(node, node, receiver, name, 0, default(SeparatedSyntaxList <TypeSyntax>), default(ImmutableArray <TypeWithAnnotations>), invoked: false, indexed: false, diagnostics); if (qualified.HasAnyErrors) { isCompletedProperty = null; return(false); } if (qualified.Kind != BoundKind.PropertyAccess) { Error(diagnostics, ErrorCode.ERR_NoSuchMember, node, awaiterType, WellKnownMemberNames.IsCompleted); isCompletedProperty = null; return(false); } isCompletedProperty = ((BoundPropertyAccess)qualified).PropertySymbol; if (isCompletedProperty.IsWriteOnly) { Error(diagnostics, ErrorCode.ERR_PropertyLacksGet, node, isCompletedProperty); isCompletedProperty = null; return(false); } if (isCompletedProperty.Type.SpecialType != SpecialType.System_Boolean) { Error(diagnostics, ErrorCode.ERR_BadAwaiterPattern, node, awaiterType, awaitedExpressionType); isCompletedProperty = null; return(false); } return(true); }
public SynthesizedRecordEquals(SourceMemberContainerTypeSymbol containingType, PropertySymbol?equalityContract, int memberOffset, BindingDiagnosticBag diagnostics) : base(containingType, WellKnownMemberNames.ObjectEquals, hasBody: true, memberOffset, diagnostics) { Debug.Assert(equalityContract is null == containingType.IsRecordStruct); _equalityContract = equalityContract; }
internal static IPropertySymbol? GetPublicSymbol(this PropertySymbol? symbol) { return symbol.GetPublicSymbol<IPropertySymbol>(); }