System.IConvertible.ToInt32(System.IFormatProvider)

Here are the examples of the csharp api System.IConvertible.ToInt32(System.IFormatProvider) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

138 Examples 7

19 Source : ExtensionMethods.cs
with MIT License
from Aiko-IT-Systems

public static string GetName<T>(this T e) where T : IConvertible
        {
            if (e is Enum)
            {
                var type = e.GetType();
                var values = Enum.GetValues(type);

                foreach (int val in values)
                {
                    if (val == e.ToInt32(CultureInfo.InvariantCulture))
                    {
                        var memInfo = type.GetMember(type.GetEnumName(val));

                        return memInfo[0]
                            .GetCustomAttributes(typeof(ChoiceNameAttribute), false)
                            .FirstOrDefault() is ChoiceNameAttribute nameAttribute ? nameAttribute.Name : type.GetEnumName(val);
                    }
                }
            }
            return null;
        }

19 Source : AopJsonReader.cs
with Apache License 2.0
from alipay

public IList GetListObjects(string listName, string itemName, Type type, DAopConvert convert)
        {
            IList listObjs = null;

            Object jsonObject = json[listName];


            IList jsonList = null;
            if (jsonObject is IList)
            {
                jsonList = jsonObject as IList;
            }
            else if (jsonObject is IDictionary)
            {
                IDictionary jsonMap = jsonObject as IDictionary;

                if (jsonMap != null && jsonMap.Count > 0)
                {

                    Object itemTmp = jsonMap[itemName];

                    if (itemTmp == null && listName != null)
                    {
                        itemTmp = jsonMap[listName.Substring(0, listName.Length - 1)];
                    }

                    if (itemTmp is IList)
                    {
                        jsonList = itemTmp as IList;
                    }

                }
            }

            if (jsonList != null && jsonList.Count > 0)
            {
                Type listType = typeof(List<>).MakeGenericType(new Type[] { type });
                listObjs = Activator.CreateInstance(listType) as IList;
                foreach (object item in jsonList)
                {
                    if (typeof(JObject).IsreplacedignableFrom(item.GetType())) // object
                    {
                        JObject subMap = item as JObject;
                        object subObj = convert(new AopJsonReader(subMap), type);
                        if (subObj != null)
                        {
                            listObjs.Add(subObj);
                        }
                    }
                    else if (typeof(IList).IsreplacedignableFrom(item.GetType())) // list/array
                    {
                        // TODO not support yet
                    }
                    else if (typeof(long).IsreplacedignableFrom(type))
                    {
                        JValue tmp = item as JValue;
                        if (tmp.Value != null)
                        {
                            listObjs.Add(((IConvertible)tmp).ToInt64(null));
                        }
                        else
                        {
                            listObjs.Add(null);
                        }
                    }
                    else if (typeof(int).IsreplacedignableFrom(type))
                    {
                        JValue tmp = item as JValue;
                        if (tmp.Value != null)
                        {
                            listObjs.Add(((IConvertible)tmp).ToInt32(null));
                        }
                        else
                        {
                            listObjs.Add(null);
                        }
                    }
                    else if (typeof(double).IsreplacedignableFrom(type))
                    {
                        JValue tmp = item as JValue;
                        if (tmp.Value != null)
                        {
                            listObjs.Add(((IConvertible)tmp).ToDouble(null));
                        }
                        else
                        {
                            listObjs.Add(null);
                        }
                    }
                    else if (typeof(bool).IsreplacedignableFrom(type))
                    {
                        JValue tmp = item as JValue;
                        if (tmp.Value != null)
                        {
                            listObjs.Add(((IConvertible)tmp).ToBoolean(null));
                        }
                        else
                        {
                            listObjs.Add(null);
                        }
                    }
                    else if (typeof(string).IsreplacedignableFrom(type))
                    {
                        JValue tmp = item as JValue;
                        if (tmp.Value != null)
                        {
                            listObjs.Add(((IConvertible)tmp).ToString(null));
                        }
                        else
                        {
                            listObjs.Add(null);
                        }
                    }
                    else
                    {
                        JValue tmp = item as JValue;
                        listObjs.Add(tmp.Value);
                    }
                }

            }

            return listObjs;
        }

19 Source : IDirect3DDevice9.cs
with MIT License
from amerkoleci

public void SetRenderState<T>(RenderState renderState, T value) where T : struct, IConvertible
        {
            if (!typeof(T).GetTypeInfo().IsEnum)
            {
                throw new ArgumentException("T must be an enum type", "value");
            }

            SetRenderState(renderState, value.ToInt32(CultureInfo.InvariantCulture));
        }

19 Source : EditorUtilitiesInternal.cs
with GNU Lesser General Public License v3.0
from ApexGameTools

internal static void EnumToIntField(Rect position, SerializedProperty property, Type enumType, GUIContent label)
        {
            var currentValue = property.intValue;
            var curEnumVal = (Enum)Enum.ToObject(enumType, property.intValue);

            var newValRaw = EditorGUI.EnumMaskField(position, label, curEnumVal) as IConvertible;

            var newVal = newValRaw.ToInt32(null);
            if (newVal != currentValue)
            {
                property.intValue = newVal;
            }
        }

19 Source : SettingRecord.cs
with MIT License
from b-editor

private static void WriteSerializable(Utf8JsonWriter writer, string name, object obj)
        {
            if (obj is bool @bool) writer.WriteBoolean(name, @bool);
            else if (obj is byte @byte) writer.WriteNumber(name, @byte);
            else if (obj is sbyte @sbyte) writer.WriteNumber(name, @sbyte);
            else if (obj is short @short) writer.WriteNumber(name, @short);
            else if (obj is ushort @ushort) writer.WriteNumber(name, @ushort);
            else if (obj is int @int) writer.WriteNumber(name, @int);
            else if (obj is uint @uint) writer.WriteNumber(name, @uint);
            else if (obj is long @long) writer.WriteNumber(name, @long);
            else if (obj is ulong @ulong) writer.WriteNumber(name, @ulong);
            else if (obj is char @char) writer.WriteString(name, @char.ToString());
            else if (obj is double @double) writer.WriteNumber(name, @double);
            else if (obj is float @float) writer.WriteNumber(name, @float);
            else if (obj is string @string) writer.WriteString(name, @string);
            else if (obj is DateTime dateTime) writer.WriteString(name, dateTime);
            else if (obj is DateTimeOffset dateTimeOffset) writer.WriteString(name, dateTimeOffset);
            else if (obj is Guid guid) writer.WriteString(name, guid);
            else if (obj is Enum @enum) writer.WriteNumber(name, ((IConvertible)@enum).ToInt32(CultureInfo.InvariantCulture));
        }

19 Source : SmartEvent.cs
with The Unlicense
from BAndysc

public static string? GetDescription<T>(this T e) where T : IConvertible
        {
            if (e is Enum)
            {
                Type type = e.GetType();
                Array values = System.Enum.GetValues(type);

                foreach (int val in values)
                {
                    if (val == e.ToInt32(CultureInfo.InvariantCulture))
                    {
                        var memInfo = type.GetMember(type.GetEnumName(val)!);
                        var descriptionAttribute = memInfo[0]
                            .GetCustomAttributes(typeof(DescriptionAttribute), false)
                            .FirstOrDefault() as DescriptionAttribute;

                        if (descriptionAttribute != null)
                        {
                            return descriptionAttribute.Description;
                        }
                    }
                }
            }
            return null; // could also return string.Empty
        }

