Rocket.Libraries.DataModeling
1.1.0
See the version list below for details.
dotnet add package Rocket.Libraries.DataModeling --version 1.1.0
NuGet\Install-Package Rocket.Libraries.DataModeling -Version 1.1.0
<PackageReference Include="Rocket.Libraries.DataModeling" Version="1.1.0" />
paket add Rocket.Libraries.DataModeling --version 1.1.0
#r "nuget: Rocket.Libraries.DataModeling, 1.1.0"
// Install Rocket.Libraries.DataModeling as a Cake Addin #addin nuget:?package=Rocket.Libraries.DataModeling&version=1.1.0 // Install Rocket.Libraries.DataModeling as a Cake Tool #tool nuget:?package=Rocket.Libraries.DataModeling&version=1.1.0
Rocket.Libraries.DataModeling
Do a lot of data formatting for presentation. Don't pepper your code in random places with formatting statements. Instead, use this library to decorate your class properties with the desired final format.
Sounds vague? Read on, it is quite straightforward once you've seen the code examples.
Quick Start
1. Installation
Install the package from nuget
2. Configure your dotnet app
- Include in your startup.cs file.
using Rocket.Libraries.DataModeling.Configuration;
- Register services auth library in your ConfigureServices method.
public void ConfigureServices (IServiceCollection services)
{
//This registers all the various services of the Modeling Library for DI.
//We'll see these services as we move along.
services.SetupRocketDataModeling ();
//Register other services
}
3. Defining Properties To Be Formatted
If you have a class that contains properties that'll later on be output in a user-friendly format. Simply mark the properties with appropriate attributes.
namespace Example
{
public class OrderLineItem
{
[FormatAsNumber (decimalPlacesCount: 2,formatSpecifier:'N',customCultureInfoName:"en-KE")]
public decimal Price { get; set; }
[FormatAsDate(dateFormat:"dd/MM/yyyy",customCultureInfoName:"en-KE")]
public DateTime Dated { get; set; }
public decimal Quantity { get; set; }
}
}
4. Getting Formatted Values
Below is an example class that is using the library and the class above to get formatted value
namespace Example
{
public class ExampleOfFormatting
{
private readonly Rocket.Libraries.DataModeling.Formatting autoFormatter;
//Access the IAutoFormatter interface via DI.
public ExampleOfFormatting(Rocket.Libraries.DataModeling.Formatting.IAutoFormatter autoFormatter)
{
this.autoFormatter = autoFormatter;
}
public void DoFormatting()
{
var orderLineItem = new Example.OrderLineItem
{
Price = 5000,
Dated = new DateTime(2022,02,08)
};
var formattedOrderLineItem = autoFormatter.GetSingleFormatted(orderLineItem);
}
}
}
Above call returns a new object, which besides the original properties and values of the unformatted object, includes two new properties; Price_Formatted && Dated_Formatted which correspond to the decorated properties respectively.
You'll notice that there IS NOT a Quantity_Formatted property. This is because we did not place any formatting attributes on the Quantity property.
4.1 Points of Note on Formatted Object
- The newly created object that contains your formatted data, also contains all of the original properties, including their data.
- All new properties generated with formatted data are suffixed by _Formatted. Be careful not to name any of your own properties in a manner that would cause name collisions once your object is run through the formatter.
- The object created is a dynamic object, so its type is distinct from that of your original unformatted object.
5. Formatting Lists Of Objects
Sometimes you wish to format more than just one object. To accomplish this, Rocket.Libraries.DataModeling supplies interface Rocket.Libraries.DataModeling.Modeling.IRocketDataModeler
having performed the setup in step 2 above, this interface can be injected into your class.
To use the object obtained by injecting the interface, there are some basic constraints that the object to be formatted needs to follow. We'll start off by looking at an example object adhering to these constraints, then we'll individually describe each of the constraint.
using System.Collections.Generic;
namespace Example
{
public class FormattableObject
{
public List<ExampleOfFormatting> _RawData { get; set; }
public List<object> Data { get; set; }
}
}
5.1 Constraints
- Data to be formatted must be in a list whose name is prefixed by _Raw - this allows the library to identify which properties of your object are to be formatted and which are not.
- For each list to be formatted, there must be a an corresponding list of type object whose name matches the list to be formatted, but without the prefix _Raw
5.2 Formatting Your List
using Rocket.Libraries.DataModeling.Modeling;
namespace Example
{
public class ListFormatter
{
private readonly IRocketDataModeler rocketDataModeler;
public ListFormatter(IRocketDataModeler rocketDataModeler)
{
this.rocketDataModeler = rocketDataModeler;
}
public void FormatList(FormattableObject formattableObject)
{
rocketDataModeler.RunModeling (formattableObject, (summary) => { }); var formattedData = formattableObject.Data;
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- Microsoft.Extensions.Configuration (>= 3.1.18)
- Microsoft.Extensions.Options (>= 3.1.18)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 3.1.18)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.0-beta01 | 168 | 9/26/2022 |
1.1.0 | 415 | 5/6/2022 |
1.1.0-beta07 | 340 | 2/13/2022 |
1.1.0-beta06 | 142 | 2/13/2022 |
1.1.0-beta05 | 142 | 2/9/2022 |
1.1.0-beta04 | 150 | 2/8/2022 |
1.1.0-beta03 | 151 | 2/8/2022 |
1.1.0-beta02 | 161 | 2/8/2022 |
1.1.0-beta01 | 149 | 2/8/2022 |
1.0.0-beta23 | 185 | 9/6/2021 |
1.0.0-beta22 | 169 | 9/6/2021 |
1.0.0-beta21 | 157 | 9/6/2021 |
1.0.0-beta20 | 214 | 8/28/2021 |
1.0.0-beta19 | 188 | 8/28/2021 |
1.0.0-beta18 | 206 | 8/28/2021 |
1.0.0-beta17 | 203 | 8/28/2021 |
1.0.0-beta16 | 208 | 8/28/2021 |
1.0.0-beta14 | 200 | 8/28/2021 |
1.0.0-beta13 | 198 | 8/28/2021 |
1.0.0-beta12 | 171 | 8/27/2021 |
1.0.0-beta11 | 170 | 8/27/2021 |
1.0.0-beta10 | 181 | 8/27/2021 |
1.0.0-beta09 | 172 | 8/27/2021 |
1.0.0-beta08 | 181 | 8/27/2021 |
1.0.0-beta07 | 176 | 8/27/2021 |
1.0.0-beta06 | 178 | 8/27/2021 |
1.0.0-beta05 | 187 | 8/27/2021 |
1.0.0-beta04 | 185 | 8/27/2021 |
1.0.0-beta03 | 183 | 8/27/2021 |
1.0.0-beta02 | 171 | 8/27/2021 |
1.0.0-beta01 | 185 | 8/27/2021 |