Skip to main content
Fixed code indentation, removed dubious advice on answer-copying.
Source Link
Mast
  • 13.9k
  • 12
  • 57
  • 128
// this class (like all the others) are of course much more complicated than this. // There's also a lot of abstraction etc (you can see the actual code on the github I've linked at the start). SomeConfig config = new SomeConfig { Options = new SomeOptions { SomeInt = 2, SomeString = null, // any trace of this property will not be present in the expando object Axes = new List<Axis> { new Axis() // this axis will also be an expandoObject after being extracted from the json } }, Data = new SomeData { Data = new List<int> { 1, 2, 3, 4, 5 }, SomeString = "asdf" } }; dynamic expando = /* ParseConfigToJsonWithoutNulls -> ParseJsonToExpandoObject */ IJSRuntime jsRT = GetTheRuntime(); jsRT.InvokeAsync("blabla", expando); // this would NOT work because ExpandoObject cannot be serialized to json correctly and throws a runtime error   // this method is what we need in the best way possible without missing something :) Dictionary<string, object> dictFromExpando = ConvertExpandoToDictonary(expando); // so the only purpose of the ConvertExpandoToDictonary is to recursively convert all the ExpandoObjects to Dictionaries as they are serializable // I have to do this recursively since there are nested ExpandoObjects that were created when parsing the huge json to the ExpandoObject with Json.Net // I have decided to go with Dictionaries because it works and ExpandoObject implements the interface IDictionary<string, object> jsRT.InvokeAsync("blabla", dictFromExpando); // this now works perfectly fine 

I have asked a new, much more detailed question. Please have a look at it if you have the time :)
Also I have no problem with people copying their answers 1:1 if they are still accurate.

// this class (like all the others) are of course much more complicated than this. // There's also a lot of abstraction etc (you can see the actual code on the github I've linked at the start). SomeConfig config = new SomeConfig { Options = new SomeOptions { SomeInt = 2, SomeString = null, // any trace of this property will not be present in the expando object Axes = new List<Axis> { new Axis() // this axis will also be an expandoObject after being extracted from the json } }, Data = new SomeData { Data = new List<int> { 1, 2, 3, 4, 5 }, SomeString = "asdf" } }; dynamic expando = /* ParseConfigToJsonWithoutNulls -> ParseJsonToExpandoObject */ IJSRuntime jsRT = GetTheRuntime(); jsRT.InvokeAsync("blabla", expando); // this would NOT work because ExpandoObject cannot be serialized to json correctly and throws a runtime error   // this method is what we need in the best way possible without missing something :) Dictionary<string, object> dictFromExpando = ConvertExpandoToDictonary(expando); // so the only purpose of the ConvertExpandoToDictonary is to recursively convert all the ExpandoObjects to Dictionaries as they are serializable // I have to do this recursively since there are nested ExpandoObjects that were created when parsing the huge json to the ExpandoObject with Json.Net // I have decided to go with Dictionaries because it works and ExpandoObject implements the interface IDictionary<string, object> jsRT.InvokeAsync("blabla", dictFromExpando); // this now works perfectly fine 

I have asked a new, much more detailed question. Please have a look at it if you have the time :)
Also I have no problem with people copying their answers 1:1 if they are still accurate.

// this class (like all the others) are of course much more complicated than this. // There's also a lot of abstraction etc (you can see the actual code on the github I've linked at the start). SomeConfig config = new SomeConfig { Options = new SomeOptions { SomeInt = 2, SomeString = null, // any trace of this property will not be present in the expando object Axes = new List<Axis> { new Axis() // this axis will also be an expandoObject after being extracted from the json } }, Data = new SomeData { Data = new List<int> { 1, 2, 3, 4, 5 }, SomeString = "asdf" } }; dynamic expando = /* ParseConfigToJsonWithoutNulls -> ParseJsonToExpandoObject */ IJSRuntime jsRT = GetTheRuntime(); jsRT.InvokeAsync("blabla", expando); // this would NOT work because ExpandoObject cannot be serialized to json correctly and throws a runtime error // this method is what we need in the best way possible without missing something :) Dictionary<string, object> dictFromExpando = ConvertExpandoToDictonary(expando); // so the only purpose of the ConvertExpandoToDictonary is to recursively convert all the ExpandoObjects to Dictionaries as they are serializable // I have to do this recursively since there are nested ExpandoObjects that were created when parsing the huge json to the ExpandoObject with Json.Net // I have decided to go with Dictionaries because it works and ExpandoObject implements the interface IDictionary<string, object> jsRT.InvokeAsync("blabla", dictFromExpando); // this now works perfectly fine 