19 Source : VBExtension.cs
with BSD 2-Clause "Simplified" License
from bhoogter

public static int CInt(object A) { return (A is System.IConvertible) ? ((System.IConvertible)A).ToInt32(null) : 0; }

19 Source : CompressedString.cs
with MIT License
from circles-arrows

int IConvertible.ToInt32(IFormatProvider? provider)
        {
            return ((IConvertible)Value).ToInt32(provider);
        }

19 Source : JsonConvert.cs
with MIT License
from CragonGame

public static string ToString(object value)
    {
      if (value == null)
        return Null;

      IConvertible convertible = value as IConvertible;

      if (convertible != null)
      {
        switch (convertible.GetTypeCode())
        {
          case TypeCode.String:
            return ToString(convertible.ToString(CultureInfo.InvariantCulture));
          case TypeCode.Char:
            return ToString(convertible.ToChar(CultureInfo.InvariantCulture));
          case TypeCode.Boolean:
            return ToString(convertible.ToBoolean(CultureInfo.InvariantCulture));
          case TypeCode.SByte:
            return ToString(convertible.ToSByte(CultureInfo.InvariantCulture));
          case TypeCode.Int16:
            return ToString(convertible.ToInt16(CultureInfo.InvariantCulture));
          case TypeCode.UInt16:
            return ToString(convertible.ToUInt16(CultureInfo.InvariantCulture));
          case TypeCode.Int32:
            return ToString(convertible.ToInt32(CultureInfo.InvariantCulture));
          case TypeCode.Byte:
            return ToString(convertible.ToByte(CultureInfo.InvariantCulture));
          case TypeCode.UInt32:
            return ToString(convertible.ToUInt32(CultureInfo.InvariantCulture));
          case TypeCode.Int64:
            return ToString(convertible.ToInt64(CultureInfo.InvariantCulture));
          case TypeCode.UInt64:
            return ToString(convertible.ToUInt64(CultureInfo.InvariantCulture));
          case TypeCode.Single:
            return ToString(convertible.ToSingle(CultureInfo.InvariantCulture));
          case TypeCode.Double:
            return ToString(convertible.ToDouble(CultureInfo.InvariantCulture));
          case TypeCode.DateTime:
            return ToString(convertible.ToDateTime(CultureInfo.InvariantCulture));
          case TypeCode.Decimal:
            return ToString(convertible.ToDecimal(CultureInfo.InvariantCulture));
          case TypeCode.DBNull:
            return Null;
        }
      }
      else if (value is DateTimeOffset)
      {
        return ToString((DateTimeOffset)value);
      }
      else if (value is Guid)
      {
        return ToString((Guid) value);
      }
      else if (value is Uri)
      {
        return ToString((Uri) value);
      }
      else if (value is TimeSpan)
      {
        return ToString((TimeSpan) value);
      }

      throw new ArgumentException("Unsupported type: {0}. Use the JsonSerializer clreplaced to get the object's JSON representation.".FormatWith(CultureInfo.InvariantCulture, value.GetType()));
    }

19 Source : JsonWriter.cs
with MIT License
from CragonGame

public virtual void WriteValue(object value)
    {
      if (value == null)
      {
        WriteNull();
        return;
      }
      else if (value is IConvertible)
      {
        IConvertible convertible = value as IConvertible;

        switch (convertible.GetTypeCode())
        {
          case TypeCode.String:
            WriteValue(convertible.ToString(CultureInfo.InvariantCulture));
            return;
          case TypeCode.Char:
            WriteValue(convertible.ToChar(CultureInfo.InvariantCulture));
            return;
          case TypeCode.Boolean:
            WriteValue(convertible.ToBoolean(CultureInfo.InvariantCulture));
            return;
          case TypeCode.SByte:
            WriteValue(convertible.ToSByte(CultureInfo.InvariantCulture));
            return;
          case TypeCode.Int16:
            WriteValue(convertible.ToInt16(CultureInfo.InvariantCulture));
            return;
          case TypeCode.UInt16:
            WriteValue(convertible.ToUInt16(CultureInfo.InvariantCulture));
            return;
          case TypeCode.Int32:
            WriteValue(convertible.ToInt32(CultureInfo.InvariantCulture));
            return;
          case TypeCode.Byte:
            WriteValue(convertible.ToByte(CultureInfo.InvariantCulture));
            return;
          case TypeCode.UInt32:
            WriteValue(convertible.ToUInt32(CultureInfo.InvariantCulture));
            return;
          case TypeCode.Int64:
            WriteValue(convertible.ToInt64(CultureInfo.InvariantCulture));
            return;
          case TypeCode.UInt64:
            WriteValue(convertible.ToUInt64(CultureInfo.InvariantCulture));
            return;
          case TypeCode.Single:
            WriteValue(convertible.ToSingle(CultureInfo.InvariantCulture));
            return;
          case TypeCode.Double:
            WriteValue(convertible.ToDouble(CultureInfo.InvariantCulture));
            return;
          case TypeCode.DateTime:
            WriteValue(convertible.ToDateTime(CultureInfo.InvariantCulture));
            return;
          case TypeCode.Decimal:
            WriteValue(convertible.ToDecimal(CultureInfo.InvariantCulture));
            return;
          case TypeCode.DBNull:
            WriteNull();
            return;
        }
      }
      else if (value is DateTimeOffset)
      {
        WriteValue((DateTimeOffset)value);
        return;
      }
      else if (value is byte[])
      {
        WriteValue((byte[])value);
        return;
      }
      else if (value is Guid)
      {
        WriteValue((Guid)value);
        return;
      }
      else if (value is Uri)
      {
        WriteValue((Uri)value);
        return;
      }
      else if (value is TimeSpan)
      {
        WriteValue((TimeSpan)value);
        return;
      }

      throw new ArgumentException("Unsupported type: {0}. Use the JsonSerializer clreplaced to get the object's JSON representation.".FormatWith(CultureInfo.InvariantCulture, value.GetType()));
    }

19 Source : SYSTEMTIME.cs
with MIT License
from dahall

int IConvertible.ToInt32(IFormatProvider provider) => ((IConvertible)(DateTime)this).ToInt32(provider);

19 Source : StructMarshaler.cs
with MIT License
from dahall

