Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Convert object data to CSV for display.

Posted on 2016-08-05
8
Medium Priority
?
44 Views
Last Modified: 2016-08-09
Hi

I have an object to work with that has a data field of 'resources' that are presented as a set of name / value pairs. The attached image shows what these look like.

How would I get this data into a comma separated list for display?

Regards

Andy
Locs.png
0
Comment
Question by:Andy Green
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 13

Expert Comment

by:Jitendra Patil
ID: 41744024
0
 
LVL 3

Author Comment

by:Andy Green
ID: 41744046
Hi

Its not the whole object I want to parse out rather just the resource data item.

My initial attempt was to cast the resource dataitem as an IDictonary and use LINQ to parse that out, then wondered whether there was a more efficient way,

Andy
0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 41745395
It would be better if you give more information about the type of "resources" and how you access it. And more about requirements. However if it can be casted into IDictionary or Dictionary the way you mentioned above seems to be a right way I believe.

May be use something like
String names = string.Join(", ", myDict.Select(x => x.Key + "-" + x.Value));

Open in new window

or
string s = string.Join(";", myDict.Select(x => x.Key + "=" + x.Value).ToArray());

Open in new window

or simply
myDict.Select(x => x.Key + "=" + x.Value).ToArray();

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:Andy Green
ID: 41746778
Thanks, How do I get this into a Dictionary. I have tried several ways and this one runs OK but always returns null.

var resourceList = DataBinder.Eval(e.Item.DataItem, "Resources") as System.Collections.Generic.Dictionary<string, string>;

The shape of the data can be seen in the image in the OP/

Regards

Andy
0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 41747880
What is the type of the .Resources field? I thought it was IDictionary?...
0
 
LVL 3

Author Comment

by:Andy Green
ID: 41747960
It's a name value pair, as a child of the main location object. It is ienumerable. If I use intelligence it just says object with no specific type.

Sorry to be vague, all I can do is point you to the image I posted on the OP that shows the main object and resources as a child.

Thanks for your help, Andy
0
 
LVL 30

Accepted Solution

by:
anarki_jimbel earned 2000 total points
ID: 41748010
May be, try something like:

Dictionary<int, string> myDict= resourcesList.GetComponents().ToDictionary(x => x.Key, x => x.Value);

Open in new window


or

Dictionary<int, string> myDict= e.Item.DataItem.resources.GetComponents().ToDictionary(x => x.Key, x => x.Value);

Open in new window

0
 
LVL 3

Author Closing Comment

by:Andy Green
ID: 41748521
Thanks for sticking with me.

anarki_jimbel I had to modify your sample to get to the data, but the construct for the Dictionary was what I needed:

 Dictionary<int, string> resourceList = DataBinder.Eval(e.Item.DataItem, "Resources") as Dictionary<int, string>;  

And the LINQ worked too to create the string.

Thank you
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question