コード例 #1
0
        private void CreateInitialProxies(
            TypeMap TypeMap,
            IOrderedEnumerable <Symbol> captured,
            MultiDictionary <Symbol, CSharpSyntaxNode> locations)
        {
            foreach (var sym in captured)
            {
                var local = sym as LocalSymbol;
                if ((object)local != null && local.DeclarationKind != LocalDeclarationKind.CompilerGenerated)
                {
                    Debug.Assert(local.RefKind == RefKind.None); // there are no user-declared ref variables
                    MakeInitialProxy(TypeMap, locations, local);
                    continue;
                }

                var parameter = sym as ParameterSymbol;
                if ((object)parameter != null)
                {
                    if (parameter.IsThis)
                    {
                        var proxyField = F.StateMachineField(method.ContainingType, GeneratedNames.IteratorThisProxyName(), isPublic: true);
                        variableProxies.Add(parameter, new CapturedToFrameSymbolReplacement(proxyField));

                        if (PreserveInitialLocals)
                        {
                            var initialThis = method.ContainingType.IsStructType() ?
                                              F.StateMachineField(method.ContainingType, GeneratedNames.IteratorThisProxyProxyName(), isPublic: true) : proxyField;

                            initialParameters.Add(parameter, new CapturedToFrameSymbolReplacement(initialThis));
                        }
                    }
                    else
                    {
                        var proxyField = F.StateMachineField(TypeMap.SubstituteType(parameter.Type), parameter.Name, isPublic: true);
                        variableProxies.Add(parameter, new CapturedToFrameSymbolReplacement(proxyField));

                        if (PreserveInitialLocals)
                        {
                            string proxyName = GeneratedNames.IteratorParameterProxyName(parameter.Name);
                            initialParameters.Add(parameter, new CapturedToFrameSymbolReplacement(
                                                      F.StateMachineField(TypeMap.SubstituteType(parameter.Type), proxyName, isPublic: true)));
                        }
                        if (parameter.Type.IsRestrictedType())
                        {
                            // CS4013: Instance of type '{0}' cannot be used inside an anonymous function, query expression, iterator block or async method
                            diagnostics.Add(ErrorCode.ERR_SpecialByRefInLambda, parameter.Locations[0], parameter.Type);
                        }
                    }
                }
            }
        }