public static SafeCoTaskMemHandle Serialize(object structure)
		{
			if (structure is null) return SafeCoTaskMemHandle.Null;

			// If this doesn't have our attribute, use standard marshaling.
			var attr = structure.GetType().GetCustomAttributes<MarshaledStructAttribute>().FirstOrDefault();
			if (attr is null)
				return SafeCoTaskMemHandle.CreateFromStructure(structure);

			if (!attr.Bias.IsFlagSet(MarshalBias.ToNative))
				throw new ArgumentException("The supplied object is not configured to be marshaled to native memory. See the MarshaledStructAttribute.Bias value.");

			// Process each field and write it into memory
			var allocator = new SafeCoTaskMemHandle(attr.Size > 0 ? attr.Size : 256);
			using (var stream = new NativeMemoryStream(allocator) { CharSet = attr.CharSet })
			{
				foreach (var fi in structure.GetType().GetFields(stdBind))
				{
					var val = fi.GetValue(structure);
					var fattr = fi.GetCustomAttributes<MarshalDirectiveAttribute>().FirstOrDefault();

					// Get size info
					var fsize = int.MaxValue;
					if (fattr?.SizeConst > 0)
						fsize = fattr.SizeConst;
					else if (fattr?.SizeField != null)
					{
						var szFieldVal = structure.GetType().GetField(fattr.SizeField, stdBind)?.GetValue(structure);
						if (szFieldVal != null && szFieldVal is IConvertible c && c.ToInt32(null) > 0)
							fsize = c.ToInt32(null);
					}

					// Handle cases where directive is omitted or MarshalDirectiveAttibute not set.
					var dir = fattr?.Value ?? MarshalDirective.Normal;
					if (dir == MarshalDirective.Normal)
					{
						if (val is string)
							dir = fattr?.SizeConst > 0 ? MarshalDirective.AsArray : MarshalDirective.AsReference;
						else if (fattr?.AlternateType != null)
							dir = MarshalDirective.AsAlternateType;
						else if (val is IEnumerable)
							dir = val.GetType().FindElementType() == typeof(string) ? MarshalDirective.AsRefArray : MarshalDirective.AsArray;
					}

					switch (dir)
					{
						case MarshalDirective.Normal:
							stream.WriteObject(val);
							break;
						case MarshalDirective.AsReference:
							stream.WriteReferenceObject(val);
							break;
						case MarshalDirective.AsArray:
							if (val is string s)
							{
								if (s.Length >= fsize)
									s = s.Substring(0, fsize - 1);
								stream.Write(s, fattr.CharSet != CharSet.None && fattr.CharSet != attr.CharSet ? fattr.CharSet : attr.CharSet);
							}
							else if (val is IEnumerable ie)
							{
								var max = fsize;
								foreach (var oval in ie)
								{
									if (max-- > 0)
										stream.WriteObject(oval);
								}
							}
							else
								throw new InvalidOperationException("The only types supported by MarshalDirective.AsArray are string and IEnumerable.");
							break;
						case MarshalDirective.AsRefArray:
							if (val is IEnumerable ire)
							{
								var max = fsize;
								foreach (var oval in ire)
								{
									if (max-- > 0)
										stream.WriteReferenceObject(oval);
								}
							}
							else
								throw new InvalidOperationException("The only type supported by MarshalDirective.AsRefArray is IEnumerable.");
							break;
						case MarshalDirective.AsAlternateType:
							stream.WriteObject(Convert.ChangeType(val, fattr?.AlternateType ?? throw new InvalidOperationException("The MarshalDirectiveAttribute.AlternateType value must be set when using MarshalDirective.AsAlternateType.")));
							break;
						case MarshalDirective.AsNullTermStringArray:
							if (!(val is IEnumerable<string> ies)) throw new InvalidOperationException("The only type supported by MarshalDirective.AsNullTermStringArray is IEnumerable<string>.");
							stream.Write(ies);
							break;
						default:
							break;
					}
				}
				stream.Flush();
				allocator.Size = (int)stream.Length;
			}
			return allocator;
		}

19 Source : BOOLEAN.cs
with MIT License
from dahall

int IConvertible.ToInt32(IFormatProvider provider) => ((IConvertible)Value).ToInt32(provider);

19 Source : FunctionHelper.cs
with MIT License
from dahall

public static Win32Error CallMethodWithTypedBuf<TOut, TSize>(SizeFunc<TSize> getSize, PtrFunc<TSize> method, out TOut result, Func<IntPtr, TSize, TOut> outConverter = null, Win32Error? bufErr = null) where TSize : struct, IConvertible
		{
			TSize sz = default;
			result = default;
			var err = (getSize ?? GetSize)(ref sz);
			if (err.Failed && (bufErr == null || bufErr.Value != err) && !buffErrs.Contains(err)) return err;
			using (var buf = new SafeHGlobalHandle(sz.ToInt32(null)))
			{
				err = method(buf.DangerousGetHandle(), ref sz);
				if (err.Succeeded)
					result = (outConverter ?? Conv)(buf.DangerousGetHandle(), sz);
				return err;
			}

			Win32Error GetSize(ref TSize sz1) => method(IntPtr.Zero, ref sz1);

			static TOut Conv(IntPtr p, TSize s) => p == IntPtr.Zero ? default : p.Convert<TOut>(Convert.ToUInt32(s));
		}

19 Source : Win32Error.cs
with MIT License
from dahall

int IConvertible.ToInt32(IFormatProvider provider) => ((IConvertible)value).ToInt32(provider);

19 Source : FunctionHelper.cs
with MIT License
from dahall

public static TRet CallMethodWithStrBuf<TSize, TRet>(SBFunc<TSize, TRet> method, out string result, Func<TSize, TRet, bool> gotGoodSize = null) where TSize : struct, IConvertible
		{
			TSize sz = default;
			var ret0 = method(null, ref sz);
			if (!(gotGoodSize ?? IsNotDef)(sz, ret0))
			{
				result = null;
				return ret0;
			}
			var len = sz.ToInt32(null) + 1;
			var sb = new StringBuilder(len, len);
			sz = (TSize)Convert.ChangeType(len, typeof(TSize));
			var ret = method(sb, ref sz);
			result = sb.ToString();
			return ret;

			bool IsNotDef(TSize _sz, TRet _ret) => !_sz.Equals(default(TSize));
		}

19 Source : FunctionHelper.cs
with MIT License
from dahall

public static TRet CallMethodWithStrBuf<TSize, TRet>(Func<StringBuilder, TSize, TRet> method, TSize bufSz, out string result) where TSize : IConvertible
		{
			var len = bufSz.ToInt32(null) + 1;
			var sb = new StringBuilder(len, len);
			var ret = method(sb, bufSz);
			result = sb.ToString();
			return ret;
		}

19 Source : NTStatusTests.cs
with MIT License
from dahall

[Test()]
		public void IConvTest()
		{
			NTStatus nts = NTStatus.STATUS_ACCESS_DENIED;
			var c = (IConvertible)nts;
			var cv = (IConvertible)NTStatus.STATUS_ACCESS_DENIED;
			var f = System.Globalization.CultureInfo.CurrentCulture.NumberFormat;
			replacedert.That(c.GetTypeCode(), Is.EqualTo(cv.GetTypeCode()));
			replacedert.That(() => c.ToChar(f), Throws.Exception);
			replacedert.That(() => c.ToSByte(f), Throws.Exception);
			replacedert.That(() => c.ToByte(f), Throws.Exception);
			replacedert.That(() => c.ToInt16(f), Throws.Exception);
			replacedert.That(() => c.ToUInt16(f), Throws.Exception);
			replacedert.That(c.ToInt32(f), Is.EqualTo(cv.ToInt32(f)));
			replacedert.That(c.ToUInt32(f), Is.EqualTo((uint)nts));
			replacedert.That(c.ToInt64(f), Is.EqualTo(cv.ToInt64(f)));
			replacedert.That(c.ToUInt64(f), Is.EqualTo((ulong)(uint)nts));
			replacedert.That(c.ToSingle(f), Is.EqualTo(cv.ToSingle(f)));
			replacedert.That(c.ToDouble(f), Is.EqualTo(cv.ToDouble(f)));
			replacedert.That(c.ToDecimal(f), Is.EqualTo(cv.ToDecimal(f)));
			replacedert.That(c.ToBoolean(f), Is.EqualTo(nts.Succeeded));
			replacedert.That(() => c.ToDateTime(f), Throws.Exception);
			replacedert.That(c.ToString(f), Does.StartWith("STATUS_ACCESS_DENIED"));
			replacedert.That(c.ToType(typeof(int), f), Is.EqualTo(cv.ToType(typeof(int), f)));
		}

