Пример #1
0
        public String SetData <T>(T data)
        {
            var fields = from field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
                         let attrs = field.GetCustomAttributes()
                                     from attr in attrs
                                     where attr is Messgae
                                     select field;
            IDictionary <String, Object> map = new Dictionary <String, Object>();

            foreach (var field in fields)
            {
                Messgae message = field.FieldType.GetCustomAttribute(typeof(Messgae)) as Messgae;
                map.Add(message.KeyName, field.GetValue(data));
            }
            return(list.Push(map));
        }
Пример #2
0
        public String SetDataList <T>(IList <T> data)
        {
            var fields = from field in typeof(T).GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
                         let attrs = field.GetCustomAttributes()
                                     from attr in attrs
                                     where attr is Messgae
                                     select field;
            IList <IDictionary <String, Object> > listmap = new List <IDictionary <String, Object> >();

            foreach (T entity in data)
            {
                IDictionary <String, Object> map = new Dictionary <String, Object>();
                listmap.Add(map);
                foreach (var field in fields)
                {
                    Messgae message = field.GetCustomAttribute(typeof(Messgae)) as Messgae;
                    map.Add(message.KeyName, field.GetValue(entity));
                }
            }
            return(list.Push(listmap));
        }