/// <summary> /// Sets the double value on the user data source. /// </summary> /// <param name="datasource">The datasource.</param> /// <param name="userDataSourceId">The user data source identifier.</param> /// <param name="value">The value.</param> public static void SetValue(this UserDataSources datasource, string userDataSourceId, double?value) { if (value != null) { datasource.Item(userDataSourceId).ValueEx = ((double)value).ToString(CultureInfo.InvariantCulture); } }
/// <summary> /// Sets the DateTime value on the user data source. /// </summary> /// <param name="datasource">The datasource.</param> /// <param name="userDataSourceId">The user data source identifier.</param> /// <param name="value">The value.</param> public static void SetValue(this UserDataSources datasource, string userDataSourceId, DateTime?value) { if (value != null) { datasource.Item(userDataSourceId).ValueEx = ((DateTime)value).ToString("yyyyMMdd"); } }
public static UserDataSources SAPObjetFromXml(this UserDataSources userDataSources, XmlDocument xmlDocument, string documentName = null) { var result = xmlDocument.ToObject(userDataSources, userDataSources.Count, GetItem, GetName, SetValue, documentName); return(result); }
public static TDestiny ToObject <TDestiny>(UserDataSources source, bool useXmlAttributes = true) where TDestiny : class, new() { var destiny = new TDestiny(); ToObject(source, destiny, useXmlAttributes); return(destiny); }
/// <summary> /// Returns the integer value in the datasource or null if none is found. /// </summary> /// <param name="datasource">The datasource.</param> /// <param name="userDataSourceId">The user data source identifier.</param> /// <param name="defaultValue">The value to return when the datasource is empty.</param> /// <returns> /// The integer value in the datasource or null if none is found. /// </returns> /// <remarks> /// Note that if the value in the datasource cannot be cast to an integer an exception will be thrown. /// <para /> /// The default value will not be returned. /// </remarks> /// <exception cref="InvalidOperationException"> /// Thrown when the value in the datasource cannot be converted to an integer. /// </exception> public static int GetInt(this UserDataSources datasource, string userDataSourceId, int defaultValue) { int? value = datasource.GetInt(userDataSourceId); if (value != null) { return (int) value; } return defaultValue; }
public static void FromObject <TSource>(UserDataSources destiny, TSource source, bool useXmlAttributes = true) where TSource : class { if (destiny == null) { throw new ArgumentNullException("destiny"); } if (source == null) { throw new ArgumentNullException("source"); } var props = ObjectHelpers.LoadProperties(source.GetType(), p => p.CanRead, useXmlAttributes); for (var index = 0; index < destiny.Count; ++index) { var item = destiny.Item(index); PropertyInfo propertyInfo; if (!props.TryGetValue(item.UID, out propertyInfo)) { continue; } var value = propertyInfo.GetValue(source, null); if (value == null) { item.Value = String.Empty; } else { bool nullable; var type = ObjectHelpers.GetSpecificType(propertyInfo.PropertyType, out nullable); if (nullable && value.Equals(null)) { item.Value = String.Empty; } else if (type == ObjectHelpers.TypeOfBoolean) { item.Value = value.Equals(true) ? "Y" : "N"; } else { var convertible = value as IConvertible; item.Value = convertible != null ? convertible.ToString(CultureInfo.InvariantCulture) : value.ToString(); } } } }
/// <summary> /// Returns the double value in the datasource or null if none is found. /// </summary> /// <param name="datasource">The datasource.</param> /// <param name="userDataSourceId">The user data source identifier.</param> /// <param name="defaultValue">The value to return when the datasource is empty.</param> /// <returns> /// The double value in the datasource or null if none is found. /// </returns> /// <remarks> /// Note that if the value in the datasource cannot be cast to a double an exception will be thrown. /// <para /> /// The default value will not be returned. /// </remarks> /// <exception cref="InvalidOperationException"> /// Thrown when the value in the datasource cannot be converted to a double. /// </exception> public static double GetDouble( this UserDataSources datasource, string userDataSourceId, double defaultValue) { var value = datasource.GetDouble(userDataSourceId); if (value != null) { return (double) value; } return defaultValue; }
public static DateTime?GetDateTime(this UserDataSources datasource, string userDataSourceId) { if (datasource.IsEmpty(userDataSourceId)) { return(null); } var data = datasource.GetString(userDataSourceId); DateTime value; var success = DateTime.TryParse(data, CultureInfo.InvariantCulture, DateTimeStyles.None, out value); if (success) { return(value); } throw new InvalidOperationException(FormatMessage(userDataSourceId, data, typeof(DateTime?))); }
/// <summary> /// Returns the integer value in the datasource or null if none is found. /// </summary> /// <param name="datasource">The datasource.</param> /// <param name="userDataSourceId">The user data source identifier.</param> /// <returns> /// The integer value in the datasource or null if none is found. /// </returns> /// <exception cref="InvalidOperationException"> /// Thrown when the value in the datasource cannot be converted to an integer. /// </exception> public static int?GetInt(this UserDataSources datasource, string userDataSourceId) { if (datasource.IsEmpty(userDataSourceId)) { return(null); } string data = datasource.GetString(userDataSourceId); int value; var success = int.TryParse(data, NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out value); if (success) { return(value); } throw new InvalidOperationException(FormatMessage(userDataSourceId, data, typeof(int?))); }
/// <summary> /// Returns the double value in the datasource or null if none is found. /// </summary> /// <param name="datasource">The datasource.</param> /// <param name="userDataSourceId">The user data source identifier.</param> /// <returns> /// The double value in the datasource or null if none is found. /// </returns> /// <exception cref="InvalidOperationException"> /// Thrown when the value in the datasource cannot be converted to a double. /// </exception> public static double? GetDouble(this UserDataSources datasource, string userDataSourceId) { if (datasource.IsEmpty(userDataSourceId)) { return null; } string data = datasource.GetString(userDataSourceId); double value; var success = double.TryParse(data, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out value); if (success) { return value; } throw new InvalidOperationException(FormatMessage(userDataSourceId, data, typeof(double?))); }
/// <summary> /// Determines whether the specified user data source is empty. /// </summary> /// <param name="datasource">The datasource.</param> /// <param name="userDataSourceId">The user data source identifier.</param> /// <returns>True when empty, false otherwise.</returns> private static bool IsEmpty(this UserDataSources datasource, string userDataSourceId) { string value = datasource.GetString(userDataSourceId); return(string.IsNullOrEmpty(value)); }
/// <summary> /// Sets the string value on the user data source. /// </summary> /// <param name="datasource">The datasource.</param> /// <param name="userDataSourceId">The user data source identifier.</param> /// <param name="value">The value.</param> /// <remarks>If value is null an empty string will be used instead.</remarks> /// /// public static void SetValue(this UserDataSources datasource, string userDataSourceId, string value) { datasource.Item(userDataSourceId).ValueEx = value ?? string.Empty; }
/// <summary> /// Returns the string value in the datasource. /// </summary> /// <param name="datasource">The datasource.</param> /// <param name="userDataSourceId">The user data source identifier.</param> /// <returns> /// The string on the datasource. /// </returns> public static string GetString(this UserDataSources datasource, string userDataSourceId) { return(datasource.Item(userDataSourceId).ValueEx ?? string.Empty); }
public static void ToObject <TDestiny>(UserDataSources source, TDestiny destiny, bool useXmlAttributes = true) where TDestiny : class { if (source == null) { throw new ArgumentNullException("source"); } if (destiny == null) { throw new ArgumentNullException("destiny"); } var props = ObjectHelpers.LoadProperties(destiny.GetType(), p => p.CanWrite, useXmlAttributes); for (var index = 0; index < source.Count; ++index) { var item = source.Item(index); PropertyInfo propertyInfo; if (!props.TryGetValue(item.UID, out propertyInfo)) { continue; } object value; bool nullable; var type = ObjectHelpers.GetSpecificType(propertyInfo.PropertyType, out nullable); if (nullable && String.IsNullOrEmpty(item.ValueEx)) { value = null; } else if (type == ObjectHelpers.TypeOfString) { value = item.ValueEx; } else if (type == ObjectHelpers.TypeOfInt) { value = int.Parse(item.ValueEx); } else if (type == ObjectHelpers.TypeOfDateTime) { value = DateTime.ParseExact(item.ValueEx, item.DataType == BoDataType.dt_DATE ? "yyyyMMdd" : "HH:mm", CultureInfo.InvariantCulture); } else if (type == ObjectHelpers.TypeOfDouble) { value = double.Parse(item.ValueEx, CultureInfo.InvariantCulture); } else if (type == ObjectHelpers.TypeOfBoolean) { value = (item.ValueEx == "Y"); } else { continue; } propertyInfo.SetValue(destiny, value, null); } }
internal static UserDataSource GetItem(UserDataSources ds, int index) { return(ds.Item(index)); }
public static XmlDocument SAPObjectToXml(this UserDataSources userDataSources, string documentName) { var result = userDataSources.ToXmlDocument(userDataSources.Count, GetItem, GetName, GetValue, documentName); return(result); }