I have asked a new, much more detailed question. Please have a look at it if you have the time :)

Add link to new question
Source Link
Joelius
  • 355
  • 2
  • 13
// this class (like all the others) are of course much more complicated than this. // There's also a lot of abstraction etc (you can see the actual code on the github I've linked at the start). SomeConfig config = new SomeConfig { Options = new SomeOptions { SomeInt = 2, SomeString = null, // any trace of this property will not be present in the expando object Axes = new List<Axis> { new Axis() // this axis will also be an expandoObject after being extracted from the json } }, Data = new SomeData { Data = new List<int> { 1, 2, 3, 4, 5 }, SomeString = "asdf" } }; dynamic expando = /* ParseConfigToJsonWithoutNulls -> ParseJsonToExpandoObject */ IJSRuntime jsRT = GetTheRuntime(); jsRT.InvokeAsync("blabla", expando); // this would NOT work because ExpandoObject cannot be serialized to json correctly and throws a runtime error // this method is what we need in the best way possible without missing something :) Dictionary<string, object> dictFromExpando = ConvertExpandoToDictonary(expando); // so the only purpose of the ConvertExpandoToDictonary is to recursively convert all the ExpandoObjects to Dictionaries as they are serializable // I have to do this recursively since there are nested ExpandoObjects that were created when parsing the huge json to the ExpandoObject with Json.Net // I have decided to go with Dictionaries because it works and ExpandoObject implements the interface IDictionary<string, object> jsRT.InvokeAsync("blabla", dictFromExpando); // this now works perfectly fine ``` 

EDIT 2:

I have asked a new, much more detailed question. Please have a look at it if you have the time :)
Also I have no problem with people copying their answers 1:1 if they are still accurate.

// this class (like all the others) are of course much more complicated than this. // There's also a lot of abstraction etc (you can see the actual code on the github I've linked at the start). SomeConfig config = new SomeConfig { Options = new SomeOptions { SomeInt = 2, SomeString = null, // any trace of this property will not be present in the expando object Axes = new List<Axis> { new Axis() // this axis will also be an expandoObject after being extracted from the json } }, Data = new SomeData { Data = new List<int> { 1, 2, 3, 4, 5 }, SomeString = "asdf" } }; dynamic expando = /* ParseConfigToJsonWithoutNulls -> ParseJsonToExpandoObject */ IJSRuntime jsRT = GetTheRuntime(); jsRT.InvokeAsync("blabla", expando); // this would NOT work because ExpandoObject cannot be serialized to json correctly and throws a runtime error // this method is what we need in the best way possible without missing something :) Dictionary<string, object> dictFromExpando = ConvertExpandoToDictonary(expando); // so the only purpose of the ConvertExpandoToDictonary is to recursively convert all the ExpandoObjects to Dictionaries as they are serializable // I have to do this recursively since there are nested ExpandoObjects that were created when parsing the huge json to the ExpandoObject with Json.Net // I have decided to go with Dictionaries because it works and ExpandoObject implements the interface IDictionary<string, object> jsRT.InvokeAsync("blabla", dictFromExpando); // this now works perfectly fine ``` 
// this class (like all the others) are of course much more complicated than this. // There's also a lot of abstraction etc (you can see the actual code on the github I've linked at the start). SomeConfig config = new SomeConfig { Options = new SomeOptions { SomeInt = 2, SomeString = null, // any trace of this property will not be present in the expando object Axes = new List<Axis> { new Axis() // this axis will also be an expandoObject after being extracted from the json } }, Data = new SomeData { Data = new List<int> { 1, 2, 3, 4, 5 }, SomeString = "asdf" } }; dynamic expando = /* ParseConfigToJsonWithoutNulls -> ParseJsonToExpandoObject */ IJSRuntime jsRT = GetTheRuntime(); jsRT.InvokeAsync("blabla", expando); // this would NOT work because ExpandoObject cannot be serialized to json correctly and throws a runtime error // this method is what we need in the best way possible without missing something :) Dictionary<string, object> dictFromExpando = ConvertExpandoToDictonary(expando); // so the only purpose of the ConvertExpandoToDictonary is to recursively convert all the ExpandoObjects to Dictionaries as they are serializable // I have to do this recursively since there are nested ExpandoObjects that were created when parsing the huge json to the ExpandoObject with Json.Net // I have decided to go with Dictionaries because it works and ExpandoObject implements the interface IDictionary<string, object> jsRT.InvokeAsync("blabla", dictFromExpando); // this now works perfectly fine 