19 Source : Win32ErrorTests.cs
with MIT License
from dahall

[Test()]
		public void IConvTest()
		{
			Win32Error err = Win32Error.ERROR_ACCESS_DENIED;
			var c = (IConvertible)err;
			var cv = (IConvertible)Win32Error.ERROR_ACCESS_DENIED;
			var f = System.Globalization.CultureInfo.CurrentCulture.NumberFormat;
			replacedert.That(c.GetTypeCode(), Is.EqualTo(cv.GetTypeCode()));
			replacedert.That(() => c.ToChar(f), Throws.Exception);
			replacedert.That(c.ToSByte(f), Is.EqualTo(cv.ToSByte(f)));
			replacedert.That(c.ToByte(f), Is.EqualTo(cv.ToByte(f)));
			replacedert.That(c.ToInt16(f), Is.EqualTo(cv.ToInt16(f)));
			replacedert.That(c.ToUInt16(f), Is.EqualTo(cv.ToUInt16(f)));
			replacedert.That(c.ToInt32(f), Is.EqualTo(cv.ToInt32(f)));
			replacedert.That(c.ToUInt32(f), Is.EqualTo(cv.ToUInt32(f)));
			replacedert.That(c.ToInt64(f), Is.EqualTo(cv.ToInt64(f)));
			replacedert.That(c.ToUInt64(f), Is.EqualTo(cv.ToUInt64(f)));
			replacedert.That(c.ToSingle(f), Is.EqualTo(cv.ToSingle(f)));
			replacedert.That(c.ToDouble(f), Is.EqualTo(cv.ToDouble(f)));
			replacedert.That(c.ToDecimal(f), Is.EqualTo(cv.ToDecimal(f)));
			replacedert.That(() => c.ToDateTime(f), Throws.Exception);
			replacedert.That(c.ToString(f), Does.StartWith("ERROR_ACCESS_DENIED"));
			replacedert.That(c.ToType(typeof(uint), f), Is.EqualTo(cv.ToType(typeof(uint), f)));
		}

19 Source : HRESULTTests.cs
with MIT License
from dahall

[Test()]
		public void IConvTest()
		{
			HRESULT hr = HRESULT.E_ACCESSDENIED;
			var c = (IConvertible) hr;
			var cv = (IConvertible)HRESULT.E_ACCESSDENIED;
			var f = System.Globalization.CultureInfo.CurrentCulture.NumberFormat;
			replacedert.That(c.GetTypeCode(), Is.EqualTo(cv.GetTypeCode()));
			replacedert.That(() => c.ToChar(f), Throws.Exception);
			replacedert.That(() => c.ToSByte(f), Throws.Exception);
			replacedert.That(() => c.ToByte(f), Throws.Exception);
			replacedert.That(() => c.ToInt16(f), Throws.Exception);
			replacedert.That(() => c.ToUInt16(f), Throws.Exception);
			replacedert.That(c.ToUInt32(f), Is.EqualTo(unchecked((uint)HRESULT.E_ACCESSDENIED)));
			replacedert.That(c.ToInt32(f), Is.EqualTo(cv.ToInt32(f)));
			replacedert.That(c.ToInt64(f), Is.EqualTo(cv.ToInt64(f)));
			replacedert.That(c.ToUInt64(f), Is.EqualTo((ulong)unchecked((uint)HRESULT.E_ACCESSDENIED)));
			replacedert.That(c.ToSingle(f), Is.EqualTo(cv.ToSingle(f)));
			replacedert.That(c.ToDouble(f), Is.EqualTo(cv.ToDouble(f)));
			replacedert.That(c.ToDecimal(f), Is.EqualTo(cv.ToDecimal(f)));
			replacedert.That(() => c.ToDateTime(f), Throws.Exception);
			replacedert.That(c.ToString(f), Does.StartWith("E_ACCESSDENIED"));
			replacedert.That(c.ToType(typeof(int), f), Is.EqualTo(cv.ToType(typeof(int), f)));
		}

19 Source : AseDataReader.cs
with Apache License 2.0
from DataAction

public override int GetInt32(int i)
        {
            return GetPrimitive(i, (value, provider) => value.ToInt32(provider));
        }

19 Source : SqlNative.cs
with MIT License
from DataObjects-NET

int IConvertible.ToInt32(IFormatProvider provider)
    {
      return ((IConvertible) Value).ToInt32(provider);
    }

19 Source : XamarinFormsMarkupExtensions.cs
with MIT License
from davidortinau

static int ToInt(this IConvertible convertible) => convertible?.ToInt32(System.Globalization.CultureInfo.InvariantCulture) ?? 0;

19 Source : XamarinFormsMarkupExtensions.cs
with MIT License
from davidortinau

public static ColumnDefinitionCollection Define<TEnum>(params (TEnum name, GridLength width)[] cols) where TEnum : IConvertible
            {
                var columnDefinitions = new ColumnDefinitionCollection();
                for (int i = 0; i < cols.Length; i++)
                {
                    if (i != cols[i].name.ToInt32(System.Globalization.CultureInfo.InvariantCulture)) throw new ArgumentException($"Value of column name { cols[i].name } is not { i }. Columns must be defined with enum names whose values form the sequence 0,1,2,...");
                    columnDefinitions.Add(new ColumnDefinition { Width = cols[i].width });
                }
                return columnDefinitions;
            }

19 Source : XamarinFormsMarkupExtensions.cs
with MIT License
from davidortinau

public static RowDefinitionCollection Define<TEnum>(params (TEnum name, GridLength height)[] rows) where TEnum : IConvertible
            {
                var rowDefinitions = new RowDefinitionCollection();
                for (int i = 0; i < rows.Length; i++)
                {
                    if (i != rows[i].name.ToInt32(System.Globalization.CultureInfo.InvariantCulture)) throw new ArgumentException($"Value of row name { rows[i].name } is not { i }. Rows must be defined with enum names whose values form the sequence 0,1,2,...");
                    rowDefinitions.Add(new RowDefinition { Height = rows[i].height });
                }
                return rowDefinitions;
            }

19 Source : AbapStringValue.cs
with MIT License
from dbosoft

public int ToInt32(IFormatProvider provider)
        {
            return ((IConvertible) Value).ToInt32(CultureInfo.InvariantCulture);
        }

19 Source : AbapIntValue.cs
with MIT License
from dbosoft

