|
| 1 | +// Description: C# Eval Function | Evaluate, Compile and Execute C# code and expression at runtime. |
| 2 | +// Website & Documentation: https://github.com/zzzprojects/Eval-Expression.NET |
| 3 | +// Forum & Issues: https://github.com/zzzprojects/Eval-Expression.NET/issues |
| 4 | +// License: https://github.com/zzzprojects/Eval-Expression.NET/blob/master/LICENSE |
| 5 | +// More projects: http://www.zzzprojects.com/ |
| 6 | +// Copyright © ZZZ Projects Inc. 2014 - 2017. All rights reserved. |
| 7 | + |
| 8 | +using System.Collections.Generic; |
| 9 | + |
| 10 | +namespace System.Linq.Dynamic.Core |
| 11 | +{ |
| 12 | + internal static class Dynamic |
| 13 | + { |
| 14 | + internal static object DynamicIndex(object obj, string name) |
| 15 | + { |
| 16 | + // CAUTION: This method is called via reflection, so even with 0 reference, the method is used |
| 17 | + // var method = typeof(Dynamic).GetMethod("DynamicIndex", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); |
| 18 | + // return Expression.Call(null, method, instance, Expression.Constant(id)); |
| 19 | + |
| 20 | + // TBD: If we want to really support Expando Object for properties & method |
| 21 | + // - We will need to add a reference to: Microsoft.CSharp.dll |
| 22 | + // - Copy source from Z.Expressions.Eval\Z.Expressions.Compiler.Shared\CodeCompiler\CSharp\Compiler\Dynamic\DynamicIndexer.cs and other files |
| 23 | + |
| 24 | + // At this moment, this is only a very quick fix for issue: https://github.com/zzzprojects/System.Linq.Dynamic.Core/issues/397 |
| 25 | + // To replace DynamicGetMemberBinder.cs old logic that was caching the result |
| 26 | + |
| 27 | + var dictionary = obj as IDictionary<string, object>; |
| 28 | + if (dictionary == null) |
| 29 | + { |
| 30 | + throw new InvalidOperationException("Target object is not an ExpandoObject"); |
| 31 | + } |
| 32 | + |
| 33 | + return dictionary[name]; |
| 34 | + } |
| 35 | + } |
| 36 | +} |
0 commit comments