//----------------------------------------------------------------------------------------------------------------------------------------------------- private static void ManuallyImplementLoggingDecorator( ImplementationClassWriter <AncestorRepository.IFewMethods> implementor, FieldAccessOperand <List <string> > logField, string logSuffix = "") { var decorator = new ImplementationClassWriter <AncestorRepository.IFewMethods>(implementor.OwnerClass); decorator.AllMethods().ForEachMember(method => new TemplateMethodWriter(method, MethodWriterModes.Decorator, w => { logField.Add(w.Const(w.OwnerMethod.Name + ":BEFORE" + logSuffix)); w.Try(() => { var retVal = w.Proceed <TypeTemplate.TReturn>(); if (!method.Signature.IsVoid) { logField.Add(w.Const(w.OwnerMethod.Name + ":RETVAL" + logSuffix + "=") + retVal.Func <string>(x => x.ToString)); w.Return(retVal); } }).Catch <Exception>(e => { logField.Add(w.Const(w.OwnerMethod.Name + ":ERROR" + logSuffix + "=") + e.Prop(x => x.Message)); w.Throw(); }).Finally(() => { logField.Add(w.Const(w.OwnerMethod.Name + ":AFTER" + logSuffix)); }); })); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- 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> StaticField <T>(string name, out FieldAccessOperand <T> field) { field = this.StaticField <T>(name); return(this); }