Created
October 26, 2016 03:52
-
-
Save toptensoftware/df13f8ee47d443ba503ce91d8b27e797 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MyLibrary | |
| { | |
| public MyLibrary() | |
| { | |
| pi = Math.PI; | |
| } | |
| public double pi { get; private set; } | |
| public double r { get; set; } | |
| public double rectArea(double width, double height) | |
| { | |
| return width * height; | |
| } | |
| public double rectPerimeter(double width, double height) | |
| { | |
| return (width + height) * 2; | |
| } | |
| } | |
| [TestMethod] | |
| public void Reflection() | |
| { | |
| // Create a library of helper function | |
| var lib = new MyLibrary(); | |
| lib.r = 10; | |
| // Create a context that uses the library | |
| var ctx = new ReflectionContext(lib); | |
| // Test | |
| Assert.AreEqual(Parser.Parse("rectArea(10,20)").Eval(ctx), 200); | |
| Assert.AreEqual(Parser.Parse("rectPerimeter(10,20)").Eval(ctx), 60); | |
| Assert.AreEqual(Parser.Parse("2 * pi * r").Eval(ctx), 2 * Math.PI * 10); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment