crashanalysercmd/PerfToolsSharedLibraries/Engine/SymBuildParsingLib/Utils/SymExpressionEvaluator.cs
equal
deleted
inserted
replaced
|
1 /* |
|
2 * Copyright (c) 2004-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 using System; |
|
19 using Microsoft.JScript; |
|
20 using Microsoft.JScript.Vsa; |
|
21 using Microsoft.Vsa; |
|
22 |
|
23 |
|
24 namespace SymBuildParsingLib.Utils |
|
25 { |
|
26 public class SymExpressionEvaluator |
|
27 { |
|
28 #region API |
|
29 public static object Evaluate( string aExpression ) |
|
30 { |
|
31 object ret = null; |
|
32 // |
|
33 try |
|
34 { |
|
35 ret = Microsoft.JScript.Eval.JScriptEvaluate( aExpression, iScriptEngine ); |
|
36 } |
|
37 catch (Exception) |
|
38 { |
|
39 ret = false; |
|
40 } |
|
41 // |
|
42 return ret; |
|
43 } |
|
44 |
|
45 public static bool EvaluateAsBoolean( string aExpression ) |
|
46 { |
|
47 bool ret = false; |
|
48 // |
|
49 object result = Evaluate( aExpression ); |
|
50 // |
|
51 if ( result != null ) |
|
52 { |
|
53 if ( result is bool ) |
|
54 { |
|
55 ret = (bool) result; |
|
56 } |
|
57 else |
|
58 { |
|
59 // Anything non-NULL that is not a bool will be treated |
|
60 // as 'true' |
|
61 ret = true; |
|
62 } |
|
63 } |
|
64 else |
|
65 { |
|
66 // Null evaluation so we'll treat that as 'false' |
|
67 ret = false; |
|
68 } |
|
69 // |
|
70 return ret; |
|
71 } |
|
72 #endregion |
|
73 |
|
74 #region Data members |
|
75 private static VsaEngine iScriptEngine = VsaEngine.CreateEngine(); |
|
76 #endregion |
|
77 } |
|
78 } |