- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
public void ValidateValue( ref object value ) {
bool b;
if ( value == null ) return;
var typeName = BaseType.Name;
var valueType = value.GetType();
if ( valueType.Name == "String" ) {
if ( BaseType == valueType ) return;
if ( BaseType == Constants.Types.Boolean ) {
if ( string.Compare( "yes", (string) value, StringComparison.OrdinalIgnoreCase ) == 0 ) value = true;
else if ( string.Compare( "no", (string) value, StringComparison.OrdinalIgnoreCase ) == 0 ) value = false;
#if !CF
else if ( Boolean.TryParse( value.ToString(), out b ) ) value = b;
#else
else if (TryParseUtility.TryParse(value.ToString(), out b)) value = b;
#endif
else throw new ArgumentException( String.Format( Resources.ValueNotCorrectType, value ) );
return;
}
}
#if !CF
if ( typeName == "Boolean"
&& Boolean.TryParse( value.ToString(), out b ) ) {
value = b;
return;
}
UInt64 uintVal;
if ( typeName.StartsWith( "UInt64" )
&& UInt64.TryParse( value.ToString(), out uintVal ) ) {
value = uintVal;
return;
}
UInt32 uintVal32;
if ( typeName.StartsWith( "UInt32" )
&& UInt32.TryParse( value.ToString(), out uintVal32 ) ) {
value = uintVal32;
return;
}
long intVal;
if ( typeName.StartsWith( "long" )
&& long.TryParse( value.ToString(), out intVal ) ) {
value = intVal;
return;
}
int intVal32;
if ( typeName.StartsWith( "Int32" )
&& Int32.TryParse( value.ToString(), out intVal32 ) ) {
value = intVal32;
return;
}
#else
if (typeName == "Boolean" && TryParseUtility.TryParse(value.ToString(), out b)) { value = b; return; }
UInt64 uintVal;
if (typeName.StartsWith("UInt64") && TryParseUtility.TryParse(value.ToString(), out uintVal)) { value = uintVal; return; }
UInt32 uintVal32;
if (typeName.StartsWith("UInt32") && TryParseUtility.TryParse(value.ToString(), out uintVal32)) { value = uintVal32; return; }
long intVal;
if (typeName.StartsWith("long") && TryParseUtility.TryParse(value.ToString(), out intVal)) { value = intVal; return; }
Int32 intVal32;
if (typeName.StartsWith("Int32") && TryParseUtility.TryParse(value.ToString(), out intVal32)) { value = intVal32; return; }
#endif
object objValue;
#if RT
Type baseType = BaseType.GetTypeInfo().BaseType;
#else
var baseType = BaseType.BaseType;
#endif
if ( baseType != null
&& baseType.Name == "Enum"
&& ParseEnum( value.ToString(), out objValue ) ) {
value = objValue;
return;
}
throw new ArgumentException( String.Format( Resources.ValueNotCorrectType, value ) );
}
pushistayapodmyshka 24.11.2014 19:24 # 0