I can always go and do what is mentioned here. Using Enum.TryParse
However What I am doing is passing a string to the request. Then created a local variable on my controller of the Enum type so that I can pass the Enum type to my service method to perform task. I feel like if I can directly convert it to the type of Enum on the request's set property, that would be great.
This is what I have currently:
public enum SearchSortType
{
None,
Rating,
Date,
Etc
}
[DataContract]
public class MyRequest
{
/// <summary>
/// The field to order on.
/// </summary>
/// <value>
/// The order by.
/// </value>
[DataMember(Name = "sortOn")]
public string SortOn { get; set; }
}
what I want is following. I will keep posting String from the request.
[DataContract]
public class MyRequest
{
/// <summary>
/// The field to order on.
/// </summary>
/// <value>
/// The order by.
/// </value>
[DataMember(Name = "sortOn")]
public SearchSortType SortOn { get; set; }
}
Is it possible to keep passing string and get it converted on the set property ( or any other way to the enum so that I don't have to create a local variable and convert and then use it?