static void ThrowInvalidExp() { throw new FormatException(Locale.GetText("Invalid exponent")); }
/// <summary>Initializes a new instance of the <see cref="T:System.MissingMemberException" /> class.</summary> public MissingMemberException() : base(Locale.GetText("Cannot find the requested class member.")) { base.HResult = -2146233070; }
public ArgumentOutOfRangeException(string paramName) : base(Locale.GetText("Argument is out of range."), paramName) { HResult = Result; }
// Constructors public MethodAccessException() : base(Locale.GetText("Attempt to access a private/protected method failed.")) { HResult = Result; }
// Constructors public UriFormatException() : base(Locale.GetText("Invalid URI format")) { }
/// <summary>Initializes a new instance of the <see cref="T:System.ArrayTypeMismatchException" /> class.</summary> public ArrayTypeMismatchException() : base(Locale.GetText("Source array type cannot be assigned to destination array type.")) { base.HResult = -2146233085; }
/// <summary>Initializes a new instance of the <see cref="T:System.ContextMarshalException" /> class with default properties.</summary> public ContextMarshalException() : base(Locale.GetText("Attempt to marshal and object across a context failed.")) { base.HResult = -2146233084; }
// Constructors public InvalidCastException() : base(Locale.GetText("Cannot cast from source type to destination type.")) { HResult = Result; }
public MemberAccessException() : base(Locale.GetText("Cannot access a class member.")) { HResult = Result; }
/// <summary>Initializes a new instance of the <see cref="T:System.DllNotFoundException" /> class with default properties.</summary> public DllNotFoundException() : base(Locale.GetText("DLL not found.")) { base.HResult = -2146233052; }
public static object CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, object [] args, CultureInfo culture, object [] activationAttributes) { CheckType(type); #if NET_2_0 && !DISABLE_SECURITY if (type.ContainsGenericParameters) { throw new ArgumentException(type + " is an open generic type", "type"); } #endif // It seems to apply the same rules documented for InvokeMember: "If the type of lookup // is omitted, BindingFlags.Public | BindingFlags.Instance will apply". if ((bindingAttr & _accessFlags) == 0) { bindingAttr |= BindingFlags.Public | BindingFlags.Instance; } int length = 0; if (args != null) { length = args.Length; } Type[] atypes = length == 0 ? Type.EmptyTypes : new Type [length]; for (int i = 0; i < length; ++i) { if (args [i] != null) { atypes [i] = args [i].GetType(); } } if (binder == null) { binder = Binder.DefaultBinder; } ConstructorInfo ctor = (ConstructorInfo)binder.SelectMethod(bindingAttr, type.GetConstructors(bindingAttr), atypes, null); if (ctor == null) { // Not sure about this if (type.IsValueType && atypes.Length == 0) { return(CreateInstanceInternal(type)); } StringBuilder sb = new StringBuilder(); foreach (Type t in atypes) { sb.Append(t != null ? t.ToString() : "(unknown)"); sb.Append(", "); } if (sb.Length > 2) { sb.Length -= 2; } throw new MissingMethodException(String.Format(Locale.GetText("No constructor found for {0}::.ctor({1})"), type.FullName, sb)); } CheckAbstractType(type); #if !NET_2_1 || MONOTOUCH if (activationAttributes != null && activationAttributes.Length > 0) { if (!type.IsMarshalByRef) { string msg = Locale.GetText("Type '{0}' doesn't derive from MarshalByRefObject.", type.FullName); throw new NotSupportedException(msg); } object newOb = ActivationServices.CreateProxyFromAttributes(type, activationAttributes); if (newOb != null) { // This returns null ctor.Invoke(newOb, bindingAttr, binder, args, culture); return(newOb); } } #endif return(ctor.Invoke(bindingAttr, binder, args, culture)); }
/// <summary>Initializes a new instance of the <see cref="T:System.NullReferenceException" /> class, setting the <see cref="P:System.Exception.Message" /> property of the new instance to a system-supplied message that describes the error, such as "The value 'null' was found where an instance of an object was required." This message takes into account the current system culture.</summary> public NullReferenceException() : base(Locale.GetText("A null value was found where an object instance was required.")) { base.HResult = -2147467261; }
/// <summary>Initializes a new instance of the <see cref="T:System.MissingMethodException" /> class.</summary> public MissingMethodException() : base(Locale.GetText("Cannot find the requested method.")) { base.HResult = -2146233069; }
private static string stripStyles(string s, NumberStyles style, NumberFormatInfo nfi, out int decPos, out bool isNegative, out bool expFlag, out int exp, bool throwex) { isNegative = false; expFlag = false; exp = 0; decPos = -1; bool hasSign = false; bool hasOpeningParentheses = false; bool hasDecimalPoint = false; bool allowedLeadingWhiteSpace = ((style & NumberStyles.AllowLeadingWhite) != 0); bool allowedTrailingWhiteSpace = ((style & NumberStyles.AllowTrailingWhite) != 0); bool allowedLeadingSign = ((style & NumberStyles.AllowLeadingSign) != 0); bool allowedTrailingSign = ((style & NumberStyles.AllowTrailingSign) != 0); bool allowedParentheses = ((style & NumberStyles.AllowParentheses) != 0); bool allowedThousands = ((style & NumberStyles.AllowThousands) != 0); bool allowedDecimalPoint = ((style & NumberStyles.AllowDecimalPoint) != 0); bool allowedExponent = ((style & NumberStyles.AllowExponent) != 0); /* get rid of currency symbol */ bool hasCurrency = false; if ((style & NumberStyles.AllowCurrencySymbol) != 0) { int index = s.IndexOf(nfi.CurrencySymbol); if (index >= 0) { s = s.Remove(index, nfi.CurrencySymbol.Length); hasCurrency = true; } } string decimalSep = (hasCurrency) ? nfi.CurrencyDecimalSeparator : nfi.NumberDecimalSeparator; string groupSep = (hasCurrency) ? nfi.CurrencyGroupSeparator : nfi.NumberGroupSeparator; int pos = 0; int len = s.Length; StringBuilder sb = new StringBuilder(len); // leading while (pos < len) { char ch = s[pos]; if (Char.IsDigit(ch)) { break; // end of leading } else if (allowedLeadingWhiteSpace && Char.IsWhiteSpace(ch)) { pos++; } else if (allowedParentheses && ch == '(' && !hasSign && !hasOpeningParentheses) { hasOpeningParentheses = true; hasSign = true; isNegative = true; pos++; } else if (allowedLeadingSign && ch == nfi.NegativeSign[0] && !hasSign) { int slen = nfi.NegativeSign.Length; if (slen == 1 || s.IndexOf(nfi.NegativeSign, pos, slen) == pos) { hasSign = true; isNegative = true; pos += slen; } } else if (allowedLeadingSign && ch == nfi.PositiveSign[0] && !hasSign) { int slen = nfi.PositiveSign.Length; if (slen == 1 || s.IndexOf(nfi.PositiveSign, pos, slen) == pos) { hasSign = true; pos += slen; } } else if (allowedDecimalPoint && ch == decimalSep[0]) { int slen = decimalSep.Length; if (slen != 1 && s.IndexOf(decimalSep, pos, slen) != pos) { if (throwex) { ThrowAtPos(pos); } else { return(null); } } break; } else { if (throwex) { ThrowAtPos(pos); } else { return(null); } } } if (pos == len) { if (throwex) { throw new FormatException(Locale.GetText("No digits found")); } else { return(null); } } // digits while (pos < len) { char ch = s[pos]; if (Char.IsDigit(ch)) { sb.Append(ch); pos++; } else if (allowedThousands && ch == groupSep[0]) { int slen = groupSep.Length; if (slen != 1 && s.IndexOf(groupSep, pos, slen) != pos) { if (throwex) { ThrowAtPos(pos); } else { return(null); } } pos += slen; } else if (allowedDecimalPoint && ch == decimalSep[0] && !hasDecimalPoint) { int slen = decimalSep.Length; if (slen == 1 || s.IndexOf(decimalSep, pos, slen) == pos) { decPos = sb.Length; hasDecimalPoint = true; pos += slen; } } else { break; } } // exponent if (pos < len) { char ch = s[pos]; if (allowedExponent && Char.ToUpperInvariant(ch) == 'E') { expFlag = true; pos++; if (pos >= len) { if (throwex) { ThrowInvalidExp(); } else { return(null); } } ch = s[pos]; bool isNegativeExp = false; if (ch == nfi.PositiveSign[0]) { int slen = nfi.PositiveSign.Length; if (slen == 1 || s.IndexOf(nfi.PositiveSign, pos, slen) == pos) { pos += slen; if (pos >= len) { if (throwex) { ThrowInvalidExp(); } else { return(null); } } } } else if (ch == nfi.NegativeSign[0]) { int slen = nfi.NegativeSign.Length; if (slen == 1 || s.IndexOf(nfi.NegativeSign, pos, slen) == pos) { pos += slen; if (pos >= len) { if (throwex) { ThrowInvalidExp(); } else { return(null); } } isNegativeExp = true; } } ch = s[pos]; if (!Char.IsDigit(ch)) { if (throwex) { ThrowInvalidExp(); } else { return(null); } } exp = ch - '0'; pos++; while (pos < len && Char.IsDigit(s[pos])) { exp *= 10; exp += s[pos] - '0'; pos++; } if (isNegativeExp) { exp *= -1; } } } // trailing while (pos < len) { char ch = s[pos]; if (allowedTrailingWhiteSpace && Char.IsWhiteSpace(ch)) { pos++; } else if (allowedParentheses && ch == ')' && hasOpeningParentheses) { hasOpeningParentheses = false; pos++; } else if (allowedTrailingSign && ch == nfi.NegativeSign[0] && !hasSign) { int slen = nfi.NegativeSign.Length; if (slen == 1 || s.IndexOf(nfi.NegativeSign, pos, slen) == pos) { hasSign = true; isNegative = true; pos += slen; } } else if (allowedTrailingSign && ch == nfi.PositiveSign[0] && !hasSign) { int slen = nfi.PositiveSign.Length; if (slen == 1 || s.IndexOf(nfi.PositiveSign, pos, slen) == pos) { hasSign = true; pos += slen; } } else { if (throwex) { ThrowAtPos(pos); } else { return(null); } } } if (hasOpeningParentheses) { if (throwex) { throw new FormatException(Locale.GetText("Closing Parentheses not found")); } else { return(null); } } if (!hasDecimalPoint) { decPos = sb.Length; } return(sb.ToString()); }
internal static bool Parse(string s, NumberStyles style, IFormatProvider provider, bool tryParse, out ulong result, out Exception exc) { result = 0; exc = null; if (s == null) { if (!tryParse) { exc = new ArgumentNullException("s"); } return(false); } if (s.Length == 0) { if (!tryParse) { exc = Int32.GetFormatException(); } return(false); } NumberFormatInfo nfi = null; if (provider != null) { Type typeNFI = typeof(NumberFormatInfo); nfi = provider.GetFormat(typeNFI) as NumberFormatInfo; } if (nfi == null) { nfi = Thread.CurrentThread.CurrentCulture.NumberFormat; } if (!Int32.CheckStyle(style, tryParse, ref exc)) { return(false); } bool AllowCurrencySymbol = (style & NumberStyles.AllowCurrencySymbol) != 0; bool AllowHexSpecifier = (style & NumberStyles.AllowHexSpecifier) != 0; bool AllowThousands = (style & NumberStyles.AllowThousands) != 0; bool AllowDecimalPoint = (style & NumberStyles.AllowDecimalPoint) != 0; bool AllowParentheses = (style & NumberStyles.AllowParentheses) != 0; bool AllowTrailingSign = (style & NumberStyles.AllowTrailingSign) != 0; bool AllowLeadingSign = (style & NumberStyles.AllowLeadingSign) != 0; bool AllowTrailingWhite = (style & NumberStyles.AllowTrailingWhite) != 0; bool AllowLeadingWhite = (style & NumberStyles.AllowLeadingWhite) != 0; bool AllowExponent = (style & NumberStyles.AllowExponent) != 0; int pos = 0; if (AllowLeadingWhite && !Int32.JumpOverWhite(ref pos, s, true, tryParse, ref exc)) { return(false); } bool foundOpenParentheses = false; bool negative = false; bool foundSign = false; bool foundCurrency = false; // Pre-number stuff if (AllowParentheses && s [pos] == '(') { foundOpenParentheses = true; foundSign = true; negative = true; // MS always make the number negative when there parentheses // even when NumberFormatInfo.NumberNegativePattern != 0!!! pos++; if (AllowLeadingWhite && !Int32.JumpOverWhite(ref pos, s, true, tryParse, ref exc)) { return(false); } if (s.Substring(pos, nfi.NegativeSign.Length) == nfi.NegativeSign) { if (!tryParse) { exc = Int32.GetFormatException(); } return(false); } if (s.Substring(pos, nfi.PositiveSign.Length) == nfi.PositiveSign) { if (!tryParse) { exc = Int32.GetFormatException(); } return(false); } } if (AllowLeadingSign && !foundSign) { // Sign + Currency Int32.FindSign(ref pos, s, nfi, ref foundSign, ref negative); if (foundSign) { if (AllowLeadingWhite && !Int32.JumpOverWhite(ref pos, s, true, tryParse, ref exc)) { return(false); } if (AllowCurrencySymbol) { Int32.FindCurrency(ref pos, s, nfi, ref foundCurrency); if (foundCurrency && AllowLeadingWhite && !Int32.JumpOverWhite(ref pos, s, true, tryParse, ref exc)) { return(false); } } } } if (AllowCurrencySymbol && !foundCurrency) { // Currency + sign Int32.FindCurrency(ref pos, s, nfi, ref foundCurrency); if (foundCurrency) { if (AllowLeadingWhite && !Int32.JumpOverWhite(ref pos, s, true, tryParse, ref exc)) { return(false); } if (foundCurrency) { if (!foundSign && AllowLeadingSign) { Int32.FindSign(ref pos, s, nfi, ref foundSign, ref negative); if (foundSign && AllowLeadingWhite && !Int32.JumpOverWhite(ref pos, s, true, tryParse, ref exc)) { return(false); } } } } } ulong number = 0; int nDigits = 0; int decimalPointPos = -1; ulong digitValue; char hexDigit; // Number stuff // Just the same as Int32, but this one adds instead of substract while (pos < s.Length) { if (!Int32.ValidDigit(s [pos], AllowHexSpecifier)) { if (AllowThousands && (Int32.FindOther(ref pos, s, nfi.NumberGroupSeparator) || Int32.FindOther(ref pos, s, nfi.CurrencyGroupSeparator))) { continue; } if (AllowDecimalPoint && decimalPointPos < 0 && (Int32.FindOther(ref pos, s, nfi.NumberDecimalSeparator) || Int32.FindOther(ref pos, s, nfi.CurrencyDecimalSeparator))) { decimalPointPos = nDigits; continue; } break; } nDigits++; if (AllowHexSpecifier) { hexDigit = s [pos++]; if (Char.IsDigit(hexDigit)) { digitValue = (ulong)(hexDigit - '0'); } else if (Char.IsLower(hexDigit)) { digitValue = (ulong)(hexDigit - 'a' + 10); } else { digitValue = (ulong)(hexDigit - 'A' + 10); } if (tryParse) { // Any number above 32 will do bool can_overflow = number > 0xffff; number = number * 16 + digitValue; if (can_overflow && number < 16) { return(false); } } else { number = checked (number * 16 + digitValue); } continue; } try { number = checked (number * 10 + (ulong)(s [pos++] - '0')); } catch (OverflowException) { if (!tryParse) { exc = new OverflowException(Locale.GetText("Value too large or too small.")); } return(false); } } // Post number stuff if (nDigits == 0) { if (!tryParse) { exc = Int32.GetFormatException(); } return(false); } int exponent = 0; if (AllowExponent) { if (Int32.FindExponent(ref pos, s, ref exponent, tryParse, ref exc) && exc != null) { return(false); } } if (AllowTrailingSign && !foundSign) { // Sign + Currency Int32.FindSign(ref pos, s, nfi, ref foundSign, ref negative); if (foundSign && pos < s.Length) { if (AllowTrailingWhite && !Int32.JumpOverWhite(ref pos, s, true, tryParse, ref exc)) { return(false); } } } if (AllowCurrencySymbol && !foundCurrency) { if (AllowTrailingWhite && pos < s.Length && !Int32.JumpOverWhite(ref pos, s, false, tryParse, ref exc)) { return(false); } // Currency + sign Int32.FindCurrency(ref pos, s, nfi, ref foundCurrency); if (foundCurrency && pos < s.Length) { if (AllowTrailingWhite && !Int32.JumpOverWhite(ref pos, s, true, tryParse, ref exc)) { return(false); } if (!foundSign && AllowTrailingSign) { Int32.FindSign(ref pos, s, nfi, ref foundSign, ref negative); } } } if (AllowTrailingWhite && pos < s.Length && !Int32.JumpOverWhite(ref pos, s, false, tryParse, ref exc)) { return(false); } if (foundOpenParentheses) { if (pos >= s.Length || s [pos++] != ')') { if (!tryParse) { exc = Int32.GetFormatException(); } return(false); } if (AllowTrailingWhite && pos < s.Length && !Int32.JumpOverWhite(ref pos, s, false, tryParse, ref exc)) { return(false); } } if (pos < s.Length && s [pos] != '\u0000') { if (!tryParse) { exc = Int32.GetFormatException(); } return(false); } // -0 is legal but other negative values are not if (negative && (number > 0)) { if (!tryParse) { exc = new OverflowException( Locale.GetText("Negative number")); } return(false); } if (decimalPointPos >= 0) { exponent = exponent - nDigits + decimalPointPos; } if (exponent < 0) { // // Any non-zero values after decimal point are not allowed // long remainder; number = (ulong)Math.DivRem((long)number, (long)Math.Pow(10, -exponent), out remainder); if (remainder != 0) { if (!tryParse) { exc = new OverflowException("Value too large or too small."); } return(false); } } else if (exponent > 0) { // // result *= 10^exponent // // Reduce the risk of throwing an overflow exc // double res = checked (Math.Pow(10, exponent) * number); if (res < MinValue || res > MaxValue) { if (!tryParse) { exc = new OverflowException("Value too large or too small."); } return(false); } number = (ulong)res; } result = number; return(true); }
public MissingMemberException() : base(Locale.GetText("Cannot find the requested class member.")) { HResult = Result; }
// Constructors public NotSupportedException() : base(Locale.GetText("Operation is not supported.")) { HResult = Result; }
// Constructors public InvalidProgramException() : base(Locale.GetText("Metadata is invalid.")) { }
// Constructors public TypeInitializationException(string fullTypeName, Exception innerException) : base(Locale.GetText("An exception was thrown by the type initializer for ") + fullTypeName, innerException) { this.type_name = fullTypeName; }
internal static bool Parse(string s, bool tryParse, out uint result, out Exception exc) { uint val = 0; int len; int i; bool digits_seen = false; bool has_negative_sign = false; result = 0; exc = null; if (s == null) { if (!tryParse) { exc = new ArgumentNullException("s"); } return(false); } len = s.Length; char c; for (i = 0; i < len; i++) { c = s [i]; if (!Char.IsWhiteSpace(c)) { break; } } if (i == len) { if (!tryParse) { exc = Int32.GetFormatException(); } return(false); } if (s [i] == '+') { i++; } else if (s[i] == '-') { i++; has_negative_sign = true; } for (; i < len; i++) { c = s [i]; if (c >= '0' && c <= '9') { uint d = (uint)(c - '0'); if ((val > MaxValue / 10) || (val == (MaxValue / 10) && d > (MaxValue % 10))) { if (!tryParse) { exc = new OverflowException(Locale.GetText("Value is too large")); } return(false); } val = (val * 10) + d; digits_seen = true; } else if (!Int32.ProcessTrailingWhitespace(tryParse, s, i, ref exc)) { return(false); } } if (!digits_seen) { if (!tryParse) { exc = Int32.GetFormatException(); } return(false); } // -0 is legal but other negative values are not if (has_negative_sign && (val > 0)) { if (!tryParse) { exc = new OverflowException( Locale.GetText("Negative number")); } return(false); } result = val; return(true); }
public static object CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, object [] args, CultureInfo culture, object [] activationAttributes) { CheckType(type); if (type.ContainsGenericParameters) { throw new ArgumentException(type + " is an open generic type", "type"); } // It seems to apply the same rules documented for InvokeMember: "If the type of lookup // is omitted, BindingFlags.Public | BindingFlags.Instance will apply". if ((bindingAttr & _accessFlags) == 0) { bindingAttr |= BindingFlags.Public | BindingFlags.Instance; } if (binder == null) { binder = Binder.DefaultBinder; } object state; ConstructorInfo ctor = (ConstructorInfo)binder.BindToMethod(bindingAttr, type.GetConstructors(bindingAttr), ref args, null, null, null, out state); if (ctor == null) { // Not sure about this if (type.IsValueType && (args == null || args.Length == 0)) { return(CreateInstanceInternal(type)); } var sb = new StringBuilder(); if (args != null) { for (int i = 0; i < args.Length; i++) { if (i > 0) { sb.Append(", "); } var argument = args [i]; var arg_type = argument != null?argument.GetType() : null; sb.Append(arg_type != null ? arg_type.ToString() : "(unknown)"); } } throw new MissingMethodException(String.Format(Locale.GetText("No constructor found for {0}::.ctor({1})"), type.FullName, sb)); } CheckAbstractType(type); if (activationAttributes != null && activationAttributes.Length > 0) { #if DISABLE_REMOTING throw new NotSupportedException("Activation attributes are not supported"); #else if (!type.IsMarshalByRef) { string msg = Locale.GetText("Type '{0}' doesn't derive from MarshalByRefObject.", type.FullName); throw new NotSupportedException(msg); } object newOb = ActivationServices.CreateProxyFromAttributes(type, activationAttributes); if (newOb != null) { // This returns null ctor.Invoke(newOb, bindingAttr, binder, args, culture); return(newOb); } #endif } return(ctor.Invoke(bindingAttr, binder, args, culture)); }
internal static bool Parse(string s, NumberStyles style, IFormatProvider provider, bool tryParse, out uint result, out Exception exc) { result = 0; exc = null; if (s == null) { if (!tryParse) { exc = new ArgumentNullException("s"); } return(false); } if (s.Length == 0) { if (!tryParse) { exc = Int32.GetFormatException(); } return(false); } NumberFormatInfo nfi = null; if (provider != null) { Type typeNFI = typeof(NumberFormatInfo); nfi = (NumberFormatInfo)provider.GetFormat(typeNFI); } if (nfi == null) { nfi = Thread.CurrentThread.CurrentCulture.NumberFormat; } if (!Int32.CheckStyle(style, tryParse, ref exc)) { return(false); } bool AllowCurrencySymbol = (style & NumberStyles.AllowCurrencySymbol) != 0; bool AllowHexSpecifier = (style & NumberStyles.AllowHexSpecifier) != 0; bool AllowThousands = (style & NumberStyles.AllowThousands) != 0; bool AllowDecimalPoint = (style & NumberStyles.AllowDecimalPoint) != 0; bool AllowParentheses = (style & NumberStyles.AllowParentheses) != 0; bool AllowTrailingSign = (style & NumberStyles.AllowTrailingSign) != 0; bool AllowLeadingSign = (style & NumberStyles.AllowLeadingSign) != 0; bool AllowTrailingWhite = (style & NumberStyles.AllowTrailingWhite) != 0; bool AllowLeadingWhite = (style & NumberStyles.AllowLeadingWhite) != 0; int pos = 0; if (AllowLeadingWhite && !Int32.JumpOverWhite(ref pos, s, true, tryParse, ref exc)) { return(false); } bool foundOpenParentheses = false; bool negative = false; bool foundSign = false; bool foundCurrency = false; // Pre-number stuff if (AllowParentheses && s [pos] == '(') { foundOpenParentheses = true; foundSign = true; negative = true; // MS always make the number negative when there parentheses // even when NumberFormatInfo.NumberNegativePattern != 0!!! pos++; if (AllowLeadingWhite && !Int32.JumpOverWhite(ref pos, s, true, tryParse, ref exc)) { return(false); } if (s.Substring(pos, nfi.NegativeSign.Length) == nfi.NegativeSign) { if (!tryParse) { exc = Int32.GetFormatException(); } return(false); } if (s.Substring(pos, nfi.PositiveSign.Length) == nfi.PositiveSign) { if (!tryParse) { exc = Int32.GetFormatException(); } return(false); } } if (AllowLeadingSign && !foundSign) { // Sign + Currency Int32.FindSign(ref pos, s, nfi, ref foundSign, ref negative); if (foundSign) { if (AllowLeadingWhite && !Int32.JumpOverWhite(ref pos, s, true, tryParse, ref exc)) { return(false); } if (AllowCurrencySymbol) { Int32.FindCurrency(ref pos, s, nfi, ref foundCurrency); if (foundCurrency && AllowLeadingWhite && !Int32.JumpOverWhite(ref pos, s, true, tryParse, ref exc)) { return(false); } } } } if (AllowCurrencySymbol && !foundCurrency) { // Currency + sign Int32.FindCurrency(ref pos, s, nfi, ref foundCurrency); if (foundCurrency) { if (AllowLeadingWhite && !Int32.JumpOverWhite(ref pos, s, true, tryParse, ref exc)) { return(false); } if (foundCurrency) { if (!foundSign && AllowLeadingSign) { Int32.FindSign(ref pos, s, nfi, ref foundSign, ref negative); if (foundSign && AllowLeadingWhite && !Int32.JumpOverWhite(ref pos, s, true, tryParse, ref exc)) { return(false); } } } } } uint number = 0; int nDigits = 0; bool decimalPointFound = false; uint digitValue; char hexDigit; // Number stuff // Just the same as Int32, but this one adds instead of substract do { if (!Int32.ValidDigit(s [pos], AllowHexSpecifier)) { if (AllowThousands && Int32.FindOther(ref pos, s, nfi.NumberGroupSeparator)) { continue; } else if (!decimalPointFound && AllowDecimalPoint && Int32.FindOther(ref pos, s, nfi.NumberDecimalSeparator)) { decimalPointFound = true; continue; } break; } else if (AllowHexSpecifier) { nDigits++; hexDigit = s [pos++]; if (Char.IsDigit(hexDigit)) { digitValue = (uint)(hexDigit - '0'); } else if (Char.IsLower(hexDigit)) { digitValue = (uint)(hexDigit - 'a' + 10); } else { digitValue = (uint)(hexDigit - 'A' + 10); } if (tryParse) { ulong l = number * 16 + digitValue; if (l > MaxValue) { return(false); } number = (uint)l; } else { number = checked (number * 16 + digitValue); } } else if (decimalPointFound) { nDigits++; // Allows decimal point as long as it's only // followed by zeroes. if (s [pos++] != '0') { if (!tryParse) { exc = new OverflowException(Locale.GetText("Value too large or too small.")); } return(false); } } else { nDigits++; try { number = checked (number * 10 + (uint)(s [pos++] - '0')); } catch (OverflowException) { if (!tryParse) { exc = new OverflowException(Locale.GetText("Value too large or too small.")); } return(false); } } }while (pos < s.Length); // Post number stuff if (nDigits == 0) { if (!tryParse) { exc = Int32.GetFormatException(); } return(false); } if (AllowTrailingSign && !foundSign) { // Sign + Currency Int32.FindSign(ref pos, s, nfi, ref foundSign, ref negative); if (foundSign) { if (AllowTrailingWhite && !Int32.JumpOverWhite(ref pos, s, true, tryParse, ref exc)) { return(false); } if (AllowCurrencySymbol) { Int32.FindCurrency(ref pos, s, nfi, ref foundCurrency); } } } if (AllowCurrencySymbol && !foundCurrency) { // Currency + sign Int32.FindCurrency(ref pos, s, nfi, ref foundCurrency); if (foundCurrency) { if (AllowTrailingWhite && !Int32.JumpOverWhite(ref pos, s, true, tryParse, ref exc)) { return(false); } if (!foundSign && AllowTrailingSign) { Int32.FindSign(ref pos, s, nfi, ref foundSign, ref negative); } } } if (AllowTrailingWhite && pos < s.Length && !Int32.JumpOverWhite(ref pos, s, false, tryParse, ref exc)) { return(false); } if (foundOpenParentheses) { if (pos >= s.Length || s [pos++] != ')') { if (!tryParse) { exc = Int32.GetFormatException(); } return(false); } if (AllowTrailingWhite && pos < s.Length && !Int32.JumpOverWhite(ref pos, s, false, tryParse, ref exc)) { return(false); } } if (pos < s.Length && s [pos] != '\u0000') { if (!tryParse) { exc = Int32.GetFormatException(); } return(false); } // -0 is legal but other negative values are not if (negative && (number > 0)) { if (!tryParse) { exc = new OverflowException( Locale.GetText("Negative number")); } return(false); } result = number; return(true); }
// Constructors public TimeoutException() : base(Locale.GetText("The operation has timed-out.")) { HResult = Result; }
public override bool Equals(object o) { throw new NotSupportedException(Locale.GetText("This operation is not supported for this type.")); }
// Constructors public CannotUnloadAppDomainException() : base(Locale.GetText("Attempt to unload application domain failed.")) { HResult = Result; }
internal static bool Parse(string s, NumberStyles style, IFormatProvider provider, bool tryParse, out ulong result, out Exception exc) { result = 0UL; exc = null; if (s == null) { if (!tryParse) { exc = new ArgumentNullException("s"); } return(false); } if (s.Length == 0) { if (!tryParse) { exc = int.GetFormatException(); } return(false); } NumberFormatInfo numberFormatInfo = null; if (provider != null) { Type typeFromHandle = typeof(NumberFormatInfo); numberFormatInfo = (NumberFormatInfo)provider.GetFormat(typeFromHandle); } if (numberFormatInfo == null) { numberFormatInfo = Thread.CurrentThread.CurrentCulture.NumberFormat; } if (!int.CheckStyle(style, tryParse, ref exc)) { return(false); } bool flag = (style & NumberStyles.AllowCurrencySymbol) != NumberStyles.None; bool flag2 = (style & NumberStyles.AllowHexSpecifier) != NumberStyles.None; bool flag3 = (style & NumberStyles.AllowThousands) != NumberStyles.None; bool flag4 = (style & NumberStyles.AllowDecimalPoint) != NumberStyles.None; bool flag5 = (style & NumberStyles.AllowParentheses) != NumberStyles.None; bool flag6 = (style & NumberStyles.AllowTrailingSign) != NumberStyles.None; bool flag7 = (style & NumberStyles.AllowLeadingSign) != NumberStyles.None; bool flag8 = (style & NumberStyles.AllowTrailingWhite) != NumberStyles.None; bool flag9 = (style & NumberStyles.AllowLeadingWhite) != NumberStyles.None; int num = 0; if (flag9 && !int.JumpOverWhite(ref num, s, true, tryParse, ref exc)) { return(false); } bool flag10 = false; bool flag11 = false; bool flag12 = false; bool flag13 = false; if (flag5 && s[num] == '(') { flag10 = true; flag12 = true; flag11 = true; num++; if (flag9 && !int.JumpOverWhite(ref num, s, true, tryParse, ref exc)) { return(false); } if (s.Substring(num, numberFormatInfo.NegativeSign.Length) == numberFormatInfo.NegativeSign) { if (!tryParse) { exc = int.GetFormatException(); } return(false); } if (s.Substring(num, numberFormatInfo.PositiveSign.Length) == numberFormatInfo.PositiveSign) { if (!tryParse) { exc = int.GetFormatException(); } return(false); } } if (flag7 && !flag12) { int.FindSign(ref num, s, numberFormatInfo, ref flag12, ref flag11); if (flag12) { if (flag9 && !int.JumpOverWhite(ref num, s, true, tryParse, ref exc)) { return(false); } if (flag) { int.FindCurrency(ref num, s, numberFormatInfo, ref flag13); if (flag13 && flag9 && !int.JumpOverWhite(ref num, s, true, tryParse, ref exc)) { return(false); } } } } if (flag && !flag13) { int.FindCurrency(ref num, s, numberFormatInfo, ref flag13); if (flag13) { if (flag9 && !int.JumpOverWhite(ref num, s, true, tryParse, ref exc)) { return(false); } if (flag13 && !flag12 && flag7) { int.FindSign(ref num, s, numberFormatInfo, ref flag12, ref flag11); if (flag12 && flag9 && !int.JumpOverWhite(ref num, s, true, tryParse, ref exc)) { return(false); } } } } ulong num2 = 0UL; int num3 = 0; bool flag14 = false; do { if (!int.ValidDigit(s[num], flag2)) { if (!flag3 || !int.FindOther(ref num, s, numberFormatInfo.NumberGroupSeparator)) { if (flag14 || !flag4 || !int.FindOther(ref num, s, numberFormatInfo.NumberDecimalSeparator)) { break; } flag14 = true; } } else if (flag2) { num3++; char c = s[num++]; ulong num4; if (char.IsDigit(c)) { num4 = (ulong)((long)(c - '0')); } else if (char.IsLower(c)) { num4 = (ulong)((long)(c - 'a' + '\n')); } else { num4 = (ulong)((long)(c - 'A' + '\n')); } if (tryParse) { bool flag15 = num2 > 65535UL; num2 = num2 * 16UL + num4; if (flag15 && num2 < 16UL) { return(false); } } else { num2 = checked (num2 * 16UL + num4); } } else if (flag14) { num3++; if (s[num++] != '0') { goto Block_51; } } else { num3++; try { num2 = checked (num2 * 10UL + (ulong)(s[num++] - '0')); } catch (OverflowException) { if (!tryParse) { exc = new OverflowException(Locale.GetText("Value too large or too small.")); } return(false); } } }while (num < s.Length); goto IL_44B; Block_51: if (!tryParse) { exc = new OverflowException(Locale.GetText("Value too large or too small.")); } return(false); IL_44B: if (num3 == 0) { if (!tryParse) { exc = int.GetFormatException(); } return(false); } if (flag6 && !flag12) { int.FindSign(ref num, s, numberFormatInfo, ref flag12, ref flag11); if (flag12) { if (flag8 && !int.JumpOverWhite(ref num, s, true, tryParse, ref exc)) { return(false); } if (flag) { int.FindCurrency(ref num, s, numberFormatInfo, ref flag13); } } } if (flag && !flag13) { int.FindCurrency(ref num, s, numberFormatInfo, ref flag13); if (flag13) { if (flag8 && !int.JumpOverWhite(ref num, s, true, tryParse, ref exc)) { return(false); } if (!flag12 && flag6) { int.FindSign(ref num, s, numberFormatInfo, ref flag12, ref flag11); } } } if (flag8 && num < s.Length && !int.JumpOverWhite(ref num, s, false, tryParse, ref exc)) { return(false); } if (flag10) { if (num >= s.Length || s[num++] != ')') { if (!tryParse) { exc = int.GetFormatException(); } return(false); } if (flag8 && num < s.Length && !int.JumpOverWhite(ref num, s, false, tryParse, ref exc)) { return(false); } } if (num < s.Length && s[num] != '\0') { if (!tryParse) { exc = int.GetFormatException(); } return(false); } if (flag11 && num2 > 0UL) { if (!tryParse) { exc = new OverflowException(Locale.GetText("Negative number")); } return(false); } result = num2; return(true); }
// Constructors public ArgumentOutOfRangeException() : base(Locale.GetText("Argument is out of range.")) { HResult = Result; }
public static void Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length) { if (sourceArray == null) { throw new ArgumentNullException("sourceArray"); } if (destinationArray == null) { throw new ArgumentNullException("destinationArray"); } if (length < 0) { throw new ArgumentOutOfRangeException("length", Locale.GetText( "Value has to be >= 0.")); } ; if (sourceArray.Rank != destinationArray.Rank) { throw new RankException(SR.Rank_MultiDimNotSupported); } if (sourceIndex < 0) { throw new ArgumentOutOfRangeException("sourceIndex", Locale.GetText( "Value has to be >= 0.")); } ; if (destinationIndex < 0) { throw new ArgumentOutOfRangeException("destinationIndex", Locale.GetText( "Value has to be >= 0.")); } ; if (FastCopy(sourceArray, sourceIndex, destinationArray, destinationIndex, length)) { return; } int source_pos = sourceIndex - sourceArray.GetLowerBound(0); int dest_pos = destinationIndex - destinationArray.GetLowerBound(0); if (dest_pos < 0) { throw new ArgumentOutOfRangeException("destinationIndex", "Index was less than the array's lower bound in the first dimension."); } // re-ordered to avoid possible integer overflow if (source_pos > sourceArray.Length - length) { throw new ArgumentException("length"); } if (dest_pos > destinationArray.Length - length) { throw new ArgumentException("Destination array was not long enough. Check destIndex and length, and the array's lower bounds", nameof(destinationArray)); } Type src_type = sourceArray.GetType().GetElementType(); Type dst_type = destinationArray.GetType().GetElementType(); var dst_type_vt = dst_type.IsValueType; if (!Object.ReferenceEquals(sourceArray, destinationArray) || source_pos > dest_pos) { for (int i = 0; i < length; i++) { Object srcval = sourceArray.GetValueImpl(source_pos + i); if (srcval == null && dst_type_vt) { throw new InvalidCastException(); } try { destinationArray.SetValueImpl(srcval, dest_pos + i); } catch (ArgumentException) { throw CreateArrayTypeMismatchException(); } catch (InvalidCastException) { if (CanAssignArrayElement(src_type, dst_type)) { throw; } throw CreateArrayTypeMismatchException(); } } } else { for (int i = length - 1; i >= 0; i--) { Object srcval = sourceArray.GetValueImpl(source_pos + i); try { destinationArray.SetValueImpl(srcval, dest_pos + i); } catch (ArgumentException) { throw CreateArrayTypeMismatchException(); } catch { if (CanAssignArrayElement(src_type, dst_type)) { throw; } throw CreateArrayTypeMismatchException(); } } } }
// Constructors public TypeUnloadedException() : base(Locale.GetText("Cannot access an unloaded class.")) { }
static void ThrowAtPos(int pos) { throw new FormatException(String.Format(Locale.GetText("Invalid character at position {0}"), pos)); }