コード例 #1
0
        public override void VisitExpressionStatement(ExpressionStatement expressionStatement)
        {
            var resolveResult = ResolveWithConversion(expressionStatement.Expression);
            if (resolveResult is InvocationResolveResult && ((InvocationResolveResult)resolveResult).Member is IMethod) {
                var member = ((InvocationResolveResult)resolveResult).Member;
                if (((IUnresolvedMethod)((InvocationResolveResult)resolveResult).Member.UnresolvedMember).IsPartialMethodDeclaration) {	// This test is OK according to https://github.com/icsharpcode/NRefactory/issues/12
                    // Invocation of a partial method without definition - remove (yes, I too feel the arguments should be evaluated but the spec says no.
                    return;
                }
                var cas = member.Attributes.Where(a => a.AttributeType.FullName == "System.Diagnostics.ConditionalAttribute").Select(a => (string)a.PositionalArguments[0].ConstantValue).ToList();
                if (cas.Count > 0) {
                    if (!cas.Any(x => _definedSymbols.Contains(x))) {
                        // Invocation of conditional method, but the symbol is not defined.
                        return;
                    }
                }
            }

            var compiled = _expressionCompiler.Compile(expressionStatement.GetRegion().FileName, expressionStatement.StartLocation, resolveResult, false);
            _result.AddRange(compiled.AdditionalStatements);
            _result.Add(new JsExpressionStatement(compiled.Expression));
        }