internal object Parse(string value)
{
if (value == null)
{
return null;
}
object result = null;
// bool|enum|flags|uint|int|int64|string|timeSpan
if (Type == "bool")
{
bool b;
bool.TryParse(value, out b);
result = b;
}
else if (Type == "uint")
{
uint u;
uint.TryParse(value, out u);
result = u;
}
else if (Type == "int")
{
int i;
int.TryParse(value, out i);
result = i;
}
else if (Type == "int64")
{
long l;
long.TryParse(value, out l);
result = l;
}
else if (Type == "string")
{
result = value;
}
else if (Type == "enum")
{
var enum1 = GetEnumValues()[value];
if (enum1 == null)
{
throw new COMException(string.Format("Enum must be one of {0}\r\n", this.GetEnumValues().FormattedString));
}
result = enum1.Value;
}
else if (Type == "flags")
{
if (value == "None" || value == string.Empty)
{
// IMPORTANT: workaround for Ftp_Schema.xml bug on validationFlags defaultValue=string.Empty.
result = 0L;
}
else
{
var parts = value.Split(',');
long flags = 0;
foreach (var part in parts)
{
var values = GetEnumValues();
var item = values[part.Trim()];
if (item == null)
{
throw new COMException(string.Format("Flags must be some combination of {0}\r\n", this.GetEnumValues().FormattedString));
}
flags |= item.Value;
}
result = flags;
}
}
else if (Type == "timeSpan")
{
if (AllowInfinite && value == "Infinite")
{
result = Timeout.InfiniteTimeSpan;
}
else if (TimeSpanFormat == "string")
{
TimeSpan t;
TimeSpan.TryParse(value, out t);
result = t;
}
else if (TimeSpanFormat == "minutes")
{
result = new TimeSpan(0, int.Parse(value), 0);
}
else if (TimeSpanFormat == "seconds")
{
result = new TimeSpan(0, 0, int.Parse(value));
}
}
Validate(result);
return result;
}