-
Notifications
You must be signed in to change notification settings - Fork 21
plugin
##Plugin Attributes This feature is available in v3.3+
OData2Poco support using Plugins for extending the attributes used in c#. This feature give the developer the power to develop their own complex custom attributes that interact with internal Model and the built-in functions like ToPas, ToCamel.
For example:
[ForeignKey("AuthorFK")]
[Entity (Name="entityName")] //use camel-case
###Tutorial###
-
Create multi-target class Library project Use the template provided in github repo project The project reference the package OData2Poco The SDK project is:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFrameworks>net45;net461;netstandard2.0</TargetFrameworks> <GenerateAssemblyInfo>false</GenerateAssemblyInfo> </PropertyGroup> <ItemGroup> <PackageReference Include="OData2Poco" Version="3.2.0" /> </ItemGroup> </Project>
-
Add class that inherit from
INamedAttribute
and in the namespaceOData2Poco.CustAttributes.NamedAtributes
as given below -
Implement both the methods: GetAttributes(PropertyTemplate property ) for properties GetAttributes(ClassTemplate property) for classes give a name to you attribute. That name will be passed in the option for example:
-a mykey using System.Collections.Generic; namespace OData2Poco.CustAttributes.NamedAtributes { public class MyKeyAttribute : INamedAttribute { public string Name { get; } = "mykey"; //apply only for Key properties public List<string> GetAttributes(PropertyTemplate property) => property.IsKey ? new List<string> { "[MyKey]" } : new List<string>(); //not used for class public List<string> GetAttributes(ClassTemplate ct) => new List<string>(); } }
-
Build the project using Visual studio or dotnet cli tool:
dotnet build myproject -c Release
Copy the generated dll file to the folder that you want to store the plugins. The flder can contain all dll you build
-
In commandline, pass the path of the plugin folder and use the attributes by the names you defined in the class above. Example:
o2pgen -r http://myservice --plugin path/to/folder -a mykey
Notes for Contributers:
You can contribute an push PR for your plugins and it can be available for all developers.
- 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: