Transformed code uses var type instead of dynamic type specified in the original source code.. #262
-
Hello, I have the following line of code in my aspect to execute my code:
The generated/transformed output code becomes this:
The orignal method signature is this:
My OverrideMethod signature and code looks like this:
The problem is, the transformed code changes my dynamic variable to a var variable and the dynamic data is not recognized then. I've tried Convert.ChangeType(..), Casting, Assigning to individual variables as var & dynamic with no luck. Once the result comes back as a var I lose the dynamic access to child objects. Am I doing something wrong or could this be a bug in the transformation? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
First, you can try calling |
Beta Was this translation helpful? Give feedback.
-
If you know you have foreach (var item in (IEnumerable<object>)((OkObjectResult)result.Result).Value)
{
sb.AppendLine(System.Text.Json.JsonSerializer.Serialize(item, new JsonSerializerOptions { WriteIndented = true }));
} If you actually want to use ActionResultHelper.AppendResultValues(sb, result);
...
class ActionResultHelper
{
public static void AppendResultValues(StringBuilder sb, dynamic result)
{
foreach (var item in result.Result.Value)
{
sb.AppendLine(System.Text.Json.JsonSerializer.Serialize(item, new JsonSerializerOptions { WriteIndented = true }));
}
}
} |
Beta Was this translation helpful? Give feedback.
-
We are going to table this for the time being and just take a standard object oriented approach to add this to the 9 methods that I need it on for right now. Thanks for the information. |
Beta Was this translation helpful? Give feedback.
We are going to table this for the time being and just take a standard object oriented approach to add this to the 9 methods that I need it on for right now.
Thanks for the information.