Esempio n. 1
0
        public EntityManager(DataBaseAccess db)
        {
            object[] attrs; //datatableAttribtue
            attrs = typeof(Entity).GetCustomAttributes(typeof(DataTableAttribute), true);
            if (attrs.Length == 0)
            {
                throw new DataMappingException("此类未加上DataTable特性!");
            }
            DataTableAttribute tb = attrs[0] as DataTableAttribute;

            tableName = tb.Name;

            properties = typeof(Entity).GetProperties();

            this.db = db;
        }
Esempio n. 2
0
        public static string ToDisplayName(this DataTableAttribute attribute)
        {
            if (string.IsNullOrWhiteSpace(attribute.DisplayName) || (attribute.DisplayNameResourceType == null && DataTableGlobalConfig.SharedResourceType == null))
            {
                return(attribute.DisplayName);
            }

            var value = ResourceHelper.GetResourceLookup <string>(attribute.DisplayNameResourceType, attribute.DisplayName);

            if (string.IsNullOrWhiteSpace(value))
            {
                return(attribute.DisplayName);
            }

            return(value);
        }
Esempio n. 3
0
        internal static string GetDisplayName(this DataTableAttribute attribute)
        {
            if (string.IsNullOrWhiteSpace(attribute.DisplayName) || attribute.DisplayNameResourceType == null &&
                ElectDataTableOptions.Instance.SharedResourceType == null)
            {
                return(attribute.DisplayName);
            }

            var value = TypeHelper.GetResourceLookup <string>(attribute.DisplayNameResourceType, attribute.DisplayName);

            if (string.IsNullOrWhiteSpace(value))
            {
                return(attribute.DisplayName);
            }

            return(value);
        }
        internal static string GetDisplayName(this DataTableAttribute attribute)
        {
            if (string.IsNullOrWhiteSpace(attribute.DisplayName))
            {
                return(attribute.DisplayName);
            }

            // Translate by Attribute Resource Type is first Priority

            if (attribute.DisplayNameResourceType != null)
            {
                return(MecDataTableTranslator.Get(attribute.DisplayName, attribute.DisplayNameResourceType));
            }

            // Translate by Shared Resource Type

            return(MecDataTableTranslator.Get(attribute.DisplayName));
        }
        internal static string GetTableName(Type type)
        {
            if (type != typeof(DataEntry) && !type.IsSubclassOf(typeof(DataEntry)))
            {
                throw new ArgumentException(string.Format("Type {0} is not subclass of {1}", type.Name, typeof(DataEntry).Name));
            }
            DataTableAttribute dataTableAttribute = type.GetCustomAttributes(typeof(DataTableAttribute), false).Cast <DataTableAttribute>().FirstOrDefault <DataTableAttribute>();

            if (dataTableAttribute == null)
            {
                throw new InvalidOperationException(string.Format("Data table attribute not found for type: {0}", type.Name));
            }
            string name = dataTableAttribute.Name;

            if (string.IsNullOrEmpty(name))
            {
                throw new InvalidOperationException(string.Format("Data table name is empty for type: {0}", type.Name));
            }
            return(name);
        }