0

I have the following class:

public class Content {
      public string PartitionKey { get; set; }
      public string RowKey { get; set; }
}

The following View Model:

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";
            }
        }
    }

I created the field "UseRowKey" in the ViewModel. However can I also create this as a method that's part of the class Content?

4

1 回答 1

0

How about something like

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;
        }
    }
}

EDIT

To use it as a method, you can try

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();
        }
    }
}
于 2012-07-11T05:44:31.020 回答