public int ToInt32(IFormatProvider provider)
        {
            return ((IConvertible) Value).ToInt32(provider);
        }

19 Source : SqlBoolean.cs
with Apache License 2.0
from deveel

sbyte IConvertible.ToSByte(IFormatProvider provider) {
			return (sbyte) (this as IConvertible).ToInt32(provider);
		}

19 Source : SqlBoolean.cs
with Apache License 2.0
from deveel

short IConvertible.ToInt16(IFormatProvider provider) {
			return (short) (this as IConvertible).ToInt32(provider);
		}

19 Source : SqlBoolean.cs
with Apache License 2.0
from deveel

ushort IConvertible.ToUInt16(IFormatProvider provider) {
			return (ushort) (this as IConvertible).ToInt32(provider);
		}

19 Source : SqlBoolean.cs
with Apache License 2.0
from deveel

uint IConvertible.ToUInt32(IFormatProvider provider) {
			return (uint) (this as IConvertible).ToInt32(provider);
		}

19 Source : SqlBoolean.cs
with Apache License 2.0
from deveel

long IConvertible.ToInt64(IFormatProvider provider) {
			return (this as IConvertible).ToInt32(provider);
		}

19 Source : SqlBoolean.cs
with Apache License 2.0
from deveel

float IConvertible.ToSingle(IFormatProvider provider) {
			return (this as IConvertible).ToInt32(provider);
		}

19 Source : SqlBoolean.cs
with Apache License 2.0
from deveel

double IConvertible.ToDouble(IFormatProvider provider) {
			return (this as IConvertible).ToInt32(provider);
		}

19 Source : SqlBoolean.cs
with Apache License 2.0
from deveel

decimal IConvertible.ToDecimal(IFormatProvider provider) {
			return (this as IConvertible).ToInt32(provider);
		}

19 Source : _Int32Enum_T.cs
with MIT License
from DevZest

private static Int32? PerformConvert(T? value)
        {
            if (!value.HasValue)
                return null;
            return value.Value.ToInt32(null);
        }

19 Source : EnumExtensions.cs
with MIT License
from discord-csharp

public static EventId ToEventId<TEnum>(
                    this TEnum @event)
                where TEnum : struct, IConvertible
            => new EventId(
                @event.ToInt32(null),
                @event.ToString());

19 Source : OracleDataReader.cs
with MIT License
from ericmend

public
        override
        int GetInt32(int i)
        {
            IConvertible c = (IConvertible)GetValue(i);
            return c.ToInt32(CultureInfo.CurrentCulture);
        }

19 Source : ExpressionExtensions.cs
with MIT License
from ExRam

