Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

Converting expando object to typed object #38

Closed
Remo opened this issue Jun 29, 2018 · 6 comments
Closed

Converting expando object to typed object #38

Remo opened this issue Jun 29, 2018 · 6 comments

Comments

@Remo
Copy link

Remo commented Jun 29, 2018

I'm playing around with chromely, pretty impressed so far, but one thing bothered me. Here we are working with an expandobject: https://github.com/mattkol/Chromely/blob/master/angular-react-vue/ChromelyVueCefSharp/Controllers/DemoController.cs#L96-L116

Having my backend in .NET I very much prefer to use typed objects. In case anyone else wants to do the same

  1. Add System.Web.Extensions as a reference to your project.
  2. Add a second constructor to the MovieInfo class
public MovieInfo()
{
}
  1. Convert the data using this code
var javaScriptSerializer = new JavaScriptSerializer();
List<MovieInfo> movies = javaScriptSerializer.ConvertToType<List<MovieInfo>>(request.PostData);

You can now work with movies in a nice way.

@Remo
Copy link
Author

Remo commented Jun 29, 2018

If we could acess the raw JSON data from ChromelyRequest we might be able to use the already available litjson.

@mattkol
Copy link
Member

mattkol commented Jun 30, 2018

@Remo thanks for pointing that out.

Chromely was designed to be extremely lightweight - only using external libraries when it is extremely required. I chose LitJSON because it was easier to embed. I wanted developers to use any Json serializer of their choice. Yes, the approach you suggested is in line with Chromely design approach, and I will look into integrating that in the future.

@mattkol
Copy link
Member

mattkol commented Jul 8, 2018

@Remo I tested the demos using JavaScriptSerializer as you suggested.

For CefSharp, this only works successfully for .NET Javascript Integration (Bounded objects) demos. CefGlue demos have similar issue - does not work for all demos. Each IPC communication type processes data differently.

For other demos to work, I had to do some tweaking. Since the DemoController is used for all IPC communication types .NET/Javascript integration, Generic Message Routing, Ajax HTTP/XHR and Websocket - it is advisable to leave it the way it is for consistency across demos.

Developers can then use approaches that suit their implementations

@Remo
Copy link
Author

Remo commented Jul 9, 2018

@mattkol thanks for keeping an eye on this!

I've also had another look and I believe there's an even easier solution. What do you think about this #40?

I didn't test the linux demos, but CefGlue and CefSharp work for me, it doesn't add a new dependency and converts to a propery list of movies.

@mattkol
Copy link
Member

mattkol commented Jul 9, 2018

@Remo you are welcome.

Sure I will look at the PR. Will be by weekend, currently out of town.

However, this is what I did too. The DemoController is for all IPC modes of communication, and as long as the PR works for all of them (NET/Javascript integration, Generic Message Routing, Ajax HTTP/XHR and Websocket ), then we will be fine.

For us to be on same page, when you said you tested CefGlue and CefSharp worked for you, all IPC demos? Each has at least 2 demo options. CefGlue has Websocket. I will retest to see what I may be missing.

I will keep you posted.

Thanks.

@Remo
Copy link
Author

Remo commented Jul 9, 2018

@mattkol I've tested the Ajax Demo and Message Router Demo in CefGlue and .NET/JavaScript Integration Demo and the Ajax Demo in CefSharp, but not the websocket, didn't notice it uses the DemoController/Movie class too. Will try to have a look.
Take as much time as you need, I'm just playing around with Chromely to see if it's something I want to use in the future. Not having to work with untyped structures is one part of getting there ;-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants