ObjectGenerator.NET
1.0.2.6
Please update to at least v1.0.2.73
See the version list below for details.
dotnet add package ObjectGenerator.NET --version 1.0.2.6
NuGet\Install-Package ObjectGenerator.NET -Version 1.0.2.6
<PackageReference Include="ObjectGenerator.NET" Version="1.0.2.6" />
paket add ObjectGenerator.NET --version 1.0.2.6
#r "nuget: ObjectGenerator.NET, 1.0.2.6"
// Install ObjectGenerator.NET as a Cake Addin
#addin nuget:?package=ObjectGenerator.NET&version=1.0.2.6
// Install ObjectGenerator.NET as a Cake Tool
#tool nuget:?package=ObjectGenerator.NET&version=1.0.2.6
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
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 and ^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$|^(bc1)[0-9A-Za-z]{39,59}$\"," +
"\"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
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 and ^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$|^(bc1)[0-9A-Za-z]{39,59}$\"," +
"\"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 and ^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$|^(bc1)[0-9A-Za-z]{39,59}$\"," +
"\"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
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();
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;
}
}
}
More Examples/Tests
You can see multiple working examples, including the examples in this documentation, by looking at the Tests
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 | 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. |
-
.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.73 | 0 | 5/4/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