Ejemplo n.º 1
0
        /// <summary>
        /// Return the formatted value for the given entity field using the property datatype
        /// </summary>
        internal static object GetFormattedValue(BaseEntity entity, String fieldName, FieldMetadata fieldMetadata)
        {
            if (entity == null || string.IsNullOrEmpty(fieldName))
            {
                return(null);
            }
            try
            {
                if (fieldMetadata == null)
                {
                    return(null);
                }

                Func <object, object> func;
                if (!Converter.TryGetValue(fieldMetadata.FieldType, out func))
                {
                    return(null);
                }

                var      value = entity.GetValue(fieldName);
                DateTime datetime;
                string   dateString = (String)value;
                if (fieldMetadata.GetStringValue("editable") == "True" && DateTime.TryParseExact(dateString, "yyyy-MM-ddTHH:mm:ssZ", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AssumeLocal, out datetime))
                {
                    return(value);
                }
                return(func(value));
            }
            catch (Exception)
            {
                return(null);
            }
        }