//----------------------------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Each concrete factory is free to define arbitrary public methods according to the need. /// </summary> /// <typeparam name="T"> /// In this example, it is the primary interface that will be implemented by the dynamic type. /// </typeparam> /// <returns> /// A new instance of dynamic type implementing specified interface. /// </returns> public T CreateDemoObject <T>() { var key = new HappilTypeKey(baseType: typeof(object), primaryInterface: typeof(T)); var type = GetOrBuildType(key); return(type.CreateInstance <T>()); }
//------------------------------------------------------------------------------------------------------------------------------------------------- protected override IHappilClassDefinition DefineNewClass(HappilModule module, HappilTypeKey key) { return(Module.DefineClass(key, namespaceName: "ImplementingMethodsDemo") .ImplementInterface(key.PrimaryInterface) .VoidMethods().Implement(m => { var methodName = m.Local <string>(); methodName.AssignConst(m.MethodInfo.Name); m.EmitFromLambda(() => Console.WriteLine(methodName)); })); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- protected override IHappilClassDefinition DefineNewClass(HappilModule module, HappilTypeKey key) { return(Module.DefineClass(key, namespaceName: "EndToEndDemo") .ImplementInterface(key.PrimaryInterface) .AllProperties().ImplementAutomatic()); }
//------------------------------------------------------------------------------------------------------------------------------------------------- protected override IHappilClassDefinition DefineNewClass(HappilModule module, HappilTypeKey key) { return(Module.DefineClass( "HappilFactoryBaseTests.Impl" + key.PrimaryInterface.Name, key.BaseType) .ImplementInterface(key.PrimaryInterface) .DefaultConstructor()); }