ObjectGenerator.NET 1.0.1.3

Additional Details

Please update to at least v1.0.2.73

There is a newer version of this package available.
See the version list below for details.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package ObjectGenerator.NET --version 1.0.1.3
NuGet\Install-Package ObjectGenerator.NET -Version 1.0.1.3
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.1.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ObjectGenerator.NET --version 1.0.1.3
#r "nuget: ObjectGenerator.NET, 1.0.1.3"
#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.1.3

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

Nuget

Generates Strongly Typed Objects from valid JSON without using reflection


EXAMPLE Examples/Tests

You can see multiple working examples by looking at the Tests


EXAMPLE Generating An Object

An object can be generated by using an ObjectGenerator and providing it with Type Information and a method to create New Objects

Below is a full example of a List<Testable> object being created from JSON

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

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

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>();

ObjectGenerator<Testable>.GenerateEnumerable(ref NewObjectTestable, ref doubleTest, ref doubleTestData, TestableTypeInformation);

EXAMPLE Providing New Objects

When using a Generator 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> NewObjectTestable = () => new Testable();

static Func<TestableArray> NewObject = () => 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 NewObject, ref array, ref value, ArrayTypeInformation);

                obj.TestArray = array;

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

                ObjectGenerator<TestableArray>.GenerateEnumerableArray(ref NewObject, 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;
            }
    }
}

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

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.0.3.5 187 5/7/2024