Public API and Workflows
This document covers the primary public-facing types and how you typically interact with the Squid library.
Primary entry points
BasicDataTransferObjectTypeCreator<T>Type— returns the emittedSystem.TypeforT. Accessing it builds the type (ifTis an interface).CreateInstance(dynamic source = null)— constructs an instance of the generated type; ifsourceprovided, values are mapped into the instance viaFastMapper<T>.AssemblyName,ClassName,FacetInterfaces— configuration points to control naming and additional interfaces.SaveAssemblyToDiskandPersistAssembly— control whether emitted assemblies are persisted (default no-op for portability).
Control points and order of operations
When you request Type (or call CreateInstance) the typical build pipeline executes in this order:
- Validate configuration (primary interface
Tmust be an interface for emission to occur). - Resolve effective interface set: primary interface
Tplus anyFacetInterfacesprovided. - Create a dynamic assembly and module (via
GetAssemblyBuilder/GetModuleBuilder). - Create a
TypeBuilderfor the emitted class with the configuredClassNamein the configured assembly. - Execute
PropertyOperationsto emit fields and properties for each property passingPropertyFilter. - Execute
EventOperationsandMethodOperationsfor remaining members. - Apply
SpecialBehavioursoperations where the behaviour’s key indicates applicability (behaviours run after member emission so they can add methods that reference existing fields/members). - Execute
ClassOperationsfor any class-level customizations. - Create the type via
TypeBuilder.CreateType()and cache the resultingType. - Compile an
InstanceFactory(constructor delegate) and cache for fast instance creation.
Example: control emission with PropertyFilter and TypeMaps
// Only emit writable properties and map IList<T> to List<T>
var creator = new BasicDataTransferObjectTypeCreator<IMyDto>
{
PropertyFilter = (PropertyInfo p) => p.CanWrite, // only emit writable properties
TypeMaps = new Dictionary<Type, Type>
{
{ typeof(IList<>), typeof(List<>) }
}
};
var dtoType = creator.Type; // triggers build
var instance = creator.CreateInstance();
Advanced usage
- To add additional interfaces:
creator.FacetInterfaces = new[] { typeof(IMyFacet) }; - To provide custom property backing type mapping: subclass and override
TypeMaps. - To alter generated constructor logic: override
DefaultConstructorInstructions*properties to inject IL instructions.
Error handling
- If a property has a
DefaultValueAttributethat cannot be converted to the backing field type, the generator throwsNotSupportedExceptionduring type creation. This is by-design so that invalid default-value declarations fail fast.
Notes
- If
typeof(T).IsClassthenBuildTypereturnstypeof(T)unchanged; the generator only emits types for interfaceT. CreateInstanceusesFastMapper<T>for copying from dynamic sources — reviewFastMapperdocumentation inBrightSword.Feberfor mapping rules.