我得到了一些关于构造函数的建议,但现在我有很多。我可以用函数或其他方式简化这些吗?这是我的课吗?
public class ContentViewModel
{
public ContentViewModel() { }
public ContentViewModel(Content content)
{
this.Content = content;
}
public ContentViewModel(string pk)
{
this.Content = new Content();
this.Content.PartitionKey = pk;
this.Content.Created = DateTime.Now;
}
public ContentViewModel(string pk, string rk)
{
this.Content = new Content();
this.Content.PartitionKey = pk;
this.Content.RowKey = rk;
this.Content.Created = DateTime.Now;
}
public ContentViewModel(string pk, string rk, string user)
{
this.Content = new Content();
this.Content.PartitionKey = pk;
this.Content.RowKey = rk;
this.Content.Created = DateTime.Now;
this.Content.CreatedBy = user;
}
public Content Content { get; set; }
public bool UseRowKey {
get {
return this.Content.PartitionKey.Substring(2, 2) == "05" ||
this.Content.PartitionKey.Substring(2, 2) == "06";
}
}
public string TempRowKey { get; set; }
}
我正在使用 c# 4。有人说过命名参数和可选参数。这会帮助我吗?