仅序列化接口中可用的类的属性。 [英] Serialize only those properties of a class that is available in an interface.
问题描述
我有一个类'Request',它实现了五个接口 - IRequest,ICreateRequest,IUpdateRequest,IDeleteRequest& ISelectRequest。每个接口都有一组我在'request'类中实现的属性。
I have a class 'Request' that implements five interfaces - IRequest , ICreateRequest, IUpdateRequest, IDeleteRequest & ISelectRequest. every interface have a set of properties that i am implementing in 'request' class.
在对象初始化时我只使用接口名称赞: -
at the time of object initialization i just use interface name Like :-
CorporateUser.ISelectRequest _selectUser = new CorporateUser.Request();
CorporateUser.ISelectRequest _selectUser = new CorporateUser.Request();
在对象初始化时我可以只访问我在'ISelectRequest'界面中声明的那些属性(即.- status,offset& limit)。
at the time of object initialization i can access only those properties that i have declared in 'ISelectRequest' interface (ie.- status,offset & limit).
但是 当我要去的时候使用JavaScriptSerializer序列化' _selectUser'请求。它序列化'Request'类中可用的整个属性。以下是代码: -
but when i am going to Serialize '_selectUser' request using JavaScriptSerializer. it serialize entire properties available in 'Request' class. below is code :-
          var _jsonSerialiser = new JavaScriptSerializer();
var _jsonSerialiser = new JavaScriptSerializer();
          CorporateUser.ISelectRequest _selectUser = new CorporateUser.Request();
          _selectUser.offset = Convert.ToInt16(ConfigurationManager.AppSettings [" Offset"]);
          _selectUser.limit = Convert.ToInt16(ConfigurationManager.AppSettings [" Limit"]);
          _jsonRequest = _jsonSerialiser.Serialize(_selectUser);
在'_jsonRequest'中所有属性在序列化后都可用。我想要''_ jsonRequest'只包含我在'ISelectRequest'界面中声明的那些属性( 状态,偏移& 限制)。
in '_jsonRequest ' all properties get available after serialization. i want '_jsonRequest ' contains only those properties that i have declared in 'ISelectRequest' interface ( status,offset & limit).
是否可能?
以下是完整代码: -
below is entire code :-
公共界面IRequest
      {
          string corp_email_id {get;组; }¥b $ b       }¥b $ b      公共接口ICreateRequest:IRequest
      {
          字符串名称{get;组; }¥b $ b           string [] groups {get;组; }¥b $ b           string employee_phone_number {get;组; }¥b $ b           string employee_cost_center {get;组; }¥b $ b           string employee_code {get;组; }¥b $ b           string employee_base_location {get;组; }¥b $ b           string employee_designation {get;组; }¥b $ b           string employee_band {get;组; }¥b $ b           string employee_gender {get;组; }¥b $ b           string manager_name {get;组; }¥b $ b           string manager_email_address {get;组; }¥b $ b           string custom_field_1 {get;组; }¥b $ b           string custom_field_2 {get;组; }¥b $ b           string custom_field_3 {get;组; }¥b $ b           string custom_field_4 {get;组; }¥b $ b           string custom_field_5 {get;组; }¥b $ b       }
     公共接口IUpdateRequest:ICreateRequest
      {
          string user_status {get;组; }¥b $ b       }
     公共界面IDeleteRequest:IRequest {}
     公共界面ISelectRequest
      {
         字符串状态{get;组; }¥b $ b           int offset {get;组; }¥b $ b           int limit {get;组; }
      }
     公共类请求:IRequest,IUpdateRequest,IDeleteRequest,ISelectRequest
      {
          public string corp_email_id
          {
              get; set;
          }
         公开字符串custom_field_1
          {
             得到;设定;
          }
         公开字符串custom_field_2
          {
             得到;设定;
          }
          public string custom_field_3
          {
             得到;设定;
          }
         公开字符串custom_field_4
          {
             得到;设定;
          }
          public string custom_field_5
          {
             得到;设定;
          }
          public string employee_band
          {
             得到;设定;
          }
          public string employee_base_location
          {
             得到;设定;
          }
          public string employee_code
          {
             得到;设定;
          }
          public string employee_cost_center
          {
             得到;设定;
          }
          public string employee_designation
          {
             得到;设定;
          }
          public string employee_gender
          {
             得到;设定;
          }
          public string employee_phone_number
          {
             得到;设定;
          }
          public string [] groups
          {
             得到;设定;
          }
          public string manager_email_address
          {
             得到;设定;
          }
          public string manager_name
          {
             得到;设定;
          }
         公共字符串名称
          {
             得到;设定;
          }
          public string user_status
          {
             得到;设定;
          }
         公共字符串状态
          {
             得到;设定;
          }
          public int offset
          {
             得到;设定;
          }
          public int limit
          {
             得到;设定;
          }
      }
public interface IRequest
{
string corp_email_id { get; set; }
}
public interface ICreateRequest : IRequest
{
string name { get; set; }
string[] groups { get; set; }
string employee_phone_number { get; set; }
string employee_cost_center { get; set; }
string employee_code { get; set; }
string employee_base_location { get; set; }
string employee_designation { get; set; }
string employee_band { get; set; }
string employee_gender { get; set; }
string manager_name { get; set; }
string manager_email_address { get; set; }
string custom_field_1 { get; set; }
string custom_field_2 { get; set; }
string custom_field_3 { get; set; }
string custom_field_4 { get; set; }
string custom_field_5 { get; set; }
}
public interface IUpdateRequest : ICreateRequest
{
string user_status { get; set; }
}
public interface IDeleteRequest : IRequest { }
public interface ISelectRequest
{
string status { get; set; }
int offset { get; set; }
int limit { get; set; }
}
public class Request : IRequest, IUpdateRequest, IDeleteRequest, ISelectRequest
{
public string corp_email_id
{
get;set;
}
public string custom_field_1
{
get; set;
}
public string custom_field_2
{
get; set;
}
public string custom_field_3
{
get; set;
}
public string custom_field_4
{
get; set;
}
public string custom_field_5
{
get; set;
}
public string employee_band
{
get; set;
}
public string employee_base_location
{
get; set;
}
public string employee_code
{
get; set;
}
public string employee_cost_center
{
get; set;
}
public string employee_designation
{
get; set;
}
public string employee_gender
{
get; set;
}
public string employee_phone_number
{
get; set;
}
public string[] groups
{
get; set;
}
public string manager_email_address
{
get; set;
}
public string manager_name
{
get; set;
}
public string name
{
get; set;
}
public string user_status
{
get; set;
}
public string status
{
get; set;
}
public int offset
{
get; set;
}
public int limit
{
get; set;
}
}
推荐答案
有人可以帮忙吗?
can anyone help?
这篇关于仅序列化接口中可用的类的属性。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!