I created this page in the hope that we can collect some often used code in XtraReport scripting.
/// <summary> /// Check if the value is null or DBNull. The value is often obtained from GetCurrentColumnValue. /// </summary> /// <param name="value">the value to check for null</param> /// <returns></returns> private static bool IsNull(object value) { if (value == null || value.Equals(System.DBNull.Value)) return true; return false; } /// <summary> /// Execute the division and return the result. If the denominator is zero, return zero. /// </summary> /// <param name="n">the nominator value</param> /// <param name="d">the demoniator value</param> /// <returns>the result of the division</returns> private static decimal SafeDiv(decimal n, decimal d) { return AimUtil.SafeDiv(n, d); } /// <summary> /// Get the field value. /// </summary> /// <typeparam name="T">the return type</typeparam> /// <param name="fieldName">the name of the field</param> /// <returns>Returns the field value. If the value is null, return the default value for the type</returns> private T GetFieldValue<T>(string fieldName) { object v = GetCurrentColumnValue(fieldName); if (IsNull(v)) return default(T); return (T)v; } /// <summary> /// Get the field value from the detail report band. /// </summary> /// <typeparam name="T">the return type</typeparam> /// <param name="detail">the report detail instance</param> /// <param name="fieldName">the field name</param> /// <returns>Returns the field value. If the value is null, return the default value for the type</returns> private T GetFieldValue<T>(DetailReportBand detail, string fieldName) { object v = detail.GetCurrentColumnValue(fieldName); if (IsNull(v)) return default(T); return (T)v; }