Object Dumper: a powerful tool in functional programming Coding

Source: Internet
Author: User

Post in English: Object Dumper: An Invaluable Tool for Writing Code in the Functional Programming Style

 

When developing C # applications using functional programming, you often need to output a set to the console. Object dumper is a powerful tool in this regard. In this example, only a few developers know about it.

Function Conversion usually requires continuous transformation: converts the set a => Set B => set c => the final set. This is the main point of my Functional Programming Tutorial topic.

When I was about to develop such a conversion, I first completed this conversion model in the brain. Sometimes (especially when writing temporary conversions), I will not design every transformation completely before coding. For example, when the source set is particularly troublesome, I first convert it into simple and clear data, and then convert it into a useful format to prepare for subsequent conversion. Sometimes I convert it to an anonymous type, and sometimes I immediately know that I want to convert it to a named type. No matter which method I select, Object Dumper will be a good tool to verify whether the previous conversion is correct before I write the next conversion.

When writing these conversions, I usually do not use a common debugger. I write a conversion, verify the result, write the next conversion, then verify, and so on ...... It is not always convenient to use the debugger. But I don't worry about it. I just need to use Object Dumper.

To use it, you only need to add ObjectDumper. cs to your project.

In the simplest usage, you can easily input any object to ObjectDumper:

var z = new{    A = "1",    B = "2"};ObjectDumper.Write(z);

This code will generate the following output:

A = 1 B = 2

 

You usually have a nested set:

var z = new{    Aaa = "Hello",    Bbb = "There",    Ccc = new[] { 1, 2, 3 }};ObjectDumper.Write(z);

 

Output:

Aaa = Hello Bbb = There Ccc =...

  

At this time, it will be very useful to view the content in the nested set, so you can pass an additional parameter to ObjectDumper to tell it to output the first layer of the nested set:

var z = new{    Aaa = "Hello",    Bbb = "There",    Ccc = new[] { 1, 2, 3 }};ObjectDumper.Write(z, 1);

 

This code will generate the following output:

Aaa = Hello Bbb = There Ccc =...
Ccc: 1
Ccc: 2
Ccc: 3
 

You can find the Object Dumper in the csharpsamples.zip file installed with Visual Studio 2008.

C: \ Program Files \ Microsoft Visual Studio 9.0 \ Samples \ 1033 \ CSharpSamples.zip

Because I want to do a lot of development for SharePoint and Hyper-V, Windows Server running 64 on my development computer, for this reason, the location of csharpsamples.zip is:

C: \ Program Files (x86) \ Microsoft Visual Studio 9.0 \ Samples \ 1033 \ CSharpSamples.zip

----------------------- Original article ------------------------------

[Errors are inevitable due to a limited level. Thank you for your criticism !]

In addition to the method described by the original author, you can also obtain ObjectDumper in the following way:

1. NuGet

Install-Package ObjectDumper

2. Download from the CodePlex site

Http://objectdumper.codeplex.com/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.