Skip to content

NewFeature4_2_1

moh-hassan edited this page Aug 14, 2022 · 2 revisions

Version 4.2.1

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.

For Developers:

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;
	}
}

Try it online

CLI tool

Dotnet Global tool

  1. Run the next command to update the global tool to version 4.2.1:
   dotnet tool update --global OData2Poco.dotnet.o2pgen  
  1. 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
  1. Using the net45 tool o2pgen
set url=https://services.odata.org/TripPinRESTierService
o2pgen -r %url%  -v --read-write

Support remote xml files

OData2poc can generate Poco classes from a remote http(s) xml meta files.

Clone this wiki locally