コード例 #1
0
ファイル: Tools.cs プロジェクト: nostrenz/hieda
        public static string GetLangFromStatus(Entity.DefaultStatus status)
        {
            switch (status)
            {
            case Entity.DefaultStatus.All:
                return(Lang.ALL);

            case Entity.DefaultStatus.ToWatch:
                return(Lang.TO_WATCH);

            case Entity.DefaultStatus.Current:
                return(Lang.CURRENT);

            case Entity.DefaultStatus.StandBy:
                return(Lang.STANDBY);

            case Entity.DefaultStatus.Finished:
                return(Lang.FINISHED);

            case Entity.DefaultStatus.Dropped:
                return(Lang.DROPPED);

            default:
                return(status.ToString());
            }
        }
コード例 #2
0
        /// <summary>
        /// Fill an entity from a tuple by linking automaticaly
        /// entity properties and table collumns.
        ///
        /// The first execution generate a table schema,
        /// the second just read the schema, allowing for better performances.
        /// </summary>
        /// <param name="table"></param>
        /// <param name="entity"></param>
        /// <param name="tuple"></param>
        /// <returns></returns>
        public object FillEntityFromTuple(string table, object entity, Dictionary <string, string> tuple)
        {
            if (tuple == null)
            {
                return(null);
            }

            PropertyInfo[] properties = entity.GetType().GetProperties();

            foreach (PropertyInfo property in properties)
            {
                Collumn attribute = this.GetAttributeFrom <Collumn>(entity, property.Name);

                if (attribute == null || attribute.Name == null || !tuple.ContainsKey(attribute.Name))
                {
                    continue;
                }

                string value = tuple[attribute.Name];
                Type   type  = property.PropertyType;

                if (type == typeof(Entity.DefaultStatus))
                {
                    Entity.DefaultStatus status = (Entity.DefaultStatus)Enum.Parse(typeof(Entity.DefaultStatus), value);
                    property.SetValue(entity, status);
                }
                else if (type == typeof(Boolean))
                {
                    property.SetValue(entity, Convert.ChangeType((value == "1" ? true : false), type));
                }
                else if (!String.IsNullOrEmpty(value))
                {
                    try {
                        property.SetValue(entity, Convert.ChangeType(value, type));
                    } catch { }
                }
            }

            return(entity);
        }
コード例 #3
0
ファイル: Tools.cs プロジェクト: nostrenz/hieda
        /*
         * ============================================
         * Public
         * ============================================
         */

        #region Public

        public static string GetTranslatedStatus(Entity.DefaultStatus status)
        {
            return(Lang.Text("status_" + status));
        }