找回密码
 立即注册

QQ登录

只需一步,快速开始

卖板的

初级会员

7

主题

54

帖子

393

积分

初级会员

积分
393
卖板的
初级会员   /  发表于:2022-6-13 18:12  /   查看:1487  /  回复:8
500金币
本帖最后由 卖板的 于 2022-6-14 08:58 编辑

下面红色代码位置, string result ="123456";
能正常返回值
我通过 JsHelper js = new JsHelper();
            string result = js.EvalMethod(JsD, Ff, Cc);
这个在活字格插件里面返回的是错误Object reference not set to an instance of an object.
请教大神我要怎么改,



namespace HuoZiGe
{

    [Icon("pack://application:,,,/MyServerCommand;component/Resources/Icon.png")]
    public class MyServerCommand : Command, ICommandExecutableInServerSide, IServerCommandParamGenerator
    {

        [DisplayName("JS代码")]
        [FormulaProperty(true)]
        public object JsDaiMa { get; set; }

        [DisplayName("方法名称")]
        [FormulaProperty(true)]
        public object FangFa { get; set; }

        [DisplayName("参数字符串,号隔开")]
        [FormulaProperty(true)]
        public object CanShu { get; set; }

        [DisplayName("返回值接收变量名")]
        [FormulaProperty(true)]
        public string NewParameter { get; set; }
        public object newValue { get; private set; }

        [Obsolete]
        public ExecuteResult Execute(IServerCommandExecuteContext dataContext)
        {
            //Do some thing

            string JsD = dataContext.EvaluateFormula(this.JsDaiMa).ToString();
            string Ff = dataContext.EvaluateFormula(this.FangFa).ToString();
            string Cc = dataContext.EvaluateFormula(this.CanShu).ToString();
            // string Jg = dataContext.EvaluateFormula(this.FanHui).ToString();


            JsHelper js = new JsHelper();


            string result = js.EvalMethod(JsD, Ff, Cc);

            dataContext.Parameters[NewParameter] = result ;

            return new ExecuteResult();
        }
        public IEnumerable<GenerateParam> GetGenerateParams()
        {
            yield return new GenerateNormalParam()
            {
                ParamName = NewParameter,
            };
        }
    }
}

最佳答案

查看完整内容

一遇到代码就不会了 看看有没有热心格友可以帮助一下楼主哈

8 个回复

倒序浏览
最佳答案
最佳答案
Lay.Li悬赏达人认证 活字格认证
超级版主   /  发表于:2022-6-13 18:12:42
来自 2#
一遇到代码就不会了
看看有没有热心格友可以帮助一下楼主哈
回复 使用道具 举报
卖板的
初级会员   /  发表于:2022-6-24 16:15:00
3#
这样也行
回复 使用道具 举报
Joe.xu讲师达人认证 悬赏达人认证 活字格认证
超级版主   /  发表于:2022-6-24 17:41:37
4#
这个是不是涉及到数组转字符呀,有大神给指点下吗,金币奖励呦
回复 使用道具 举报
逛逛逛
金牌服务用户   /  发表于:2022-6-24 19:50:25
5#
本帖最后由 逛逛逛 于 2022-6-24 22:24 编辑

把你的代码改直接赋值是可以执行的,参数也没问题。
   public ExecuteResult Execute(IServerCommandExecuteContext dataContext)
        {
            //Do some thing
            string JsD = dataContext.EvaluateFormula(this.JsDaiMa).ToString();
            string Ff = dataContext.EvaluateFormula(this.FangFa).ToString();
            string Cc = dataContext.EvaluateFormula(this.CanShu).ToString();
            // string Jg = dataContext.EvaluateFormula(this.FanHui).ToString();
            //  JsHelper js = new JsHelper();
            // string result = js.EvalMethod(JsD, Ff, Cc);

            string result = JsD + "|" + Ff + "|" + Cc;
            dataContext.Parameters[NewParameter] = result;
            return new ExecuteResult();
        }

你可以查一下 你的 string result = js.EvalMethod(JsD, Ff, Cc)


评分

参与人数 1金币 +5 收起 理由
Lay.Li + 5 赞一个!

查看全部评分

回复 使用道具 举报
卖板的
初级会员   /  发表于:2022-6-25 08:42:08
6#
逛逛逛 发表于 2022-6-24 19:50
把你的代码改直接赋值是可以执行的,参数也没问题。
   public ExecuteResult Execute(IServerCommandExec ...

我试了下,在exe窗口程序可以正常没有报错,在生成插件执行就出错
回复 使用道具 举报
逛逛逛
金牌服务用户   /  发表于:2022-6-25 09:16:40
7#
卖板的 发表于 2022-6-25 08:42
我试了下,在exe窗口程序可以正常没有报错,在生成插件执行就出错

查一下  你的   js.EvalMethod(?, ?, ?)   参数类型 ,都是string吗?
回复 使用道具 举报
逛逛逛
金牌服务用户   /  发表于:2022-6-25 09:24:33
8#
[DisplayName("参数字符串,号隔开")]

看你这个,会不会要求传入的是集合啊
回复 使用道具 举报
Lay.Li悬赏达人认证 活字格认证
超级版主   /  发表于:2022-6-27 09:45:32
9#
感谢大佬的支持~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部