項目中實例化的對象,對象中裏面頗有不少屬性,有些是咱們不須要的,有些是咱們須要的,例如在下面的示例中:ID,CreateBy等屬性在CB_Projects對象中是不須要的,在獲取實例化對象屬性名稱的時候須要把這些屬性過濾掉。UpdateProjectRequest是入參實例bash
using System;
using System.Collections.Generic;
namespace ServiceMe.Apps.Business.Common.DAL
{
public partial class CB_Projects
{
public int ID { get; set; }
public string ProjectNumber { get; set; }
public string CimtasNumber { get; set; }
public string Root1 { get; set; }
public string Root2 { get; set; }
public string Fill1 { get; set; }
public string Fill2 { get; set; }
public string Fill3 { get; set; }
public string Fill4 { get; set; }
public string Fill5 { get; set; }
public string Fill6 { get; set; }
public Nullable<bool> IsDelete { get; set; }
public string JointNumber { get; set; }
public string OtherJoint { get; set; }
public string CreateBy { get; set; }
public Nullable<System.DateTime> CreateTime { get; set; }
public string ModifiedBy { get; set; }
public Nullable<System.DateTime> ModifiedTime { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ServiceMe.Apps.Business.Common.Models.RequestModel
{
/// <summary>
/// 修改項目請求參數
/// </summary>
public class UpdateProjectRequest
{
/// <summary>
/// 主鍵ID
/// </summary>
public int? ID { get; set; }
/// <summary>
/// 項目編號
/// </summary>
public string ProjectNumber { get; set; }
/// <summary>
/// 慶達西編號
/// </summary>
public string CimtasNumber { get; set; }
/// <summary>
/// root1
/// </summary>
public string Root1 { get; set; }
/// <summary>
/// Root2
/// </summary>
public string Root2 { get; set; }
/// <summary>
/// Fill1
/// </summary>
public string Fill1 { get; set; }
/// <summary>
/// Fill2
/// </summary>
public string Fill2 { get; set; }
/// <summary>
/// Fill3
/// </summary>
public string Fill3 { get; set; }
/// <summary>
/// Fill4
/// </summary>
public string Fill4 { get; set; }
/// <summary>
/// Fill5
/// </summary>
public string Fill5 { get; set; }
/// <summary>
/// Fill6
/// </summary>
public string Fill6 { get; set; }
}
}
複製代碼
public static void Main(string[] args, [FromBody]UpdateProjectRequest req)
{
CB_Projects cbProjects = new CB_Projects()
{
ProjectNumber = req.ProjectNumber,
CimtasNumber = req.CimtasNumber,
Root1 = req.Root1,
Root2 = req.Root2,
Fill1 = req.Fill1,
Fill2 = req.Fill2,
Fill3 = req.Fill3,
Fill4 = req.Fill4,
Fill5 = req.Fill5,
Fill6 = req.Fill6,
ModifiedBy = req.UserAccount,
ModifiedTime = DateTime.Now
};
PropertyInfo[] propertyInfos = typeof(CB_Projects).GetProperties();
List<string> nameList = propertyInfos.Where(t => t.GetValue(cbProjects) != null && t.Name.ToUpper() != "ID").Select(t => t.Name).ToList();
string str = string.Join(",", nameList);
string[] strArray = str.Split(',');
}
複製代碼