public static GremlinExpression? TryToGremlinExpression(this Expression body, IGraphModel model)
        {
            var maybeExpression = body.TryToGremlinExpressionImpl(model);

            if (maybeExpression is { } expression)
            {
                if (expression.Left.Expression is MethodCallExpression leftMethodCallExpression)
                {
                    if (expression.LeftWellKnownMember == WellKnownMember.ComparableCompareTo && expression.Right.GetValue() is IConvertible convertible)
                    {
                        var maybeComparison = default(int?);

                        try
                        {
                            maybeComparison = convertible.ToInt32(CultureInfo.InvariantCulture);
                        }
                        catch (FormatException)
                        {
                            
                        }

                        if (maybeComparison is { } comparison)
                        {
                            if (expression.Semantics is ObjectExpressionSemantics objectExpressionSemantics)
                            {
                                var transformed = objectExpressionSemantics.TransformCompareTo(comparison);

                                return transformed switch
                                {
                                    TrueExpressionSemantics => GremlinExpression.True,
                                    FalseExpressionSemantics => GremlinExpression.False,
                                    _ => new GremlinExpression(
                                        ExpressionFragment.Create(leftMethodCallExpression.Object!, model), default,
                                        transformed,
                                        ExpressionFragment.Create(leftMethodCallExpression.Arguments[0], model))
                                };
                            }
                        }
                    }
                }
                else if (expression.Left.Expression is UnaryExpression unaryExpression)
                {
                    if (unaryExpression.NodeType == ExpressionType.ArrayLength)
                    {
                        return new GremlinExpression(
                            ExpressionFragment.Create(unaryExpression.Operand, model),
                            WellKnownMember.ArrayLength,
                            expression.Semantics,
                            expression.Right);
                    }
                }
                else if (expression.Left.Expression is MemberExpression {Expression: {} memberExpressionExpression} && expression.LeftWellKnownMember != null)
                {
                    return new GremlinExpression(
                        ExpressionFragment.Create(memberExpressionExpression, model),
                        expression.LeftWellKnownMember,
                        expression.Semantics,
                        expression.Right);
                }
            }

19 Source : DataTableProcessor.EnumProcessor.cs
with MIT License
from FingerCaster

public override int Parse(string value)
            {
                bool isInt = int.TryParse(value, out int v);
                if (isInt)
                {
                    return int.Parse(value);
                }

                bool isString = EnumParse(value, out T v1);
                if (isString)
                {
                    return v1.ToInt32(null);
                }

                throw new Exception($"Value:{value} is not {typeof(T)}!");
            }

19 Source : DataTableExtension.cs
with MIT License
from FingerCaster

public static T EnumParse<T>(string value) where T : struct, IConvertible
        {
            if (!typeof(T).IsEnum) throw new ArgumentException("T must be an enumerated type");
            if (string.IsNullOrEmpty(value))
            {
                throw new ArgumentException("enum stringValue can not empty or null");
            }
            
            bool isInt = int.TryParse(value, out int enumInt);
            if (isInt)
            {
                foreach (T item in Enum.GetValues(typeof(T)))
                {
                    if (item.ToInt32(null) != enumInt) continue;
                    return item;
                }
            }
            else
            {
                foreach (T item in Enum.GetValues(typeof(T)))
                {
                    if (!item.ToString().ToLowerInvariant().Equals(value.Trim().ToLowerInvariant())) continue;
                    return item;
                }
            }
            
            throw new ArgumentException($"EnumStringValue :{value} is can not parse to {typeof(T).FullName}");

        }

19 Source : GenericValue.cs
with GNU General Public License v3.0
from FreeDemon2020

public int ToInt(IFormatProvider culture)
        {
            object rawValue = this.GetRawValue<object>();
            IConvertible convertible;
            if (!(rawValue is string) && (convertible = (rawValue as IConvertible)) != null)
            {
                return convertible.ToInt32(culture);
            }
            return int.Parse(this.ToString(culture), NumberStyles.None, culture);
        }

19 Source : EnumHelper.cs
with MIT License
from FuzzySlipper

public static string GetDescription<T>(T en) where T : struct, IConvertible {
        string value;
        return GetEnumDescrList<T>().TryGetValue(en.ToInt32(CultureInfo.InvariantCulture), out value) ? value : "";
    }

19 Source : EnumHelper.cs
with MIT License
from FuzzySlipper

public static string ToDescription<T>(this T en) where T : struct, IConvertible {
        string value;
        return GetEnumDescrList<T>().TryGetValue(en.ToInt32(CultureInfo.InvariantCulture), out value) ? value : "";
    }

19 Source : Calculator.cs
with MIT License
from gimlichael

private static T CalculateCore<T>(T x, T y, replacedignmentOperator replacedignment) where T : struct, IConvertible
        {
            var provider = CultureInfo.InvariantCulture;
            var replacedignmentCode = x.GetTypeCode();
            switch (replacedignmentCode)
            {
                case TypeCode.Byte:
                    switch (replacedignment)
                    {
                        case replacedignmentOperator.Addition:
                            return Decorator.Enclose<object>(x.ToByte(provider) + y.ToByte(provider)).ChangeType<T>();
                        case replacedignmentOperator.And:
                            return Decorator.Enclose<object>(x.ToByte(provider) & y.ToByte(provider)).ChangeType<T>();
                        case replacedignmentOperator.replacedign:
                            return y;
                        case replacedignmentOperator.Division:
                            return Decorator.Enclose<object>(x.ToByte(provider) / y.ToByte(provider)).ChangeType<T>();
                        case replacedignmentOperator.ExclusiveOr:
                            return Decorator.Enclose<object>(x.ToByte(provider) ^ y.ToByte(provider)).ChangeType<T>();
                        case replacedignmentOperator.LeftShift:
                            return Decorator.Enclose<object>(x.ToByte(provider) << y.ToByte(provider)).ChangeType<T>();
                        case replacedignmentOperator.Multiplication:
                            return Decorator.Enclose<object>(x.ToByte(provider) * y.ToByte(provider)).ChangeType<T>();
                        case replacedignmentOperator.Or:
                            return Decorator.Enclose<object>(x.ToByte(provider) | y.ToByte(provider)).ChangeType<T>();
                        case replacedignmentOperator.Remainder:
                            return Decorator.Enclose<object>(x.ToByte(provider) % y.ToByte(provider)).ChangeType<T>();
                        case replacedignmentOperator.RightShift:
                            return Decorator.Enclose<object>(x.ToByte(provider) >> y.ToByte(provider)).ChangeType<T>();
                        case replacedignmentOperator.Subtraction:
                            return Decorator.Enclose<object>(x.ToByte(provider) - y.ToByte(provider)).ChangeType<T>();
                        default:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment));
                    }
                case TypeCode.Decimal:
                    switch (replacedignment)
                    {
                        case replacedignmentOperator.Addition:
                            return Decorator.Enclose<object>(x.ToDecimal(provider) + y.ToDecimal(provider)).ChangeType<T>();
                        case replacedignmentOperator.And:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x &= y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.replacedign:
                            return y;
                        case replacedignmentOperator.Division:
                            return Decorator.Enclose<object>(x.ToDecimal(provider) / y.ToDecimal(provider)).ChangeType<T>();
                        case replacedignmentOperator.ExclusiveOr:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x ^= y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.LeftShift:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x << y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.Multiplication:
                            return Decorator.Enclose<object>(x.ToDecimal(provider) * y.ToDecimal(provider)).ChangeType<T>();
                        case replacedignmentOperator.Or:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x |= y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.Remainder:
                            return Decorator.Enclose<object>(x.ToDecimal(provider) % y.ToDecimal(provider)).ChangeType<T>();
                        case replacedignmentOperator.RightShift:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x >> y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.Subtraction:
                            return Decorator.Enclose<object>(x.ToDecimal(provider) - y.ToDecimal(provider)).ChangeType<T>();
                        default:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment));
                    }
                case TypeCode.Double:
                    switch (replacedignment)
                    {
                        case replacedignmentOperator.Addition:
                            return Decorator.Enclose<object>(x.ToDouble(provider) + y.ToDouble(provider)).ChangeType<T>();
                        case replacedignmentOperator.And:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x &= y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.replacedign:
                            return y;
                        case replacedignmentOperator.Division:
                            return Decorator.Enclose<object>(x.ToDouble(provider) / y.ToDouble(provider)).ChangeType<T>();
                        case replacedignmentOperator.ExclusiveOr:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x ^= y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.LeftShift:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x << y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.Multiplication:
                            return Decorator.Enclose<object>(x.ToDouble(provider) * y.ToDouble(provider)).ChangeType<T>();
                        case replacedignmentOperator.Or:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x |= y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.Remainder:
                            return Decorator.Enclose<object>(x.ToDouble(provider) % y.ToDouble(provider)).ChangeType<T>();
                        case replacedignmentOperator.RightShift:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x >> y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.Subtraction:
                            return Decorator.Enclose<object>(x.ToDouble(provider) - y.ToDouble(provider)).ChangeType<T>();
                        default:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment));
                    }
                case TypeCode.Int16:
                    switch (replacedignment)
                    {
                        case replacedignmentOperator.Addition:
                            return Decorator.Enclose<object>(x.ToInt16(provider) + y.ToInt16(provider)).ChangeType<T>();
                        case replacedignmentOperator.And:
                            return Decorator.Enclose<object>(x.ToInt16(provider) & y.ToInt16(provider)).ChangeType<T>();
                        case replacedignmentOperator.replacedign:
                            return y;
                        case replacedignmentOperator.Division:
                            return Decorator.Enclose<object>(x.ToInt16(provider) / y.ToInt16(provider)).ChangeType<T>();
                        case replacedignmentOperator.ExclusiveOr:
                            return Decorator.Enclose<object>(x.ToInt16(provider) ^ y.ToInt16(provider)).ChangeType<T>();
                        case replacedignmentOperator.LeftShift:
                            return Decorator.Enclose<object>(x.ToInt16(provider) << y.ToInt16(provider)).ChangeType<T>();
                        case replacedignmentOperator.Multiplication:
                            return Decorator.Enclose<object>(x.ToInt16(provider) * y.ToInt16(provider)).ChangeType<T>();
                        case replacedignmentOperator.Or:
                            return Decorator.Enclose<object>(x.ToInt16(provider) | y.ToInt16(provider)).ChangeType<T>();
                        case replacedignmentOperator.Remainder:
                            return Decorator.Enclose<object>(x.ToInt16(provider) % y.ToInt16(provider)).ChangeType<T>();
                        case replacedignmentOperator.RightShift:
                            return Decorator.Enclose<object>(x.ToInt16(provider) >> y.ToInt16(provider)).ChangeType<T>();
                        case replacedignmentOperator.Subtraction:
                            return Decorator.Enclose<object>(x.ToInt16(provider) - y.ToInt16(provider)).ChangeType<T>();
                        default:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment));
                    }
                case TypeCode.Int32:
                    switch (replacedignment)
                    {
                        case replacedignmentOperator.Addition:
                            return Decorator.Enclose<object>(x.ToInt32(provider) + y.ToInt32(provider)).ChangeType<T>();
                        case replacedignmentOperator.And:
                            return Decorator.Enclose<object>(x.ToInt32(provider) & y.ToInt32(provider)).ChangeType<T>();
                        case replacedignmentOperator.replacedign:
                            return y;
                        case replacedignmentOperator.Division:
                            return Decorator.Enclose<object>(x.ToInt32(provider) / y.ToInt32(provider)).ChangeType<T>();
                        case replacedignmentOperator.ExclusiveOr:
                            return Decorator.Enclose<object>(x.ToInt32(provider) ^ y.ToInt32(provider)).ChangeType<T>();
                        case replacedignmentOperator.LeftShift:
                            return Decorator.Enclose<object>(x.ToInt32(provider) << y.ToInt32(provider)).ChangeType<T>();
                        case replacedignmentOperator.Multiplication:
                            return Decorator.Enclose<object>(x.ToInt32(provider) * y.ToInt32(provider)).ChangeType<T>();
                        case replacedignmentOperator.Or:
                            return Decorator.Enclose<object>(x.ToInt32(provider) | y.ToInt32(provider)).ChangeType<T>();
                        case replacedignmentOperator.Remainder:
                            return Decorator.Enclose<object>(x.ToInt32(provider) % y.ToInt32(provider)).ChangeType<T>();
                        case replacedignmentOperator.RightShift:
                            return Decorator.Enclose<object>(x.ToInt32(provider) >> y.ToInt32(provider)).ChangeType<T>();
                        case replacedignmentOperator.Subtraction:
                            return Decorator.Enclose<object>(x.ToInt32(provider) - y.ToInt32(provider)).ChangeType<T>();
                        default:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment));
                    }
                case TypeCode.Int64:
                    switch (replacedignment)
                    {
                        case replacedignmentOperator.Addition:
                            return Decorator.Enclose<object>(x.ToInt64(provider) + y.ToInt64(provider)).ChangeType<T>();
                        case replacedignmentOperator.And:
                            return Decorator.Enclose<object>(x.ToInt64(provider) & y.ToInt64(provider)).ChangeType<T>();
                        case replacedignmentOperator.replacedign:
                            return y;
                        case replacedignmentOperator.Division:
                            return Decorator.Enclose<object>(x.ToInt64(provider) / y.ToInt64(provider)).ChangeType<T>();
                        case replacedignmentOperator.ExclusiveOr:
                            return Decorator.Enclose<object>(x.ToInt64(provider) ^ y.ToInt64(provider)).ChangeType<T>();
                        case replacedignmentOperator.LeftShift:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x << y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.Multiplication:
                            return Decorator.Enclose<object>(x.ToInt64(provider) * y.ToInt64(provider)).ChangeType<T>();
                        case replacedignmentOperator.Or:
                            return Decorator.Enclose<object>(x.ToInt64(provider) | y.ToInt64(provider)).ChangeType<T>();
                        case replacedignmentOperator.Remainder:
                            return Decorator.Enclose<object>(x.ToInt64(provider) % y.ToInt64(provider)).ChangeType<T>();
                        case replacedignmentOperator.RightShift:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x >> y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.Subtraction:
                            return Decorator.Enclose<object>(x.ToInt64(provider) - y.ToInt64(provider)).ChangeType<T>();
                        default:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment));
                    }
                case TypeCode.SByte:
                    switch (replacedignment)
                    {
                        case replacedignmentOperator.Addition:
                            return Decorator.Enclose<object>(x.ToSByte(provider) + y.ToSByte(provider)).ChangeType<T>();
                        case replacedignmentOperator.And:
                            return Decorator.Enclose<object>(x.ToSByte(provider) & y.ToSByte(provider)).ChangeType<T>();
                        case replacedignmentOperator.replacedign:
                            return y;
                        case replacedignmentOperator.Division:
                            return Decorator.Enclose<object>(x.ToSByte(provider) / y.ToSByte(provider)).ChangeType<T>();
                        case replacedignmentOperator.ExclusiveOr:
                            return Decorator.Enclose<object>(x.ToSByte(provider) ^ y.ToSByte(provider)).ChangeType<T>();
                        case replacedignmentOperator.LeftShift:
                            return Decorator.Enclose<object>(x.ToSByte(provider) << y.ToSByte(provider)).ChangeType<T>();
                        case replacedignmentOperator.Multiplication:
                            return Decorator.Enclose<object>(x.ToSByte(provider) * y.ToSByte(provider)).ChangeType<T>();
                        case replacedignmentOperator.Or:
                            return Decorator.Enclose<object>(x.ToSByte(provider) | y.ToSByte(provider)).ChangeType<T>();
                        case replacedignmentOperator.Remainder:
                            return Decorator.Enclose<object>(x.ToSByte(provider) % y.ToSByte(provider)).ChangeType<T>();
                        case replacedignmentOperator.RightShift:
                            return Decorator.Enclose<object>(x.ToSByte(provider) >> y.ToSByte(provider)).ChangeType<T>();
                        case replacedignmentOperator.Subtraction:
                            return Decorator.Enclose<object>(x.ToSByte(provider) - y.ToSByte(provider)).ChangeType<T>();
                        default:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment));
                    }
                case TypeCode.Single:
                    switch (replacedignment)
                    {
                        case replacedignmentOperator.Addition:
                            return Decorator.Enclose<object>(x.ToSingle(provider) + y.ToSingle(provider)).ChangeType<T>();
                        case replacedignmentOperator.And:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x &= y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.replacedign:
                            return y;
                        case replacedignmentOperator.Division:
                            return Decorator.Enclose<object>(x.ToSingle(provider) / y.ToSingle(provider)).ChangeType<T>();
                        case replacedignmentOperator.ExclusiveOr:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x ^= y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.LeftShift:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x << y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.Multiplication:
                            return Decorator.Enclose<object>(x.ToSingle(provider) * y.ToSingle(provider)).ChangeType<T>();
                        case replacedignmentOperator.Or:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x |= y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.Remainder:
                            return Decorator.Enclose<object>(x.ToSingle(provider) % y.ToSingle(provider)).ChangeType<T>();
                        case replacedignmentOperator.RightShift:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x >> y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.Subtraction:
                            return Decorator.Enclose<object>(x.ToSingle(provider) - y.ToSingle(provider)).ChangeType<T>();
                        default:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment));
                    }
                case TypeCode.UInt16:
                    switch (replacedignment)
                    {
                        case replacedignmentOperator.Addition:
                            return Decorator.Enclose<object>(x.ToUInt16(provider) + y.ToUInt16(provider)).ChangeType<T>();
                        case replacedignmentOperator.And:
                            return Decorator.Enclose<object>(x.ToUInt16(provider) & y.ToUInt16(provider)).ChangeType<T>();
                        case replacedignmentOperator.replacedign:
                            return y;
                        case replacedignmentOperator.Division:
                            return Decorator.Enclose<object>(x.ToUInt16(provider) / y.ToUInt16(provider)).ChangeType<T>();
                        case replacedignmentOperator.ExclusiveOr:
                            return Decorator.Enclose<object>(x.ToUInt16(provider) ^ y.ToUInt16(provider)).ChangeType<T>();
                        case replacedignmentOperator.LeftShift:
                            return Decorator.Enclose<object>(x.ToUInt16(provider) << y.ToUInt16(provider)).ChangeType<T>();
                        case replacedignmentOperator.Multiplication:
                            return Decorator.Enclose<object>(x.ToUInt16(provider) * y.ToUInt16(provider)).ChangeType<T>();
                        case replacedignmentOperator.Or:
                            return Decorator.Enclose<object>(x.ToUInt16(provider) | y.ToUInt16(provider)).ChangeType<T>();
                        case replacedignmentOperator.Remainder:
                            return Decorator.Enclose<object>(x.ToUInt16(provider) % y.ToUInt16(provider)).ChangeType<T>();
                        case replacedignmentOperator.RightShift:
                            return Decorator.Enclose<object>(x.ToUInt16(provider) >> y.ToUInt16(provider)).ChangeType<T>();
                        case replacedignmentOperator.Subtraction:
                            return Decorator.Enclose<object>(x.ToUInt16(provider) - y.ToUInt16(provider)).ChangeType<T>();
                        default:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment));
                    }
                case TypeCode.UInt32:
                    switch (replacedignment)
                    {
                        case replacedignmentOperator.Addition:
                            return Decorator.Enclose<object>(x.ToUInt32(provider) + y.ToUInt32(provider)).ChangeType<T>();
                        case replacedignmentOperator.And:
                            return Decorator.Enclose<object>(x.ToUInt32(provider) & y.ToUInt32(provider)).ChangeType<T>();
                        case replacedignmentOperator.replacedign:
                            return y;
                        case replacedignmentOperator.Division:
                            return Decorator.Enclose<object>(x.ToUInt32(provider) / y.ToUInt32(provider)).ChangeType<T>();
                        case replacedignmentOperator.ExclusiveOr:
                            return Decorator.Enclose<object>(x.ToUInt32(provider) ^ y.ToUInt32(provider)).ChangeType<T>();
                        case replacedignmentOperator.LeftShift:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x << y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.Multiplication:
                            return Decorator.Enclose<object>(x.ToUInt32(provider) * y.ToUInt32(provider)).ChangeType<T>();
                        case replacedignmentOperator.Or:
                            return Decorator.Enclose<object>(x.ToUInt32(provider) | y.ToUInt32(provider)).ChangeType<T>();
                        case replacedignmentOperator.Remainder:
                            return Decorator.Enclose<object>(x.ToUInt32(provider) % y.ToUInt32(provider)).ChangeType<T>();
                        case replacedignmentOperator.RightShift:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x >> y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.Subtraction:
                            return Decorator.Enclose<object>(x.ToUInt32(provider) - y.ToUInt32(provider)).ChangeType<T>();
                        default:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment));
                    }
                case TypeCode.UInt64:
                    switch (replacedignment)
                    {
                        case replacedignmentOperator.Addition:
                            return Decorator.Enclose<object>(x.ToUInt64(provider) + y.ToUInt64(provider)).ChangeType<T>();
                        case replacedignmentOperator.And:
                            return Decorator.Enclose<object>(x.ToUInt64(provider) & y.ToUInt64(provider)).ChangeType<T>();
                        case replacedignmentOperator.replacedign:
                            return y;
                        case replacedignmentOperator.Division:
                            return Decorator.Enclose<object>(x.ToUInt64(provider) / y.ToUInt64(provider)).ChangeType<T>();
                        case replacedignmentOperator.ExclusiveOr:
                            return Decorator.Enclose<object>(x.ToUInt64(provider) ^ y.ToUInt64(provider)).ChangeType<T>();
                        case replacedignmentOperator.LeftShift:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x << y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.Multiplication:
                            return Decorator.Enclose<object>(x.ToUInt64(provider) * y.ToUInt64(provider)).ChangeType<T>();
                        case replacedignmentOperator.Or:
                            return Decorator.Enclose<object>(x.ToUInt64(provider) | y.ToUInt64(provider)).ChangeType<T>();
                        case replacedignmentOperator.Remainder:
                            return Decorator.Enclose<object>(x.ToUInt64(provider) % y.ToUInt64(provider)).ChangeType<T>();
                        case replacedignmentOperator.RightShift:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment), string.Format(CultureInfo.InvariantCulture, "Cannot apply replacedignment operator '{0}' (x >> y) to operands of type '{1}'.", Enum.GetName(typeof(replacedignmentOperator), replacedignment), typeof(T).Name));
                        case replacedignmentOperator.Subtraction:
                            return Decorator.Enclose<object>(x.ToUInt64(provider) - y.ToUInt64(provider)).ChangeType<T>();
                        default:
                            throw new ArgumentOutOfRangeException(nameof(replacedignment));
                    }
                default:
                    throw new TypeArgumentException("T", string.Format(CultureInfo.InvariantCulture, "T appears to contain an invalid type. Expected type is numeric and must be one of the following: Byte, Decimal, Double, Int16, Int32, Int64, SByte, Single, UInt16, UInt32 or UInt64. Actually type was {0}.", typeof(T).Name));
            }
        }

