Skip to content
This repository has been archived by the owner on Dec 28, 2021. It is now read-only.

amir734jj/CustomTypeBuilder

Repository files navigation

CustomTypeBuilder

Custom type builder in C#

Nuget

Create a type on the fly, either by extending an existing type or starting from ground-up. The idea behind this project is to dynamically extend a basic POCO type (or record type), add new properties to it quickly and instantiate it as cast it back to base type. Hence underneath that type is a POCO type but with some extra properties that can be accessible by reflection.

var type = Builders.CustomTypeBuilder.New()
    // Useful while generating nested types, you can re-use `moduleBuilder`
    .GetModuleBuilder(out var moduleBuilder)
    .SetModuleBuilder(moduleBuilder)
    // Extend an existing type
    .FinalizeOptionsBuilder().Extend<DummyClass>()
    // Add properties
    .AddProperty<string>("Name")
    .AddProperty<int>("Age")
    // Class level attribute
    .AddAttribute(new RequiredAttribute())
    .Compile();
    // Or instantiate this type and cast to DummyClass, or use `Activator.CreateInstance`
    // .Instantiate<DummyClass>()

About

Custom type builder in C#

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages