Few queries regarding generic and Dictionary<string, object> support #244
Unanswered
jrkumar-conga
asked this question in
Q&A
Replies: 1 comment 2 replies
-
Currently support for generics is limited. So, a generic return method is not possible currently
You can send Dictionary<string, object> as input but it can't assume type on it own. var inputData = new Dictionary<string,object>{
{"cost",1}
};
dynamic dynamicInputData = new ExpandoObject();
foreach(var kv in inputData){
(dynamicInputData as IDictionary<string,object>).Add(kv.Key,kv.Value);
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi @abbasc52
Q1.Whether we can call any method with generic return type inside a expression?
for e.g if a method is like
public T GetFieldValue<T>(string fieldName)
Is it possible to write in expression like
"input1.GetFieldValue<string>(\"somefield\")" ?
because when we try this getting exception
System.Linq.Dynamic.Core.Exceptions.ParseException: 'No property or field 'GetCustomFieldValue' exists in type 'MyObject'
Also
Q2. Whether Dictionary<string, object> can be sent as input?
I know Dictionary<string, object> is supported, however facing the problem to convert each value to it's type before using it in expression.
For e.g.
Now if the expression is like
"input1.Price * 0.2"
getting below exceptionSystem.Linq.Dynamic.Core.Exceptions.ParseException: 'Operator '*' incompatible with operand types 'Object' and 'Double''
Same thing with DateTime also.
Our expressions are stored in DB so it will be difficult to parse and change each expression on runtime.
Please let me know if you want more information.
Beta Was this translation helpful? Give feedback.
All reactions