コード例 #1
0
        private object CompileAndRunHoverCode(
            string hoverCode, EnhancedDataTable screenDefnTable)
        {
            object hoverData = null;

            IEnumerable <string> errmsgs = null;
            var      supportCode         = ClientSettings.GetCachedSupportCode();
            Assembly assem = null;

            {
                string[] sourceInput     = new string[] { hoverCode, supportCode };
                var      autocoderTelnet = AutoCoder.Code.Ext.TypeExt.GetReference(typeof(ClientSettings));
                var      rv = CSharpCompilationExt.CompileSource(sourceInput, autocoderTelnet);
                assem   = rv.Item1;
                errmsgs = rv.Item2;
            }

            if (assem == null)
            {
                foreach (var errmsg in errmsgs)
                {
                    Debug.WriteLine(errmsg);
                }
                throw new Exception("compile of hover code failed");
            }

            // run the first static method of the hoverCode.
            else
            {
                var rv            = CodeAnalyzer.GetFirstMethod(hoverCode);
                var namespaceName = rv.Item1;
                var className     = rv.Item2;
                var methodName    = rv.Item3;
                if (methodName.IsNullOrEmpty() == false)
                {
                    var qualClassName = namespaceName + "." + className;
                    var classType     = assem.GetType(qualClassName);
                    var mi            = classType.GetMethod(methodName);
                    if (mi != null)
                    {
                        var parametersArray = new object[] { screenDefnTable };
                        hoverData = mi.Invoke(null, new object[] { screenDefnTable });
                    }
                }
            }

            return(hoverData);
        }