-
Notifications
You must be signed in to change notification settings - Fork 21
NewFeature4_2_1
moh-hassan edited this page Aug 14, 2022
·
2 revisions
Odata2Poco v4.2.1 is published on 17 April, 2022 with new features:
- A new API to enable reading xml contents directly as string.
- Enable ignoring read-only properties in metadata and generate read-write properties.
c# example
//@nuget: OData2Poco -Version 4.2.1
using System;
using System.Threading.Tasks;
using OData2Poco;
using OData2Poco.Api;
using System.Net.Http;
public class Program
{
public static void Main()
{
Console.WriteLine("Hello Odata2Poco");
new OData2PocoExample().TestReadXmlAsync().Wait();
}
}
internal class OData2PocoExample
{
public async Task TestReadXmlAsync()
{
var xmlString = await ReadXmlString();
var setting = new PocoSetting
{
ReadWrite = true, //overwrite read only property
Attributes = {"key"},
AddNullableDataType = true,
};
var o2p = new O2P(setting);
var code = await o2p.GenerateAsync(xmlString); //read xmlString directly
//not Photo.Id , Person.UserName readonly properties
Console.WriteLine(code);
}
public async Task<string> ReadXmlString()
{
var url = "https://raw.githubusercontent.com/moh-hassan/odata2poco/master/Fake/trippinV4.xml";
using HttpClient httpClient = new HttpClient();
var response = await httpClient.GetAsync(url);
var responseString = await response.Content.ReadAsStringAsync();
return responseString;
}
}
- Run the next command to update the global tool to version 4.2.1:
dotnet tool update --global OData2Poco.dotnet.o2pgen
- Using the global dotnet tool:
Enable ignoring read-only properties in metadata and generate read-write properties with option
--read-write
set url=https://services.odata.org/TripPinRESTierService
dotnet o2pgen -r %url% -v --read-write
You can call dotnet o2pgen
from within PowerShell
like:
$url='https://services.odata.org/TripPinRESTierService'
dotnet.exe o2pgen -r $url -v --read-write
- Using the net45 tool o2pgen
- Download OData2Poco.CommandLine (o2pgen) from https://www.nuget.org/packages/OData2Poco.CommandLine/4.2.1
- Unzip the package in a folder
- Run the next command
set url=https://services.odata.org/TripPinRESTierService
o2pgen -r %url% -v --read-write
OData2poc can generate Poco classes from a remote http(s) xml meta files.
- home
- Announcing V6.0.0
- Features
- Getting started with c# generation
- Http Connection
- Using Parameter file
- User Defined Attributes
- Controlling c# code generation
- Model Filter
- Enable Nullable Reference type of c# 8
- Class with Init-Only Properties (c# 9)
- Generating Constructor
- Record-Type (c# 9)
- Name Map
- Securing Password
- Using Proxy Server
- Using Plugin Attributes
- Developing with OData2Poco
- Examples in dotnetfiddle.net
- CommandLine-Reference
- AttributeExamples
- typescript generation
- Help Screen
- How to
- New Feature 4.2.1
Samples of generated code: