protected MethodSymbol VisitMethodSymbol(MethodSymbol method) { if ((object)method == null) { return(null); } if (!method.ContainingType.IsAnonymousType) { // Method of a regular type return(((MethodSymbol)method.OriginalDefinition) .AsMember((NamedTypeSymbol)TypeMap.SubstituteType(method.ContainingType).AsTypeSymbolOnly()) .ConstructIfGeneric(TypeMap.SubstituteTypesWithoutModifiers(method.TypeArguments))); } // Method of an anonymous type var newType = (NamedTypeSymbol)TypeMap.SubstituteType(method.ContainingType).AsTypeSymbolOnly(); if (ReferenceEquals(newType, method.ContainingType)) { // Anonymous type symbol was not rewritten return(method); } // get a new method by name foreach (var member in newType.GetMembers(method.Name)) { if (member.Kind == SymbolKind.Method) { return((MethodSymbol)member); } } throw ExceptionUtilities.Unreachable; }
private BoundNode RewriteMethodGroupConversion(BoundConversion conversion) { // in a method group conversion, we may need to rewrite the selected method BoundMethodGroup operand = (BoundMethodGroup)conversion.Operand; BoundExpression originalReceiverOpt = operand.ReceiverOpt; BoundExpression receiverOpt; if (originalReceiverOpt == null) { receiverOpt = null; } else if (!conversion.IsExtensionMethod && conversion.SymbolOpt.IsStatic) { receiverOpt = new BoundTypeExpression(originalReceiverOpt.Syntax, null, VisitType(originalReceiverOpt.Type)); } else { receiverOpt = (BoundExpression)Visit(originalReceiverOpt); } TypeSymbol type = this.VisitType(conversion.Type); MethodSymbol method = conversion.SymbolOpt; // if the original receiver was a base access and is was rewritten, // change the method to point to the wrapper method if (BaseReferenceInReceiverWasRewritten(originalReceiverOpt, receiverOpt) && method.IsMetadataVirtual()) { method = GetMethodWrapperForBaseNonVirtualCall(method, conversion.Syntax); } method = VisitMethodSymbol(method); operand = operand.Update( TypeMap.SubstituteTypesWithoutModifiers(operand.TypeArgumentsOpt), method.Name, operand.Methods, operand.LookupSymbolOpt, operand.LookupError, operand.Flags, receiverOpt, operand.ResultKind); var conversionInfo = conversion.Conversion; if (conversionInfo.Method != (object)method) { conversionInfo = conversionInfo.SetConversionMethod(method); } return(conversion.Update( operand, conversionInfo, isBaseConversion: conversion.IsBaseConversion, @checked: conversion.Checked, explicitCastInCode: conversion.ExplicitCastInCode, constantValueOpt: conversion.ConstantValueOpt, type: type)); }
private ReducedExtensionMethodSymbol(MethodSymbol reducedFrom) { Debug.Assert((object)reducedFrom != null); Debug.Assert(reducedFrom.IsExtensionMethod); Debug.Assert((object)reducedFrom.ReducedFrom == null); Debug.Assert(reducedFrom.ConstructedFrom == reducedFrom); Debug.Assert(reducedFrom.ParameterCount > 0); _reducedFrom = reducedFrom; _typeMap = TypeMap.Empty.WithAlphaRename(reducedFrom, this, out _typeParameters); _typeArguments = _typeMap.SubstituteTypesWithoutModifiers(reducedFrom.TypeArguments); }
protected MethodSymbol VisitMethodSymbol(MethodSymbol method) { if ((object)method == null) { return(null); } if (method.IsTupleMethod) { // Method of a tuple type var oldType = method.ContainingType; var constructedFrom = method.ConstructedFrom; Debug.Assert(oldType.IsTupleType); var newType = (NamedTypeSymbol)TypeMap.SubstituteType(oldType).AsTypeSymbolOnly(); if ((object)newType == oldType) { // tuple type symbol was not rewritten return(constructedFrom.ConstructIfGeneric(TypeMap.SubstituteTypesWithoutModifiers(method.TypeArguments))); } Debug.Assert(newType.IsTupleType); Debug.Assert(oldType.TupleElementTypes.Length == newType.TupleElementTypes.Length); // get a new method by position var oldMembers = oldType.GetMembers(); var newMembers = newType.GetMembers(); Debug.Assert(oldMembers.Length == newMembers.Length); for (int i = 0; i < oldMembers.Length; i++) { if ((object)constructedFrom == oldMembers[i]) { return(((MethodSymbol)newMembers[i]).ConstructIfGeneric(TypeMap.SubstituteTypesWithoutModifiers(method.TypeArguments))); } } throw ExceptionUtilities.Unreachable; } else if (method.ContainingType.IsAnonymousType) { // Method of an anonymous type var newType = (NamedTypeSymbol)TypeMap.SubstituteType(method.ContainingType).AsTypeSymbolOnly(); if (ReferenceEquals(newType, method.ContainingType)) { // Anonymous type symbol was not rewritten return(method); } // get a new method by name foreach (var member in newType.GetMembers(method.Name)) { if (member.Kind == SymbolKind.Method) { return((MethodSymbol)member); } } throw ExceptionUtilities.Unreachable; } else { // Method of a regular type return(((MethodSymbol)method.OriginalDefinition) .AsMember((NamedTypeSymbol)TypeMap.SubstituteType(method.ContainingType).AsTypeSymbolOnly()) .ConstructIfGeneric(TypeMap.SubstituteTypesWithoutModifiers(method.TypeArguments))); } }
internal override ImmutableArray <TypeSymbol> GetConstraintTypes(ConsList <TypeParameterSymbol> inProgress) { return(_map.SubstituteTypesWithoutModifiers(_substitutedFrom.GetConstraintTypes(inProgress)).WhereAsArray(s_isNotObjectFunc).Distinct()); }