Пример #1
0
        /// <summary>
        /// Translate the CPP code reference into the code
        /// </summary>
        /// <param name="expr"></param>
        /// <param name="result"></param>
        /// <param name="gc"></param>
        /// <param name="context"></param>
        /// <param name="container"></param>
        /// <returns></returns>
        public IValue CodeMethodCall(MethodCallExpression expr, IGeneratedQueryCode gc, CompositionContainer container)
        {
            if (expr == null)
            {
                throw new ArgumentNullException("expr");
            }

            ///
            /// Get the coding attribute off the method
            ///

            var code = expr.Method.TypeHasAttribute <CPPCodeAttribute>();

            if (code == null)
            {
                throw new InvalidOperationException(string.Format("Asked to generate code for a CPP method '{0}' but no CPPCode attribute found on that method!", expr.Method.Name));
            }

            return(CPPCodeStatement.BuildCPPCodeStatement(expr, gc, container, code.IncludeFiles, code.Code));
        }
        /// <summary>
        /// Do the work of translating this to code by fetching the data from the interface.
        /// </summary>
        /// <param name="expr"></param>
        /// <param name="gc"></param>
        /// <param name="container"></param>
        /// <returns></returns>
        public IValue CodeMethodCall(MethodCallExpression expr, IGeneratedQueryCode gc, CompositionContainer container)
        {
            if (expr == null)
            {
                throw new ArgumentNullException("expr");
            }

            // Get a reference to the object so we can code the call to get back the C++ code.
            var onTheFly = (expr?.Object as ConstantExpression)?.Value as IOnTheFlyCPPObject;

            if (onTheFly == null)
            {
                throw new InvalidOperationException("Unable to find the IOnTheFlyCPPObject!");
            }

            var includeFiles = onTheFly.IncludeFiles();
            var loc          = onTheFly.LinesOfCode(expr.Method.Name).ToArray();

            return(CPPCodeStatement.BuildCPPCodeStatement(expr, gc, container, includeFiles, loc));
        }