TypeExtensions.PocoBuilder 1.0.4

dotnet add package TypeExtensions.PocoBuilder --version 1.0.4                
NuGet\Install-Package TypeExtensions.PocoBuilder -Version 1.0.4                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TypeExtensions.PocoBuilder" Version="1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TypeExtensions.PocoBuilder --version 1.0.4                
#r "nuget: TypeExtensions.PocoBuilder, 1.0.4"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TypeExtensions.PocoBuilder as a Cake Addin
#addin nuget:?package=TypeExtensions.PocoBuilder&version=1.0.4

// Install TypeExtensions.PocoBuilder as a Cake Tool
#tool nuget:?package=TypeExtensions.PocoBuilder&version=1.0.4                

POCO Builder

CI NuGet
Quality Gate Status Coverage Security Rating Maintainability Rating Reliability Rating

What is POCO Builder?

POCO builder is a light-weight library that creates POCO (Plain Old CLR Object) type at runtime from any compile time defined type. All properies defined in POCO type has automatically created getters and setters and can be extended with attributes just like the type itself.

How do I get started?

Just install NuGet package and use PocoTypeBuilder class to create new POCO type. For example:

//Define test attribute to extend POCO type and its property
public class TestAttribute : Attribute
{
}

//Create POCO type builder
var pocoTypeBuilder = new PocoTypeBuilder("TestClass");

//Extend build POCO type with attribute and then create new property and extend it with attribute
pocoTypeBuilder
    .AddAttribute<TestAttribute>()
    .Property("Property",
        typeof(string),
        propertyBuilder => propertyBuilder.AddAttribute<TestAttribute>());
        
/*
Build POCO type.
Created POCO type class looks like this:

[TestAttribute]
public class TestClass
{
   [TestAttribute]
   public string Property { get; set; }
}
*/
var pocoType = pocoTypeBuilder.Build();

//Access POCO type property through reflection.
var propertyInfo = pocoType.GetRuntimeProperty("Property");

You can also use generic PocoTypeBuilder class to use strongly typed property selector:

//Create POCO type builder for test class
var pocoTypeBuilder = new PocoTypeBuilder<TestClass>();

//Extend build POCO type and its property with attribute
pocoTypeBuilder
    .AddAttribute<TestAttribute>()
    .Property(type => type.Property,
        propertyBuilder => propertyBuilder.AddAttribute<TestAttribute>());

You can check out more examples in test project.

Contribution

Welcome to join in and feel free to contribute by creating an Issue or Pull Request.

License

The project is under MIT license.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4 1,330 5/22/2023
1.0.3 204 4/13/2023
1.0.2 333 12/3/2022
1.0.1 335 12/2/2022
1.0.0 345 12/1/2022