EDIT 2:

I have asked a new, much more detailed question. Please have a look at it if you have the time :)
Also I have no problem with people copying their answers 1:1 if they are still accurate.

Tweeted twitter.com/StackCodeReview/status/1146297661001273349
Became Hot Network Question
added 2007 characters in body
Source Link
Joelius
  • 355
  • 2
  • 13

EDIT 1:

Because I feel like I have not made clear how I will use this function, I have some demo-code for you. This will of course not compile, it's just to show how and why I need this method.
If this edit is problematic because I'm adding new code, I will post a new, more complete question later on (I sadly don't have anymore time today).

// this class (like all the others) are of course much more complicated than this. // There's also a lot of abstraction etc (you can see the actual code on the github I've linked at the start). SomeConfig config = new SomeConfig { Options = new SomeOptions { SomeInt = 2, SomeString = null, // any trace of this property will not be present in the expando object Axes = new List<Axis> { new Axis() // this axis will also be an expandoObject after being extracted from the json } }, Data = new SomeData { Data = new List<int> { 1, 2, 3, 4, 5 }, SomeString = "asdf" } }; dynamic expando = /* ParseConfigToJsonWithoutNulls -> ParseJsonToExpandoObject */ IJSRuntime jsRT = GetTheRuntime(); jsRT.InvokeAsync("blabla", expando); // this would NOT work because ExpandoObject cannot be serialized to json correctly and throws a runtime error // this method is what we need in the best way possible without missing something :) Dictionary<string, object> dictFromExpando = ConvertExpandoToDictonary(expando); // so the only purpose of the ConvertExpandoToDictonary is to recursively convert all the ExpandoObjects to Dictionaries as they are serializable // I have to do this recursively since there are nested ExpandoObjects that were created when parsing the huge json to the ExpandoObject with Json.Net // I have decided to go with Dictionaries because it works and ExpandoObject implements the interface IDictionary<string, object> jsRT.InvokeAsync("blabla", dictFromExpando); // this now works perfectly fine ``` 

EDIT 1:

Because I feel like I have not made clear how I will use this function, I have some demo-code for you. This will of course not compile, it's just to show how and why I need this method.
If this edit is problematic because I'm adding new code, I will post a new, more complete question later on (I sadly don't have anymore time today).

// this class (like all the others) are of course much more complicated than this. // There's also a lot of abstraction etc (you can see the actual code on the github I've linked at the start). SomeConfig config = new SomeConfig { Options = new SomeOptions { SomeInt = 2, SomeString = null, // any trace of this property will not be present in the expando object Axes = new List<Axis> { new Axis() // this axis will also be an expandoObject after being extracted from the json } }, Data = new SomeData { Data = new List<int> { 1, 2, 3, 4, 5 }, SomeString = "asdf" } }; dynamic expando = /* ParseConfigToJsonWithoutNulls -> ParseJsonToExpandoObject */ IJSRuntime jsRT = GetTheRuntime(); jsRT.InvokeAsync("blabla", expando); // this would NOT work because ExpandoObject cannot be serialized to json correctly and throws a runtime error // this method is what we need in the best way possible without missing something :) Dictionary<string, object> dictFromExpando = ConvertExpandoToDictonary(expando); // so the only purpose of the ConvertExpandoToDictonary is to recursively convert all the ExpandoObjects to Dictionaries as they are serializable // I have to do this recursively since there are nested ExpandoObjects that were created when parsing the huge json to the ExpandoObject with Json.Net // I have decided to go with Dictionaries because it works and ExpandoObject implements the interface IDictionary<string, object> jsRT.InvokeAsync("blabla", dictFromExpando); // this now works perfectly fine ``` 
Rollback to Revision 2
Source Link
Loading
added 455 characters in body
Source Link
Joelius
  • 355
  • 2
  • 13
Loading
tag
Link
dfhwze
  • 14.2k
  • 3
  • 40
  • 101
Loading
Source Link
Joelius
  • 355
  • 2
  • 13
Loading