Esempio n. 1
0
        protected virtual object SubstituteValueIfRequired(object value)
        {
            Requires.NotNull(value, nameof(value));

            ISubstitutedValue substitutedValue;

            switch (this.direction)
            {
            case Direction.ToSubstitutedValue:
                if (Enum32Substitution.TrySubstituteValue(value, this.resolver, out substitutedValue) ||
                    TypeSubstitution.TrySubstituteValue(value, this.resolver, out substitutedValue) ||
                    TypeArraySubstitution.TrySubstituteValue(value, this.resolver, out substitutedValue))
                {
                    value = substitutedValue;
                }

                break;

            case Direction.ToOriginalValue:
                if ((substitutedValue = value as ISubstitutedValue) != null)
                {
                    value = substitutedValue.ActualValue;
                }

                break;

            default:
                throw Assumes.NotReachable();
            }

            return(value);
        }
 /// <summary>
 /// Creates a new TypeWithNode
 ///
 /// newType must be the result of applying the substitution to this.Type.
 /// </summary>
 internal TypeWithNode WithSubstitution(ITypeSymbol newType, TypeSubstitution subst, TypeSystem.Builder?tsBuilder)
 {
     if (this.Type is ITypeParameterSymbol tp)
     {
         var substituted = subst[tp.TypeParameterKind, tp.FullOrdinal()];
         Debug.Assert(SymbolEqualityComparer.Default.Equals(substituted.Type, newType));
         if (tsBuilder != null)
         {
             var newNode = tsBuilder.Join(substituted.Node, this.Node, new EdgeLabel());
             return(substituted.WithNode(newNode));
         }
         else
         {
             return(substituted);
         }
     }
     else if (this.Type is INamedTypeSymbol thisNamedTypeSymbol && newType is INamedTypeSymbol newNamedTypeSymbol)
     {
         Debug.Assert(SymbolEqualityComparer.Default.Equals(thisNamedTypeSymbol.OriginalDefinition, newNamedTypeSymbol.OriginalDefinition));
         Debug.Assert(newNamedTypeSymbol.FullArity() == this.TypeArguments.Count);
         TypeWithNode[] newTypeArgs = new TypeWithNode[this.TypeArguments.Count];
         var            newNamedTypeSymbolTypeArguments = newNamedTypeSymbol.FullTypeArguments().ToList();
         for (int i = 0; i < newTypeArgs.Length; i++)
         {
             newTypeArgs[i] = this.TypeArguments[i].WithSubstitution(newNamedTypeSymbolTypeArguments[i], subst, tsBuilder);
         }
         return(new TypeWithNode(newType, this.Node, newTypeArgs));
     }
Esempio n. 3
0
        public override ImmutableArray <CustomModifier> GetTypeArgumentCustomModifiers(int ordinal)
        {
            if (_hasTypeArgumentsCustomModifiers)
            {
                return(TypeSubstitution.GetTypeArgumentsCustomModifiersFor(_constructedFrom.OriginalDefinition.TypeParameters[ordinal]));
            }

            return(GetEmptyTypeArgumentCustomModifiers(ordinal));
        }