ObjectGenerator.NET 1.0.2.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package ObjectGenerator.NET --version 1.0.2.4
NuGet\Install-Package ObjectGenerator.NET -Version 1.0.2.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ObjectGenerator.NET" Version="1.0.2.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ObjectGenerator.NET --version 1.0.2.4
#r "nuget: ObjectGenerator.NET, 1.0.2.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ObjectGenerator.NET as a Cake Addin
#addin nuget:?package=ObjectGenerator.NET&version=1.0.2.4

// Install ObjectGenerator.NET as a Cake Tool
#tool nuget:?package=ObjectGenerator.NET&version=1.0.2.4

Nuget

Generates Strongly Typed Objects from valid JSON without using reflection, very quickly.


Generating Objects

Objects can be generated by using an ObjectGenerator and providing it with Type Information

EXAMPLE Generate Single Object

Provide a New Object and Type Information to the Generator to create Testable

string singleTestdata = "{" +
    "\"testInt\":1234567890," +
    "\"testString\":\"The quick brown fox, jumps over; the lazy dog.\"," +
    "\"testDecimal\":\"1234.000000\"," +
    "\"testLong\":234556667777788888," +
    "\"testArray\":[[\"BTC1\",\"701.90000000\",\"713.90000000\"],[\"BTC2\",\"702.90000000\",\"723.90000000\"]]," +
    "\"testObject\":{[\"BTC1\",\"701.90000000\",\"713.90000000\"],[\"BTC2\",\"702.90000000\",\"723.90000000\"]}," +
    "\"testBoolean\":true" +
    "}";

Testable singleTest = new Testable(); // New Object (gets filled with data)

ObjectGenerator<Testable>.Generate(ref singleTest, ref singleTestdata, TestableTypeInformation); // See below

EXAMPLE Generating List of Object

Provide a New Object and Type Information and a method create a New Object to the Generator to create List<Testable>

static Func<Testable> NewObjectMethodTestable = () => new Testable(); // New Object Method

string doubleTestData = "[" +
    "{" +
    "\"testInt\":1234567890," +
    "\"testString\":\"The quick brown fox, jumps over; the lazy dog.\"," +
    "\"testDecimal\":\"1234.000000\"," +
    "\"testLong\":234556667777788888," +
    "\"testBoolean\":true," +
    "\"testArray\":[[\"BTC1\",\"701.90000000\",\"713.90000000\"],[\"BTC2\",\"702.90000000\",\"723.90000000\"]]," +
    "\"testObject\":{[\"BTC1\",\"701.90000000\",\"713.90000000\"],[\"BTC2\",\"702.90000000\",\"723.90000000\"]}," +
    "}," +
    "{" +
    "\"testInt\":1234567890," +
    "\"testString\":\"The quick brown fox, jumps over; the lazy dog.\"," +
    "\"testDecimal\":\"1234.000000\"," +
    "\"testLong\":234556667777788888," +
    "\"testBoolean\":true," +
    "\"testArray\":[[\"BTC1\",\"701.90000000\",\"713.90000000\"],[\"BTC2\",\"702.90000000\",\"723.90000000\"]]," +
    "\"testObject\":{[\"BTC1\",\"701.90000000\",\"713.90000000\"],[\"BTC2\",\"702.90000000\",\"723.90000000\"]}," +
    "}" +
    "]";

List<Testable> doubleTest = new List<Testable>(); // New Object (gets filled with data)

ObjectGenerator<Testable>.GenerateEnumerable(ref NewObjectMethodTestable, ref doubleTest, ref doubleTestData, TestableTypeInformation); // See below

All GenerateEnumerable methods create List<T>, including GenerateEnumerableArray


EXAMPLE Providing New Objects

When using a Generator to create List<T> you will need to provide a method to create a new object

This can be as simple as the examples below or any method that returns the correct type and matches the signature

static Func<Testable> NewObjectMethodTestable = () => new Testable();

static Func<TestableArray> NewObjectMethodArray = () => new TestableArray();

EXAMPLE Creating a Generator

To generate an object you need to provide information about the type and how the members will be generated

These can have references to other Generators

public static void TestableTypeInformation(Testable obj, string valueName, string value)
{
    switch (valueName)
    {
        case "testInt":
            {
                obj.TestInt = int.Parse(value);

                break;
            }
        case "testString":
            {
                obj.TestString = value.Trim('"');

                break;
            }
        case "testDecimal":
            {
                obj.TestDecimal = decimal.Parse(value.Trim('"'));

                break;
            }
        case "testBoolean":
            {
                obj.TestBoolean = bool.Parse(value);

                break;
            }
        case "testLong":
            {
                obj.TestLong = long.Parse(value);

                break;
            }
        case "testArray":
            {
                List<TestableArray> array = new List<TestableArray>();

                ObjectGenerator<TestableArray>.GenerateEnumerableArray(ref NewObjectMethodArray, ref array, ref value, ArrayTypeInformation);

                obj.TestArray = array;

                break;
            }
        case "testObject":
            {
                List<TestableArray> array = new List<TestableArray>();

                ObjectGenerator<TestableArray>.GenerateEnumerableArray(ref NewObjectMethodArray, ref array, ref value, ArrayTypeInformation);

                obj.TestObject = array;

                break;
            }
    }
}

Array types need their information provided a different way, the members should be in the expected order

public static void ArrayTypeInformation(TestableArray obj, int position, string value)
{
    switch (position)
    {
        case 0:
            {
                obj.Symbol = value.Trim('"');

                break;
            }
        case 1:
            {
                obj.Price = decimal.Parse(value.Trim('"'));

                break;
            }
        case 2:
            {
                obj.Price2 = decimal.Parse(value.Trim('"'));

                break;
            }
    }
}

EXAMPLE More Examples/Tests

You can see multiple working examples, including the examples in this documentation, by looking at the Tests


Copyright S Christison ©2024

Product 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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ObjectGenerator.NET:

Package Downloads
BinanceObjects

Methods for turning raw responses from the RestAPI and WebsocketAPI into Binance Objects

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2.72 169 4/25/2024
1.0.2.6 138 4/23/2024
1.0.2.5 73 4/17/2024
1.0.2.4 174 4/16/2024
1.0.1.3 594 4/15/2024

This Update
-----------
Add GenerateSpecificMember
Add Test/Example for GenerateSpecificMember

Add GenerateSimpleIndex
Add Test/Example for GenerateSimpleIndex

Add GenerateEnumerableIndex
Add Test/Example for GenerateEnumerableIndex

Add Missing Tests

Rename Tests