Example #1
0
            private void ProcessAnonymousProperty([NotNull] IQueryAnonymousTypeProperty anonymousProperty)
            {
                foreach (var anonymousTypeProperty in anonymousProperty.ContainingType.Properties)
                {
                    var property    = (IQueryAnonymousTypeProperty)anonymousTypeProperty;
                    var declaration = property.Declaration;

                    if (QueryFirstFromNavigator.GetByDeclaration(declaration) == null &&
                        QueryContinuationNavigator.GetByDeclaration(declaration) == null)
                    {
                        AnonymousTypes.Add(declaration);
                    }
                }
            }
            private void ProcessReferenceExpression(IReferenceExpression reference)
            {
                var declaredElement = reference.Reference.Resolve().DeclaredElement;

                var parameter = declaredElement as IParameter;

                if (parameter != null)
                {
                    var parametersOwner = parameter.ContainingParametersOwner;
                    if (parametersOwner == null)
                    {
                        return;
                    }

                    foreach (var closure in myClosures)
                    {
                        var queryPlatform = closure as IQueryParameterPlatform;
                        if (queryPlatform != null)
                        {
                            var platform = parametersOwner as IQueryParameterPlatform;
                            if (platform != null && queryPlatform == platform)
                            {
                                return;
                            }

                            // outer query parameter
                            AddCapture(closure, parameter);
                        }
                        else
                        {
                            // anonymous parameter access
                            if (ReferenceEquals(parametersOwner, closure))
                            {
                                return;
                            }

                            if (myClosures.Count == 1)
                            {
                                if (parametersOwner.Equals(myFunction))
                                {
                                    return;                     // simple parameter access
                                }
                                var accessor = myFunction as IAccessor;
                                if (accessor != null && accessor.OwnerMember.Equals(parametersOwner))
                                {
                                    return; // indexer parameter access
                                }
                            }

                            AddCapture(closure, parameter);
                        }
                    }

                    return;
                }

                var variable = declaredElement as ILocalVariable;

                if (variable != null)
                {
                    if (variable.IsStatic)
                    {
                        return;
                    }
                    if (variable.IsConstant)
                    {
                        return;
                    }

                    var declarations = variable.GetDeclarations();
                    if (declarations.Count == 1)
                    {
                        var declaration = declarations[0];
                        foreach (var closure in myClosures)
                        {
                            if (!(closure is IQueryParameterPlatform) &&
                                closure.Contains(declaration))
                            {
                                return;
                            }

                            AddCapture(closure, variable);
                        }
                    }

                    return;
                }

                var typeMember = declaredElement as ITypeMember;

                if (typeMember != null) // .this closure
                {
                    if (typeMember is ITypeElement)
                    {
                        return;
                    }
                    if (typeMember.IsStatic)
                    {
                        return;
                    }

                    var field = typeMember as IField;
                    if (field != null && field.IsConstant)
                    {
                        return;
                    }

                    AddThisCapture();
                    return;
                }

                var anonymousProperty = declaredElement as IQueryAnonymousTypeProperty;

                if (anonymousProperty != null)
                {
                    foreach (var anonymousTypeProperty in anonymousProperty.ContainingType.Properties)
                    {
                        var property    = (IQueryAnonymousTypeProperty)anonymousTypeProperty;
                        var declaration = property.Declaration;

                        if (QueryFirstFromNavigator.GetByDeclaration(declaration) == null &&
                            QueryContinuationNavigator.GetByDeclaration(declaration) == null)
                        {
                            AnonymousTypes.Add(declaration);
                        }
                    }
                }
            }