Giter Club home page Giter Club logo

custompackagereferences's People

Contributors

al3891 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

custompackagereferences's Issues

Consider Using Surrogates (POCOs) Rather Than DOM Elements

This is a widespread problem and needs thorough ecosystem-wide correction. :P

I see a lot of this:
Example.

This is incredibly labor-intensive and error-prone. Please consider a surrogate (or rather, POCO ๐Ÿ˜„) design instead:

[Fact]
public void BetterSerializationTrustMe()
{
	var file = File.ReadAllText(@"C:\path\to\file.txt");
	var definition = JsonConvert.DeserializeObject<ProjectDefinition>(file);
	foreach (var reference in definition.References)
	{
		// do stuff.
	}
}

class ProjectDefinition
{
	[JsonProperty("dependencies")]
	public References References { get; set; } = new References();
}

[JsonArray("dependencies")]
class References : Collection<PackageReference> {}

class PackageReference
{
	[JsonProperty("name")]
	public string Name { get; set; }

	[JsonProperty("version")]
	public Version Version { get; set; }
}

This is super example code. I did not run this, but made it to get the point across. You will notice there is no linq statement as all of that is handled in JsonConvert.DeserializeObject for you.

This can be made even better by generalizing the surrogates and decoupling JSON.NET-specific attributes (making using of the JsonSerializerSettings) class.

This is why I am so hardup on POCO. As you do not have to dick around for a schema and dive into LINQ land to translate your data to the target constructs in your code. You use one line (JsonConvert.DeserializeObject) and boom! you're done. ๐Ÿ˜›

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.