Ejemplo n.º 1
0
        private static string GetCapturedVariableFieldName(Symbol variable, ref int uniqueId)
        {
            if (IsThis(variable))
            {
                return(GeneratedNames.ThisProxyFieldName());
            }

            var local = variable as LocalSymbol;

            if ((object)local != null)
            {
                if (local.SynthesizedKind == SynthesizedLocalKind.LambdaDisplayClass)
                {
                    return(GeneratedNames.MakeLambdaDisplayLocalName(uniqueId++));
                }

                if (local.SynthesizedKind == SynthesizedLocalKind.ExceptionFilterAwaitHoistedExceptionLocal)
                {
                    return(GeneratedNames.MakeHoistedLocalFieldName(local.SynthesizedKind, uniqueId++));
                }

                if (local.SynthesizedKind == SynthesizedLocalKind.InstrumentationPayload)
                {
                    return(GeneratedNames.MakeSynthesizedInstrumentationPayloadLocalFieldName(uniqueId++));
                }

                if (local.SynthesizedKind == SynthesizedLocalKind.UserDefined && local.ScopeDesignatorOpt?.Kind() == SyntaxKind.SwitchSection)
                {
                    return(GeneratedNames.MakeHoistedLocalFieldName(local.SynthesizedKind, uniqueId++, local.Name));
                }

                //
                // @MattWindsor91 (Concept-C# 2017)
                //
                // We added a new type of synthesised variable to represent
                // concept witness dictionaries, so we must generate names for
                // them.

                if (local.SynthesizedKind == SynthesizedLocalKind.ConceptDictionary)
                {
                    return(GeneratedNames.MakeConceptDictionaryLocalFieldName(uniqueId++));
                }
            }

            Debug.Assert(variable.Name != null);
            return(variable.Name);
        }