al3891 / custompackagereferences Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
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. ๐
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.