SPRNET-467

This commit is contained in:
eeichinger
2009-07-27 16:03:21 +00:00
parent 5a2e7c6c26
commit 231e096fac
29 changed files with 1433 additions and 716 deletions

View File

@@ -71,7 +71,7 @@ public static void SetValue(object root, string expression, IDictionary variable
tesla.PlaceOfBirth.City = "Smiljan";
string evaluatedName = (string) ExpressionEvaluator.GetValue(tesla, "Name");
string evaluatedName = (string) ExpressionEvaluator.GetValue(tesla, "Name");
string evaluatedCity = (string) ExpressionEvaluator.GetValue(tesla, "PlaceOfBirth.City"));</programlisting>
The value of 'evaluatedName' is 'Nikola Tesla' and that of 'evaluatedCity'
@@ -148,7 +148,7 @@ int maxValue = (int) ExpressionEvaluator.GetValue(null, "0x7FFFFFFF"); // eval
DateTime birthday = (DateTime) ExpressionEvaluator.GetValue(null, "date('1974/08/24')");
DateTime exactBirthday =
DateTime exactBirthday =
(DateTime) ExpressionEvaluator.GetValue(null, " date('19740824T131030', 'yyyyMMddTHHmmss')");
bool trueValue = (bool) ExpressionEvaluator.GetValue(null, "true");
@@ -266,10 +266,10 @@ new string[] {'abc', 'xyz'}</programlisting></para>
<para>Methods are invoked using typical C# programming syntax. You may
also invoke methods on literals.</para>
<programlisting language="csharp">//string literal
<programlisting language="csharp">//string literal
char[] chars = (char[]) ExpressionEvaluator.GetValue(null, "'test'.ToCharArray(1, 2)")) // 't','e'
//date literal
//date literal
int year = (int) ExpressionEvaluator.GetValue(null, "date('1974/08/24').AddYears(31).Year") // 2005
// object usage, calculate age of tesla navigating from the IEEE society.
@@ -372,6 +372,26 @@ string expression = @"IsMember('Nikola Tesla') and !IsMember('Mihajlo Pupin')";
bool falseValue = (bool) ExpressionEvaluator.GetValue(ieee, expression);</programlisting></para>
</sect3>
<sect3 xml:id="expressions-bitwise">
<title>Bitwise operators</title>
<para>The bitwise operators that are supported are
<emphasis>and</emphasis>, <emphasis>or</emphasis>, <emphasis>xor</emphasis> and <emphasis>not</emphasis>. Their use is demonstrated below.
Note, that the logical and bitwise operators are the same and their interpretation depends if you pass in integral values or boolean values.
<programlisting language="csharp">// AND
int result = (int) ExpressionEvaluator.GetValue(null, "1 and 3"); // 1 & 3
// OR
int result = (int) ExpressionEvaluator.GetValue(null, "1 or 3"); // 1 | 3
// XOR
int result = (int) ExpressionEvaluator.GetValue(null, "1 xor 3"); // 1 ^ 3
// NOT
int result = (int) ExpressionEvaluator.GetValue(null, "!1"); // ~1
</para>
</sect3>
<sect3 xml:id="expressions-math">
<title>Mathematical operators</title>
@@ -386,7 +406,7 @@ int two = (int)ExpressionEvaluator.GetValue(null, "1 + 1"); // 2
String testString = (String)ExpressionEvaluator.GetValue(null, "'test' + ' ' + 'string'"); //'test string'
DateTime dt = (DateTime)ExpressionEvaluator.GetValue(null, "date('1974-08-24') + 5"); // 8/29/1974
// Subtraction
int four = (int) ExpressionEvaluator.GetValue(null, "1 - -3"); //4
@@ -450,7 +470,7 @@ Inventor tesla = (Inventor) ExpressionEvaluator.GetValue(ieee, "Officers['vp'] =
last expression in the list. Examples of this are shown below
<programlisting language="csharp">//Perform property assignments and then return Name property.
String pupin = (String) ExpressionEvaluator.GetValue(ieee.Members,
String pupin = (String) ExpressionEvaluator.GetValue(ieee.Members,
"( [1].PlaceOfBirth.City = 'Beograd'; [1].PlaceOfBirth.Country = 'Serbia'; [1].Name )"));
// pupin = "Mihajlo Pupin"</programlisting></para>
@@ -514,12 +534,12 @@ Inventor pupin = (Inventor) ExpressionEvaluator.GetValue(ieee, "Officers[Society
<programlisting language="csharp">// simple ctor
DateTime dt = (DateTime) ExpressionEvaluator.GetValue(null, "new DateTime(1974, 8, 24)");
// Register Inventor type then create new inventor instance within Add method inside an expression list.
// Register Inventor type then create new inventor instance within Add method inside an expression list.
// Then return the new count of the Members collection.
TypeRegistry.RegisterType(typeof(Inventor));
int three = (int) ExpressionEvaluator.GetValue(ieee.Members, "{ Add(new Inventor('Aleksandar Seovic', date('1974-08-24'), 'Serbian')); Count}"));
</programlisting></para>
<para>As a convenience, Spring.NET also allows you to define named
@@ -602,8 +622,8 @@ ExpressionEvaluator.GetValue(ieee, "Officers['president'].( #root.Officers.Remov
IDictionary vars = new Hashtable();
vars["queryName"] = "Nikola Tesla";
string expression = @"IsMember(#queryName)
? #queryName + ' is a member of the ' + Name + ' Society'
string expression = @"IsMember(#queryName)
? #queryName + ' is a member of the ' + Name + ' Society'
: #queryName + ' is not a member of the ' + Name + ' Society'";
String queryResultString = (String) ExpressionEvaluator.GetValue(ieee, expression, vars));
@@ -868,7 +888,7 @@ object[] ordered = exp.GetValue(input); // { 1, 2.0, "a", 'b' }
if ((int)item % 2 == 0)
{
total = NumberUtils.Add(total, item);
}
}
}
else
{
@@ -905,11 +925,11 @@ object[] ordered = exp.GetValue(input); // { 1, 2.0, "a", 'b' }
{
. . .
// Retrieve context defined in the spring/context section of
// Retrieve context defined in the spring/context section of
// the standard .NET configuration file.
IApplicationContext ctx = ContextRegistry.GetContext();
int numMovies = (int) ExpressionEvaluator.GetValue(null,
int numMovies = (int) ExpressionEvaluator.GetValue(null,
"@(MyMovieLister).MoviesDirectedBy('Roberto Benigni').Length");
. . .