我有以下课程:
public class Content {
public string PartitionKey { get; set; }
public string RowKey { get; set; }
}
以下视图模型:
public class ContentViewModel
{
public ContentViewModel() { }
public Content Content { get; set; }
public bool UseRowKey {
get {
return this.Content.PartitionKey.Substring(2, 2) == "05" ||
this.Content.PartitionKey.Substring(2, 2) == "06";
}
}
}
我在ViewModel中创建了“UseRowKey”字段。但是,我是否也可以将其创建为类Content的一部分?
答案 0 :(得分:0)
像
这样的东西public class Content
{
public string PartitionKey { get; set; }
public string RowKey { get; set; }
public bool UseRowKey
{
get
{
return PartitionKey.Substring(2, 2) == "05" ||
PartitionKey.Substring(2, 2) == "06";
}
}
}
public class ContentViewModel
{
public ContentViewModel() { }
public Content Content { get; set; }
public bool UseRowKey
{
get
{
return this.Content.UseRowKey;
}
}
}
修改强>
要将其用作方法,您可以尝试
public class Content
{
public string PartitionKey { get; set; }
public string RowKey { get; set; }
public bool UseRowKey()
{
return PartitionKey.Substring(2, 2) == "05" ||
PartitionKey.Substring(2, 2) == "06";
}
}
public class ContentViewModel
{
public ContentViewModel() { }
public Content Content { get; set; }
public bool UseRowKey
{
get
{
return this.Content.UseRowKey();
}
}
}