Exemple #1
0
        public static Func <IExtractContext, string[]> Apply(
            MethodReference method, DecodeContext decodeContext)
        {
            var parameters     = method.GetSafeParameters();
            var pairParameters = parameters
                                 .Reverse()
                                 .Select(parameter => new Utilities.RightExpressionGivenParameter(
                                             parameter.ParameterType, decodeContext.PopStack()))
                                 .Reverse()
                                 .ToArray();

            var methodName   = method.GetFullMemberName(MethodNameTypes.Index);
            var functionName = methodName.ManglingSymbolName();
            var offset       = decodeContext.Current.Offset;

            // System.Object's constructor calls ignored.
            var md = method.Resolve();

            if (md.IsConstructor && md.DeclaringType.IsObjectType())
            {
                return(_ => new string[0]);
            }

            if (method.ReturnType.IsVoidType())
            {
                return(extractContext =>
                {
                    var parameterString = Utilities.GetGivenParameterDeclaration(
                        pairParameters, extractContext, offset);
                    return new[]
                    {
                        string.Format(
                            "{0}({1})",
                            functionName,
                            parameterString)
                    };
                });
            }
            else
            {
                var targetType = method.ReturnType.GetStackableType();
                var resultName = decodeContext.PushStack(targetType);

                return(extractContext =>
                {
                    var parameterString = Utilities.GetGivenParameterDeclaration(
                        pairParameters, extractContext, offset);
                    return new[]
                    {
                        string.Format(
                            "{0} = {1}({2})",
                            resultName,
                            functionName,
                            parameterString)
                    };
                });
            }
        }