public void ToStringTests() { var str = ClientConvert.ToString(new TestPrimitiveType() { Data = "Property_Value" }); Assert.AreEqual("Property_Value", str); Assert.AreEqual(0, converter.ParseCall); Assert.AreEqual(1, converter.ToStringCall); }
/// <summary> /// Converts a non-spatial primitive value to the target type. /// </summary> /// <param name="value">The value to convert.</param> /// <param name="targetType">The target type of the conversion.</param> /// <returns>The converted value.</returns> private static object ConvertNonSpatialValue(object value, Type targetType) { Debug.Assert(value != null, "value != null"); // These types can be safely converted to directly, as there is no risk of precision being lost. if (CanSafelyConvertTo(targetType)) { return(Convert.ChangeType(value, targetType, CultureInfo.InvariantCulture)); } string stringValue = ClientConvert.ToString(value); return(ClientConvert.ChangeType(stringValue, targetType)); }
private void PopulateData(EpmTargetPathSegment segment, object element, EpmContentSerializer.EpmNullValuedPropertyTree nullValuedProperties, DataServiceProviderWrapper provider) #endif { if (segment.EpmInfo != null) { Object propertyValue; try { #if ASTORIA_CLIENT propertyValue = segment.EpmInfo.ReadPropertyValue(element); #else propertyValue = segment.EpmInfo.ReadPropertyValue(element, provider); #endif } catch #if ASTORIA_CLIENT (System.Reflection.TargetInvocationException) #else (System.Reflection.TargetInvocationException e) #endif { #if !ASTORIA_CLIENT ErrorHandler.HandleTargetInvocationException(e); #endif throw; } #if ASTORIA_CLIENT this.Data = propertyValue == null ? String.Empty : ClientConvert.ToString(propertyValue, false); #else if (propertyValue == null || propertyValue == DBNull.Value) { this.Data = String.Empty; nullValuedProperties.Add(segment.EpmInfo); } else { this.Data = PlainXmlSerializer.PrimitiveToString(propertyValue); } #endif } } }
private void PopulateData(EpmTargetPathSegment segment, object element) { if (segment.EpmInfo != null) { Object propertyValue; try { propertyValue = segment.EpmInfo.PropValReader.DynamicInvoke(element); } catch (System.Reflection.TargetInvocationException) { throw; } this.Data = propertyValue == null ? String.Empty : ClientConvert.ToString(propertyValue, false); } }
/// <summary> /// Converts a non-spatial primitive value to the target type. /// </summary> /// <param name="value">The value to convert.</param> /// <param name="targetType">The target type of the conversion.</param> /// <returns>The converted value.</returns> private static object ConvertNonSpatialValue(object value, Type targetType) { Debug.Assert(value != null, "value != null"); TypeCode targetTypeCode = PlatformHelper.GetTypeCode(targetType); // These types can be safely converted to directly, as there is no risk of precision being lost. switch (targetTypeCode) { case TypeCode.Boolean: case TypeCode.Byte: case TypeCode.SByte: case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: return(Convert.ChangeType(value, targetType, CultureInfo.InvariantCulture)); } string stringValue = ClientConvert.ToString(value); return(ClientConvert.ChangeType(stringValue, targetType)); }