diff --git a/src/Compilers/CSharp/Portable/Symbols/Retargeting/RetargetingParameterSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Retargeting/RetargetingParameterSymbol.cs index dd32f3e7212af..d2c1941eba75a 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Retargeting/RetargetingParameterSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Retargeting/RetargetingParameterSymbol.cs @@ -5,7 +5,9 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; +using System.Threading; using Microsoft.CodeAnalysis.CSharp.Emit; +using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.Symbols.Retargeting { @@ -23,6 +25,8 @@ internal abstract class RetargetingParameterSymbol : WrappedParameterSymbol /// private ImmutableArray _lazyCustomAttributes; + private TypeWithAnnotations? _lazyTypeWithAnnotations; + protected RetargetingParameterSymbol(ParameterSymbol underlyingParameter) : base(underlyingParameter) { @@ -38,7 +42,12 @@ public sealed override TypeWithAnnotations TypeWithAnnotations { get { - return this.RetargetingModule.RetargetingTranslator.Retarget(_underlyingParameter.TypeWithAnnotations, RetargetOptions.RetargetPrimitiveTypesByTypeCode); + if (!_lazyTypeWithAnnotations.HasValue) + { + _lazyTypeWithAnnotations = this.RetargetingModule.RetargetingTranslator.Retarget(_underlyingParameter.TypeWithAnnotations, RetargetOptions.RetargetPrimitiveTypesByTypeCode); + } + + return _lazyTypeWithAnnotations.Value; } }