Skip to content

Commit

Permalink
Enable ignoring readOnly properties by setting read-write options, fix
Browse files Browse the repository at this point in the history
  • Loading branch information
moh-hassan committed Apr 17, 2022
1 parent 2a71c43 commit 3a263fc
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 5 deletions.
22 changes: 22 additions & 0 deletions OData2Poco.CommandLine.Test/ProgramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,28 @@ public async Task Model_readonly_test()
}
}

[Test]
//feature #41
public async Task Model_readonly_but_ignored_by_setting_readwrite_test()
{
//Arrange
string url = TestSample.TripPin4;
var a = $"-r {url} -v --read-write";
//Act
var tuble = await RunCommand(a);
var output = tuble.Item2;
//Assert
var list = new List<string>
{
"public int TripId {get;set;} //PrimaryKey not null ReadOnly" ,
"public int PlanItemId {get;set;} //PrimaryKey not null ReadOnly",
"public string AirlineCode {get;set;} //PrimaryKey not null ReadOnly"
};
foreach (var s in list)
{
Assert.IsTrue(output.Contains(s));
}
}
#endregion
}

Expand Down
1 change: 1 addition & 0 deletions OData2Poco.Core/OptionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public PocoSetting GetPocoSetting()
AddJsonAttribute = PocoOptions.AddJsonAttribute,
Include = PocoOptions.Include.ToList(),
EntityNameCase=PocoOptions.EntityNameCase.ToEnum<CaseEnum>(),
ReadWrite = PocoOptions.ReadWrite,
};
}

Expand Down
4 changes: 3 additions & 1 deletion OData2Poco.Core/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ public class Options
HelpText = "Filter the Entities by FullName, case insensitive. Use space delemeted list of entity names. Name may include the special characters * and ?. The char * represents a string of characters and ? match any single char.")]
public IEnumerable<string> Include { get; set; }


//feature #41
[Option("read-write", HelpText = "All properties are read/write")]
public bool ReadWrite { get; set; }
public List<string> Errors { get; set; }

public Options()
Expand Down
1 change: 1 addition & 0 deletions OData2PocoLib/PocoSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class PocoSetting
public bool AddReference { get; set; }
public bool GenerateInterface { get; set; }
public List<string>? Include { get; set; }
public bool ReadWrite { get; set; } //all properties are read/write
/// <summary>
/// Initialization
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion OData2PocoLib/PropertyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public string Name
.Append(" ")
.Append(Name)
.Append(" ")
.Append(_property.IsReadOnly ? "{get;}" : "{get;set;}")
.Append(_property.IsReadOnly && !_setting.ReadWrite ? "{get;}" : "{get;set;}")
.Append(" ")
.Append(Comment())
.ToString();
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
POCO classes can be used in a typed RESTful client OData services and code generation can be controlled by setting many options.

## What is news
Odata2Poco v4.1.0 is published with a new feature: Name Mapping of Entities and properties using json file. Read [wiki](https://github.com/moh-hassan/odata2poco/wiki/NameMapping) for more details and tutorial for how to use.

Odata2Poco v4.2.0 is published with new features implemented for request [#41](https://github.com/moh-hassan/odata2poco/issues/41):
-A new API to enable reading xml contents directly as string.
- Enable ignoring read-only properties in metadata and generate read-write properties.

## OData2Poco Packages
OData2Poco is available in three flavers:
Expand All @@ -27,7 +28,7 @@ OData2Poco is available in three flavers:
**Features of OData2Poco**

- Generate POCO classes corresponding to the Entities defined in the XML MetaData stored in OData Feeds.
- Generation is based on the Metadata of the service stored on the server/ or EDMX xml files.
- Generation is based on the Metadata of the service stored on the server/ EDMX xml files or xml string contents.
- Support http(s) with/without authentication. The Supported autherizations are: basic, token and Oauth2.
- Console CommandLine tool Support .NET 4.5 or higher.
- Class library Support NET5/netstandard2.0/net461/net45.
Expand Down
6 changes: 6 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## (Console: o2pgen / .Net Core: dotnet-o2pgen)

## Version 4.2.0
**Release Date:** April 17, 2022
- New features implemented for request [#41](https://github.com/moh-hassan/odata2poco/issues/41).
- A new API to enable reading xml contents directly as string.
- Enable ignoring read-only properties in metadata and generate read-write properties.

## Version 4.1.0
**Release Date:** Nov 8, 2021

Expand Down

0 comments on commit 3a263fc

Please sign in to comment.