19 Source : Convertible.cs
with MIT License
from gimlichael

public static byte[] GetBytes(Enum input, Action<EndianOptions> setup = null)
        {
            var tc = input.GetTypeCode();
            var c = input as IConvertible;
            switch (tc)
            {
                case TypeCode.Byte:
                {
                    return GetBytes(c.ToByte(CultureInfo.InvariantCulture), setup);
                }
                case TypeCode.Int16:
                {
                    return GetBytes(c.ToInt16(CultureInfo.InvariantCulture), setup);
                }
                case TypeCode.Int64:
                {
                    return GetBytes(c.ToInt64(CultureInfo.InvariantCulture), setup);
                }
                case TypeCode.UInt16:
                {
                    return GetBytes(c.ToUInt16(CultureInfo.InvariantCulture), setup);
                }
                case TypeCode.UInt32:
                {
                    return GetBytes(c.ToUInt32(CultureInfo.InvariantCulture), setup);
                }
                case TypeCode.UInt64:
                {
                    return GetBytes(c.ToUInt64(CultureInfo.InvariantCulture), setup);
                }
                case TypeCode.SByte:
                {
                    return GetBytes(c.ToSByte(CultureInfo.InvariantCulture), setup);
                }
                default:
                    return GetBytes(c.ToInt32(CultureInfo.InvariantCulture), setup);
            }
        }

