[英]Auto-Implemented Property Classes as Parameter
我想将属性类引用传递给方法。 例如:
Class SQLiteTables
{
public class tblPersonnel
{
public int PsnID { get; set; }
public string PsnFirstName { get; set; }
public string PsnMiddleName { get; set; }
public string PsnLastName { get; set; }
}
public class tblSchedules
{
public int SchID { get; set; }
public string SchDescription { get; set; }
public DateTime SchStartDtm { get; set; }
public DateTime SchEndDtm { get; set; }
...
public class TableName
{
public int Field1 { get; set; }
public string Field2 { get; set; }
public string Field3 { get; set; }
...
public string FieldN { get; set; }
}
}
我想创建一个类似这样的方法:
public void ThisMethod(PropertyClass propertyclassname)
{
List<propertyclassname> TempList = dbConn.Table<propertyclassname>().ToList<propertyclassname>();
}
并像这样使用它:
ThisMethod(tblPersonnel);
ThisMethod(tblSchedules);
我试图避免对每个属性使用多种方法。 我希望它是一种可重用的方法,但是我似乎无法弄清楚该怎么做。 提前谢谢了!
您应该使用泛型:
public void ThisMethod<T>(T mySet) where T : MySetBaseClass
{
...
}
您想用该方法做什么,谁叫它?
实际逻辑并不容易实现,但是如果将其更改为以下内容,则可能会解决
public abstract class PropertySetBase
{
public abstract int Property_int1 { get; set; }
public abstract string Property1 { get; set; }
public abstract string Property2 { get; set; }
public abstract string Property3 { get; set; }
}
头等舱
public class PropertySet1:PropertySetBase
{
public override int Property_int1
{
get
{
}
set
{
}
}
public override string Property1
{
get
{
}
set
{
}
}
public override string Property2
{
get
{
}
set
{
}
}
public override string Property3
{
get
{
}
set
{
}
}
}
二等
public class PropertySet2:PropertySetBase
{
public override int Property_int1
{
get
{
}
set
{
}
}
public override string Property1
{
get
{
}
set
{
}
}
public override string Property2
{
get
{
}
set
{
}
}
public override string Property3
{
get
{
}
set
{
}
}
}
这里是您的方法应如何编写以接受任何properties类
public void ThisMethod( PropertySetBase propertyclassname)
{
}
我认为您想重复使用propertyset类型,为此可以使用IEnumerable
public class PropertySet
{
public int Property0 { get; set; }
public string Property1 { get; set; }
public string Property2 { get; set; }
public string Property3 { get; set; }
}
在方法中使用此类型的列表,以用于要在方法中使用的尽可能多的项目
public void ThisMethod(List<PropertySet> propertyclass)
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.