private T[] CoerceArrayValue <T>(PropertyType unboxType) { if (this.Type == unboxType) { return((T[])this._data); } Array array = this._data as Array; if (array == null) { throw new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueElement", (object)this.Type, (object)typeof(T).MakeArrayType().Name), -2147316576); } PropertyType type = this.Type - 1024; T[] objArray = new T[array.Length]; for (int index = 0; index < array.Length; ++index) { try { objArray[index] = CLRIPropertyValueImpl.CoerceScalarValue <T>(type, array.GetValue(index)); } catch (InvalidCastException ex) { InvalidCastException invalidCastException = new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueArrayCoersion", (object)this.Type, (object)typeof(T).MakeArrayType().Name, (object)index, (object)ex.Message), (Exception)ex); int hr = ex._HResult; invalidCastException.SetErrorCode(hr); throw invalidCastException; } } return(objArray); }
// Token: 0x0600640E RID: 25614 RVA: 0x00153B48 File Offset: 0x00151D48 private T CoerceScalarValue <T>(PropertyType unboxType) { if (this.Type == unboxType) { return((T)((object)this._data)); } return(CLRIPropertyValueImpl.CoerceScalarValue <T>(this.Type, this._data)); }
private static bool IsCoercable(PropertyType type, object data) { if (type == PropertyType.Guid || type == PropertyType.String) { return(true); } return(CLRIPropertyValueImpl.IsNumericScalarImpl(type, data)); }
// Token: 0x0600640D RID: 25613 RVA: 0x00153A1C File Offset: 0x00151C1C private T[] CoerceArrayValue <T>(PropertyType unboxType) { if (this.Type == unboxType) { return((T[])this._data); } Array array = this._data as Array; if (array == null) { throw new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueElement", new object[] { this.Type, typeof(T).MakeArrayType().Name }), -2147316576); } PropertyType type = this.Type - 1024; T[] array2 = new T[array.Length]; for (int i = 0; i < array.Length; i++) { try { array2[i] = CLRIPropertyValueImpl.CoerceScalarValue <T>(type, array.GetValue(i)); } catch (InvalidCastException ex) { Exception ex2 = new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueArrayCoersion", new object[] { this.Type, typeof(T).MakeArrayType().Name, i, ex.Message }), ex); ex2.SetErrorCode(ex._HResult); throw ex2; } } return(array2); }
// Token: 0x0600640F RID: 25615 RVA: 0x00153B70 File Offset: 0x00151D70 private static T CoerceScalarValue <T>(PropertyType type, object value) { if (!CLRIPropertyValueImpl.IsCoercable(type, value) && type != PropertyType.Inspectable) { throw new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueElement", new object[] { type, typeof(T).Name }), -2147316576); } try { if (type == PropertyType.String && typeof(T) == typeof(Guid)) { return((T)((object)Guid.Parse((string)value))); } if (type == PropertyType.Guid && typeof(T) == typeof(string)) { return((T)((object)((Guid)value).ToString("D", CultureInfo.InvariantCulture))); } foreach (Tuple <Type, PropertyType> tuple in CLRIPropertyValueImpl.NumericScalarTypes) { if (tuple.Item1 == typeof(T)) { return((T)((object)Convert.ChangeType(value, typeof(T), CultureInfo.InvariantCulture))); } } } catch (FormatException) { throw new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueElement", new object[] { type, typeof(T).Name }), -2147316576); } catch (InvalidCastException) { throw new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueElement", new object[] { type, typeof(T).Name }), -2147316576); } catch (OverflowException) { throw new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueCoersion", new object[] { type, value, typeof(T).Name }), -2147352566); } IPropertyValue propertyValue = value as IPropertyValue; if (type == PropertyType.Inspectable && propertyValue != null) { if (typeof(T) == typeof(byte)) { return((T)((object)propertyValue.GetUInt8())); } if (typeof(T) == typeof(short)) { return((T)((object)propertyValue.GetInt16())); } if (typeof(T) == typeof(ushort)) { return((T)((object)propertyValue.GetUInt16())); } if (typeof(T) == typeof(int)) { return((T)((object)propertyValue.GetUInt32())); } if (typeof(T) == typeof(uint)) { return((T)((object)propertyValue.GetUInt32())); } if (typeof(T) == typeof(long)) { return((T)((object)propertyValue.GetInt64())); } if (typeof(T) == typeof(ulong)) { return((T)((object)propertyValue.GetUInt64())); } if (typeof(T) == typeof(float)) { return((T)((object)propertyValue.GetSingle())); } if (typeof(T) == typeof(double)) { return((T)((object)propertyValue.GetDouble())); } } throw new InvalidCastException(Environment.GetResourceString("InvalidCast_WinRTIPropertyValueElement", new object[] { type, typeof(T).Name }), -2147316576); }