0
編輯問題:這應該很清楚。如何將不同的請求對象傳遞給格式相同的方法?
using System;
namespace UpdateDateTimeFields
{
class Program
{
static void Main(string[] args)
{
string dateTimeFormat = "dd/MM/yyy HH:mm:ss";
DateTime time = DateTime.Now;
Update(time, dateTimeFormat); //Should update time
movemnet mymove = new movemnet();
mymove.FromDate = DateTime.Now;
mymove.ToDate = DateTime.Now;
mymove.Name = "Test_Movement";
Update(mymove, dateTimeFormat); //should update FromDate, ToDate
ParentClass cls = new ParentClass();
cls.mv.FromDate = DateTime.Now;
cls.mv.ToDate = DateTime.Now;
cls.CurrentDate = DateTime.Now;
cls.Comment = "ParentClass_Comment";
Update(cls, dateTimeFormat); //should update FromDate, ToDate, CurrentDate
}
private static void Update<T>(T Request, string format)
{
// How can this be acheived ???
//tried with Using Reflection to Get and Set values of Properties - NO JOY !!!
}
}
internal class movemnet
{
public DateTime FromDate { get; set; }
public DateTime ToDate { get; set; }
public string Name { get; set; }
}
internal class ParentClass
{
public movemnet mv { get; set; }
public DateTime CurrentDate { get; set; }
public string Comment { get; set; }
}
}
我不清楚問題是什麼 - 指定類型參數(根據主題)或循環對象的字段(在這種情況下使用request.GetType()和Type.GetFiles)。 – 2009-04-27 01:10:31