public override object ConvertFromString(string text, Type destinationType, IValueSerializerContext context) { if (text != null && text.IndexOfAny(WS) >= 0) { long num = 0; foreach (var item in text.Split(WS, StringSplitOptions.RemoveEmptyEntries)) { string a = InflectedName(item); num |= Convert.ToInt64((Enum)Enum.Parse(destinationType, a, /* ignoreCase */ true), CultureInfo.InvariantCulture); } return(Enum.ToObject(destinationType, num)); } return(Base.ConvertFromString(InflectedName(text), destinationType, context)); }
public object ConvertFromString(string text, Type destinationType, IValueSerializerContext context) { string s = text; if (s != null) { if ("yes".Equals(s, StringComparison.OrdinalIgnoreCase)) { return(true); } if ("no".Equals(s, StringComparison.OrdinalIgnoreCase)) { return(false); } } return(Base.ConvertFromString(text, destinationType, context)); }
public void ConvertFromString_will_convert_from_flags() { Assert.Equal(SocketFlags.Broadcast | SocketFlags.ControlDataTruncated | SocketFlags.Multicast, conv.ConvertFromString("Broadcast,ControlDataTruncated,Multicast", typeof(SocketFlags), null)); }