如何使用System.ComponentModel命名空间的Attributes为类名提供别名

时间:2013-08-16 09:46:55

标签: c# .net

当我使用JSON将我的类的数据渲染到网页时 然后我的类名被呈现为全名,包括完整的命名空间 在C#中使用属性的方式是什么,我可以为类名提供一些别名。

我不想公开类的完整名称 { “mycompany.productname.classname”: “someValue中”}

我想渲染它 { “类名”: “someValue中”}

以下是Receivings.aspx.cs的代码 //包含Receivings.aspx的交互逻辑

   public partial class Receivings : Page
    {                
        [WebMethod(EnableSession = true)]
    public static object GetReceivingDetails(int pId)
    {
        try
        {
            RecDetail recDetail = new AccountsBL().GetReceivingDetails(pId);

            //Return result to jTable
            return new { Result = "OK", Records = recDetail };
        }
        catch (Exception ex)
        {
            return new { Result = "ERROR", Message = ex.Message };
        }
    }
}

呈现的JSON如下所示

enter image description here

这是JSOn,如上面的截图

所示
{"d":{"Result":"OK","Records":{"__type":"ERP.Models.Accounts.RecDetail","Id":0,"Mode":0,"Amount":0,"CatId":0,"CatTypeId":0,"RecId":0,"PayerId":0,"Cash":{"Id":1,"Thousand":30,"FiveHundred":0,"Hundred":0,"Fifty":0,"Twenty":0,"Ten":0,"Five":0,"Two":0,"One":0,"RecId":0,"PayerId":0,"CashRec":30000,"Notes":"xccxvcxcvzc"},"Cheque":{"Id":5,"Bank":"HDFC","Branch":"6868","No":"452326424","Date":"5/5/2013 12:00:00 AM","Amount":10000,"RecId":0,"PayerId":0,"Notes":"asdfasdfasdf"},"DD":{"Id":1,"Bank":"SBI","Branch":"354356","No":"141234123","Date":"5/5/2013 12:00:00 AM","Amount":10000,"RecId":0,"PayerId":0,"Notes":"sdfgsfdgsdfg"}}}}

以下是RecDetail类

namespace ERP.Models.Accounts
{
    [ERPAttributes("RecDetail")]
    public class RecDetail
    {
        public int Id { get; set; }

        public byte Mode { get; set; }

        public int Amount { get; set; }

        public byte CatId { get; set; }

        public byte CatTypeId { get; set; }

        public int RecId { get; set; }

        public int PayerId { get; set; }

        public Cash Cash { get; set; }

        public Cheque Cheque { get; set; }

        public DD DD { get; set; }
    }
}

0 个答案:

没有答案