Ejemplo n.º 1
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            private void InspectReturnValue(IHappilMethodBodyTemplate method, HappilOperand <TypeTemplate.TReturn> returnValueExpression)
            {
                if (!object.ReferenceEquals(returnValueExpression, null))
                {
                    var returnValue = method.Local <TypeTemplate.TReturn>(initialValue: returnValueExpression);

                    if (m_OnReturnValue != null)
                    {
                        m_OnReturnValue(method, returnValue);
                    }

                    if (m_OnSuccess != null)
                    {
                        m_OnSuccess(method);
                    }

                    method.Return(returnValue);
                }
                else
                {
                    if (m_OnReturnVoid != null)
                    {
                        m_OnReturnVoid(method);
                    }

                    if (m_OnSuccess != null)
                    {
                        m_OnSuccess(method);
                    }
                }
            }
Ejemplo n.º 2
0
            //-----------------------------------------------------------------------------------------------------------------------------------------------------

            private void InspectOutputArguments(IHappilMethodBodyTemplate method)
            {
                if (m_OnOutputArgument != null)
                {
                    method.ForEachArgument(arg => {
                        if (arg.IsByRef || arg.IsOut)
                        {
                            m_OnOutputArgument(method, arg);
                        }
                    });
                }
            }
Ejemplo n.º 3
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            internal void ApplyBody(IHappilMethodBodyTemplate method)
            {
                var successLocal = (m_OnFailure != null ? method.Local <bool>(initialValueConst: false) : null);

                if (m_OnBefore != null)
                {
                    m_OnBefore(method);
                }

                InspectInputArguments(method);

                var tryBlock = method.Try(
                    () => {
                    var returnValueExpression = method.Proceed();

                    if (m_OnFailure != null)
                    {
                        successLocal.AssignConst(true);
                    }

                    InspectReturnValue(method, returnValueExpression);
                    InspectOutputArguments(method);
                });

                foreach (var exceptionHandler in m_OnCatchExceptions)
                {
                    exceptionHandler(method, tryBlock);
                }

                tryBlock.Finally(() => {
                    if (m_OnFailure != null)
                    {
                        method.If(!successLocal).Then(() => m_OnFailure(method));
                    }

                    if (m_OnAfter != null)
                    {
                        m_OnAfter(method);
                    }
                });
            }