有关使用Script#删除ajax数据中的get和set值的问题 [英] A question about remove the get and set value in data of ajax, using Script#

查看:99
本文介绍了有关使用Script#删除ajax数据中的get和set值的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我开始使用Script#,我尝试通过ajax将数据包发送到服务器:

As now I have started to use Script#, I tried to send a data package to server via ajax:

jQuery.AjaxRequest<RespondPackage>(url, new jQueryAjaxOptions("type", "POST", "dataType", "json", "data",  dataSendToServer));

与dataSendToServer一起使用获取和设置访问器的对象类型为"SendPackage",如下所示:

with dataSendToServer is in form of object Type "SendPackage" using get and set accessor, like this:

public class SendPackage
{  private string reportID;
    public string ReportID
    {
        get { return reportID; }
        set { reportID = value; }
    }
    public SendPackage(string reportID)
    {
        this.reportID = reportID;
    }
}

在转换为Javascript后使用ajax将数据发送到服务器时,它不仅发送reportID(所需的数据),还发送get_reportID和set_reportID.

While sending the data to server using ajax after transform to Javascript, it send not only the reportID (the data needed) , but also get_reportID and set_reportID.

我尝试了几种方法来删除get和set访问器的伪属性,例如Type.DeleteField,但这似乎不起作用.因此,我想问一下是否有任何方法可以处理发送到服务器的数据以删除get和set访问器的属性?

I have tried several method to remove the dummy properties of the get and set accessor like Type.DeleteField but it seems doesn't work. Therefore I want to ask if there is any method to treat the data sending to server to remove the property of get and set accessor?

感谢您的关注.

推荐答案

使用记录类,即从Record基类派生您的类.

Use a record class, i.e. derive your class from the Record base class.

记录类不会被定义为常规类-而是仅创建一个表示您的ctor的工厂方法.工厂的结果是一个香草对象,该对象将按您的期望序列化为JSON对象.

Record classes don't get defined as a regular class - instead only a factory method representing your ctor is created. The result of the factory is a vanilla object which serializes into a JSON object as you'd expect.

记录类不能具有方法或属性-只能具有公共属性,并且最多只能具有ctor.

Record classes cannot have methods or properties - just public properties and at most a ctor.

请注意,您还可以使任何类实现ToJSON方法-使用脚本引擎中内置的JSON功能(并且jQuery也可能使用它)时,该类将覆盖序列化的内容.

Note that you could also have any class implement a ToJSON method - that gets to override what gets serialized when using the JSON functionality built into the script engine (and presumably jQuery also uses it).

这篇关于有关使用Script#删除ajax数据中的get和set值的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