19 Source : bool.cs
with MIT License
from GridProtectionAlliance

int IConvertible.ToInt32(IFormatProvider? provider) => ((IConvertible)Value).ToInt32(provider);

19 Source : string.cs
with MIT License
from GridProtectionAlliance

int IConvertible.ToInt32(IFormatProvider? provider) => ((IConvertible)ToString()).ToInt32(provider);

19 Source : complex64.cs
with MIT License
from GridProtectionAlliance

int IConvertible.ToInt32(IFormatProvider? provider) => ((IConvertible)m_real).ToInt32(provider);

19 Source : INode.cs
with MIT License
from hiro80

protected void CorrectComments2<TEnum>(TEnum propValue
                                          , TEnum value
                                          , int offset
                                          , params bool[] terminalNodeExistsArray)
    where TEnum: struct, System.IConvertible {
      int propValueId = propValue.ToInt32(null);
      int valueId = value.ToInt32(null);
      int nullValueId = default(TEnum).ToInt32(null);
      if(valueId != nullValueId) {
        if(propValueId == nullValueId) {
          var i = CountTrue(terminalNodeExistsArray);
          this.Comments.Insert(offset + i, null);
        }
      } else {
        if(propValueId != nullValueId) {
          var i = CountTrue(terminalNodeExistsArray);
          this.Comments.RemoveAt(offset + i);
        }
      }
    }

See More Examples