当前位置: 首页>>代码示例>>C#>>正文


C# ScriptingContext.FormatObject方法代码示例

本文整理汇总了C#中Mono.Debugger.Frontend.ScriptingContext.FormatObject方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptingContext.FormatObject方法的具体用法?C# ScriptingContext.FormatObject怎么用?C# ScriptingContext.FormatObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mono.Debugger.Frontend.ScriptingContext的用法示例。


在下文中一共展示了ScriptingContext.FormatObject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EvaluateExpression

        public string EvaluateExpression(ScriptingContext context, string text,
						  DisplayFormat format)
        {
            F.Expression expression = context.ParseExpression (text);

            try {
                expression = expression.Resolve (context);
            } catch (ScriptingException ex) {
                throw new ScriptingException ("Cannot resolve expression `{0}': {1}",
                                  text, ex.Message);
            } catch {
                throw new ScriptingException ("Cannot resolve expression `{0}'.", text);
            }

            try {
                object retval = expression.Evaluate (context);
                return context.FormatObject (retval, format);
            } catch (ScriptingException ex) {
                throw new ScriptingException ("Cannot evaluate expression `{0}': {1}",
                                  text, ex.Message);
            } catch {
                throw new ScriptingException ("Cannot evaluate expression `{0}'.", text);
            }
        }
开发者ID:baulig,项目名称:debugger,代码行数:24,代码来源:ExpressionParser.cs

示例2: Execute

        protected override string Execute(ScriptingContext context,
						   Expression expression, DisplayFormat format)
        {
            if (NestedBreakStates)
                context.ScriptingFlags |= ScriptingFlags.NestedBreakStates;

            if (expression is TypeExpression)
                throw new ScriptingException (
                    "`{0}' is a type, not a variable.", expression.Name);
            object retval = expression.Evaluate (context);
            string text = context.FormatObject (retval, format);
            context.Print (text);
            return text;
        }
开发者ID:baulig,项目名称:debugger,代码行数:14,代码来源:Command.cs

示例3: Execute

        protected override string Execute(ScriptingContext context,
		                                   Expression expression, DisplayFormat format)
        {
            try {
                if (expression is TypeExpression)
                    throw new ScriptingException (
                                                  "`{0}' is a type, not a variable.", expression.Name);
                object retval = expression.Evaluate (context);

                EmonicInterpreter.printData output = new EmonicInterpreter.printData();
                output.type = "";
                output.varValue = "";
                output.varNames = "";

                if (retval != null) {
                    output.type = ((TargetObject)retval).TypeName;
                    if (output.type == null)
                        output.type = "";

                    switch (((TargetObject)retval).Kind) {
                        case TargetObjectKind.Fundamental:
                        // we send the value of the fundamental type
                        TargetFundamentalObject tfo = retval as TargetFundamentalObject;
                        if (tfo == null) {
                            // element is "null"
                            output.varValue = "<null>";
                            break;
                        }
                        output.varValue = tfo.GetObject(context.CurrentThread).ToString();
                        if (output.varValue == null)
                            output.varValue = "";
                        break;
                        case TargetObjectKind.Array:
                        // we send back the number of array elements
                        TargetArrayObject tao = retval as TargetArrayObject;
                        if (tao == null) {
                            // element is "null"
                            output.varValue = "<null>";
                            break;
                        }
                        int lower = tao.GetLowerBound (context.CurrentThread, 0);
                        int upper = tao.GetUpperBound (context.CurrentThread, 0);
                        output.varNames = (upper-lower).ToString();
                        break;
                        // same for struct and class
                        case TargetObjectKind.Struct:
                        case TargetObjectKind.Class:
                        // we send back the member's names
                        // NOTE! we also show static and constant fields
                        TargetObject obj = retval as TargetObject;
                        if (obj.HasAddress && obj.GetAddress(context.CurrentThread).IsNull) {
                            output.varValue = "<null>";
                            break;
                        }
                        Mono.Debugger.Thread thread = context.CurrentThread;
                        TargetClass tc = ((TargetClassObject)retval).Type.GetClass(thread);
                        if (tc == null)
                            break;
                        TargetFieldInfo[] tfi = tc.GetFields(thread);
                        if (tfi == null)
                            break;
                        output.varNames = "";
                        for (int i=0; i<tfi.Length; i++) {
                            if (tfi[i].IsStatic) // do not show static fields, they're not accessible via the instance!
                                continue;
                            output.varNames += tfi[i].Name;
                            output.varNames += " ";
                        }
                        output.varNames = output.varNames.Trim();
                        break;
                        case TargetObjectKind.Object:
                        case TargetObjectKind.Pointer:
                        case TargetObjectKind.Unknown:
                        case TargetObjectKind.Function:
                        case TargetObjectKind.Alias:
                        case TargetObjectKind.Enum:
                        context.Print("ERROR: Print Command will return no values because of an implementation error");
                        break;
                    }
                }
                string text = context.FormatObject (retval, format);
                context.Print (text);

                EmonicInterpreter.printOutput = output;
                EmonicInterpreter.printSem.Release();

                return text;
            } catch {
                EmonicInterpreter.printData output = new EmonicInterpreter.printData();
                output.type = "";
                output.varValue = "";
                output.varNames = "";
                EmonicInterpreter.printOutput = output;
                EmonicInterpreter.printSem.Release();
                throw;
            }
        }
开发者ID:visual000,项目名称:misc,代码行数:97,代码来源:EmonicCommand.cs


注:本文中的Mono.Debugger.Frontend.ScriptingContext.FormatObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。