Пример #1
0
 /// <summary>
 /// Raises Format event.
 /// </summary>
 /// <param name="e">Provides event arguments.</param>
 protected virtual void OnFormat(DataConvertEventArgs e)
 {
     DataConvertEventHandler handler = Format;
     if (handler != null)
         handler(this, e);
 }
Пример #2
0
        private string GetDataText(ItemVisualGenerator generator, object data, string fieldName, object propertyValue)
        {
            if (!_FormattingEnabled)
            {
                if (data == null)
                {
                    return string.Empty;
                }
                if (propertyValue == null)
                {
                    return "";
                }
                return Convert.ToString(propertyValue, CultureInfo.CurrentCulture);
            }

            DataConvertEventArgs e = new DataConvertEventArgs(propertyValue, typeof(string), data, fieldName);
            this.OnFormat(e);
            if ((e.Value != data) && (e.Value is string))
            {
                return (string)e.Value;
            }
            if (stringTypeConverter == null)
            {
                stringTypeConverter = TypeDescriptor.GetConverter(typeof(string));
            }
            try
            {
                return (string)FormatHelper.FormatObject(propertyValue, typeof(string), generator.GetFieldConverter(fieldName), stringTypeConverter, _FormatString, _FormatInfo, null, DBNull.Value);
            }
            catch (Exception ex)
            {
                if (ex is SecurityException || IsCriticalException(ex))
                {
                    throw;
                }
                return ((propertyValue != null) ? Convert.ToString(data, CultureInfo.CurrentCulture) : "");
            }
        }