Skip to content
Moh.Hassan edited this page May 21, 2019 · 1 revision

##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 namespace OData2Poco.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.

Clone this wiki locally