//------------------------------------------------------------------------------------------------------------------------------------------------- public IHappilClassBody <TBase> Implement( IHappilAttributes attributes, Func <IHappilPropertyBody <TypeTemplate.TProperty>, IHappilPropertyGetter> getter, Func <IHappilPropertyBody <TypeTemplate.TProperty>, IHappilPropertySetter> setter = null) { return(Implement(prop => attributes, getter, setter)); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public IHappilClassBody <TBase> StaticField <T>(string name, IHappilAttributes attributes, out FieldAccessOperand <T> field) { var fieldMember = DefineField <T>(name, isStatic: true); fieldMember.SetAttributes(attributes as HappilAttributes); field = fieldMember.AsOperand <T>(); return(this); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public IHappilClassBody <TBase> Constructor <TArg1, TArg2, TArg3>( Action <IHappilConstructorBody, HappilArgument <TArg1>, HappilArgument <TArg2>, HappilArgument <TArg3> > body, IHappilAttributes attributes = null) { return(DefineConstructor( attributes, (ctor) => body(ctor, new HappilArgument <TArg1>(ctor, 1), new HappilArgument <TArg2>(ctor, 2), new HappilArgument <TArg3>(ctor, 3)), typeof(TArg1), typeof(TArg2), typeof(TArg3))); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public IHappilClassBody <TBase> StaticConstructor( Action <IHappilConstructorBody> body, IHappilAttributes attributes = null) { var constructorMember = HappilConstructor.CreateStaticConstructor(m_HappilClass); constructorMember.SetAttributes(attributes as HappilAttributes); constructorMember.AddBodyDefinition(() => { body(constructorMember); }); m_HappilClass.AddUndeclaredMember(constructorMember); return(this); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- private IHappilClassBody <TBase> DefineConstructor( IHappilAttributes attributes, Action <HappilConstructor> invokeBodyDefinition, params Type[] argumentTypes) { var resolvedArgumentTypes = argumentTypes.Select(TypeTemplate.Resolve).ToArray(); var constructorMember = new HappilConstructor(m_HappilClass, resolvedArgumentTypes); constructorMember.SetAttributes(attributes as HappilAttributes); constructorMember.AddBodyDefinition(() => { invokeBodyDefinition(constructorMember); }); m_HappilClass.AddUndeclaredMember(constructorMember); m_HappilClass.DefineFactoryMethod(constructorMember.ConstructorInfo, argumentTypes); return(this); }
//------------------------------------------------------------------------------------------------------------------------------------------------- public IHappilClassBody <TBase> Implement( IHappilAttributes attributes, Func <IHappilPropertyBody <TIndex1, TIndex2, TProperty>, IHappilPropertyGetter> getter, Func <IHappilPropertyBody <TIndex1, TIndex2, TProperty>, IHappilPropertySetter> setter = null) { DefineMembers <TProperty>(body => { body.SetAttributes(attributes as HappilAttributes); if (getter != null) { getter((IHappilPropertyBody <TIndex1, TIndex2, TProperty>)body); } if (setter != null) { setter((IHappilPropertyBody <TIndex1, TIndex2, TProperty>)body); } }); return(OwnerBody); }
//------------------------------------------------------------------------------------------------------------------------------------------------- public IHappilClassBody <TBase> ImplementAutomatic(IHappilAttributes attributes) { return(DefineAutomaticImplementation <TypeTemplate.TProperty>(prop => attributes)); }
//------------------------------------------------------------------------------------------------------------------------------------------------- public IHappilClassBody <TBase> Throw <TException>(IHappilAttributes attributes, string message = null) where TException : Exception { return(DefineMembers <object>( attributes: m => attributes, invokeBodyDefinition: m => m.Throw <TException>(message))); }
//------------------------------------------------------------------------------------------------------------------------------------------------- public IHappilClassBody <TBase> Implement( IHappilAttributes attributes, Action <IHappilMethodBody <TReturn>, HappilArgument <TArg1>, HappilArgument <TArg2>, HappilArgument <TArg3> > body) { return(Implement(m => attributes, body)); }
//------------------------------------------------------------------------------------------------------------------------------------------------- public IHappilClassBody <TBase> Implement(IHappilAttributes attributes, Action <IVoidHappilMethodBody> body) { return(Implement(m => attributes, body)); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public IHappilClassBody <TBase> Constructor( Action <IHappilConstructorBody> body, IHappilAttributes attributes = null) { return(DefineConstructor(attributes, body)); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public IHappilClassBody <TBase> DefaultConstructor(IHappilAttributes attributes = null) { return(DefineConstructor(attributes, ctor => ctor.Base())); }