Exemplo n.º 1
0
        //public static TField[] ToFieldArray<TField>(this IEnumerable<CustomFieldCache.CustomFieldItem> items,
        //    ICollection<Field> collection, string namePrefix, Func<ICollection<Field>, string, LocalText, int, FieldFlags, TField> createField)
        //{
        //    var result = new List<Field>();
        //    foreach (var item in items)
        //    {
        //        var meta = new FieldMeta((namePrefix ?? "") + item.Name,
        //            ToLocalText(item.Caption), item.Size, item.Required ? Required : NotRequired);

        //        Field field = createField(meta);
        //        result.Add(field);
        //    }

        //    return result.ToArray();
        //}

        //public static TField[] ToFieldArray<TField>(this IEnumerable<CustomFieldCache.CustomFieldItem> items,
        //    ICollection<Field> collection, string namePrefix, Func<FieldMeta, TField> createField)
        //    where TField: Field
        //{
        //    var result = new List<TField>();
        //    foreach (var item in items)
        //    {
        //        var meta = new FieldMeta((namePrefix ?? "") + item.Name,
        //            ToLocalText(item.Caption), item.Size, item.Required ? Required : NotRequired);

        //        TField field = createField(meta);
        //        result.Add(field);
        //    }

        //    return result.ToArray();
        //}

        public static void DefaultFieldCaption(this RowFieldsBase fields, string fieldName, string caption)
        {
            LocalText.Add(new List <LocalText.Entry>()
            {
                new LocalText.Entry(LocalText.DefaultLanguageID, "Db." + fields.TableName + "." + fieldName,
                                    caption)
            }, false);
        }
Exemplo n.º 2
0
        public static string FormatEnum(Type enumType, object value)
        {
            if (value == null)
            {
                return(String.Empty);
            }

            if (enumType != null &&
                enumType.IsEnum &&
                System.Enum.GetName(enumType, value) != null)
            {
                var typeName = enumType.Name;
                var enumName = System.Enum.GetName(enumType, value);
                var key      = "Enums." + typeName + "." + enumName;
                var text     = LocalText.TryGet(key);
                if (text == null)
                {
                    var memInfo = enumType.GetMember(enumName);
                    if (memInfo != null && memInfo.Length == 1)
                    {
                        var attributes = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
                        if (attributes.Length > 0)
                        {
                            text = ((DescriptionAttribute)attributes[0]).Description;
                            LocalText.Add(new List <LocalText.Entry>
                            {
                                new LocalText.Entry(LocalText.DefaultLanguageID, key, text)
                            }, false);
                        }
                    }
                }

                return(text ?? enumName);
            }
            else
            {
                return(value.ToString());
            }
        }