????3???????????
??????1?????????????????????????????÷???????????????????????Щstatic????÷???????????????????????????DataGridViewRow????????????????Model????????£?
public static T ToObject<T>(DataGridViewRow item) where T:class
{
var model = item.DataBoundItem as T;
if (model != null)
return model;
var dr = item.DataBoundItem as System.Data.DataRowView;
model = (T)typeof(T).GetConstructor(new System.Type[] { }).Invoke(new object[] { });
//????????????????
PropertyInfo[] pro = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public);
Type type = model.GetType();
foreach (PropertyInfo propertyInfo in pro)
{
if (Convert.IsDBNull(dr[propertyInfo.Name]))
{
continue;
}
if (!string.IsNullOrEmpty(Convert.ToString(dr[propertyInfo.Name])))
{
var propertytype = propertyInfo.PropertyType;
if (propertytype == typeof(System.Nullable<DateTime>) || propertytype == typeof(DateTime))
{
type.GetProperty(propertyInfo.Name).SetValue(model?? Convert.ToDateTime(dr[propertyInfo.Name])?? null);
}
else if (propertytype == typeof(System.Nullable<decimal>) || propertytype == typeof(decimal))
{
type.GetProperty(propertyInfo.Name).SetValue(model?? Convert.ToDecimal(dr[propertyInfo.Name])?? null);
}
else if (propertytype == typeof(System.Nullable<int>) || propertytype == typeof(int))
{
type.GetProperty(propertyInfo.Name).SetValue(model?? Convert.ToInt32(dr[propertyInfo.Name])?? null);
}
else if (propertytype == typeof(System.Nullable<double>) || propertytype == typeof(double))
{
type.GetProperty(propertyInfo.Name).SetValue(model?? Convert.ToDouble(dr[propertyInfo.Name])?? null);
}
else
{
type.GetProperty(propertyInfo.Name).SetValue(model?? dr[propertyInfo.Name]?? null);
}
}
}
return model;
}
??????÷???????????????
??????????????????public void Fun1<T>(T a);??public void Fun1<U>(U a);?????????????????????????T??U?????????????????????????
???????????????д????????????дFuncA????д????????FuncB????д???????????????????У???????д??
abstract class BaseClass
{
public abstract T FuncA<T??U>(T t??U u) where U:T;
public abstract T FuncB<T>(T t) where T:IComparable;
}
class ClassA:BaseClass
{
public override X FuncA<X??Y>(X x??Y y){...}
public override T FuncB<T>(T t) where T:IComparable{...}
}
??????2?????????????
????public class Class_Base<DTO?? T>
????{}
?????????????????????????????????
??????3????????????????е?????
??????????????????????????????????????????????????????
????public interface Interface_Base<T>
????{}
????public class Class_Base<DTO?? T> : Interface_Base<DTO>
????{}
????DTO??????????Class_Base
??????4????????е?????????????÷??????????ú?????????????????????????????
???????巺????У?
????public delegate void MyDelegate<T>(T obj);
??????????е?????
????public delegate void MyDelegate<T>(T obj);
????static void Main(string[] args)
????{
????var method = new MyDelegate<int>(printInt);
????method(1);
????Console.ReadKey();
????}
????static void printInt(int i)
????{
????Console.WriteLine(i);
????}
??????5??????????????????????????????Щ?????????????????????????
???????????????
????public class Imps_Base<DTO?? T> : Ifs_Base<DTO>
????where T : BaseEntity
????where DTO : class
????{
????}