Example #1
0
        public static TModel GetModel <TModel>(this IWrapResponse <TModel> source)
            where TModel : class
        {
            if (source.Data is ICollection <object> )
            {
                throw new Exception("Data is a collection!");
            }

            var model = Activator.CreateInstance <TModel>();

            ReflectionsHelper.Copy(source.Data, model);

            return(model);
        }
        public static IList <TModel> GetModels <TModel>(this IWrapResponse <TModel> source)
            where TModel : class
        {
            if (!(source.Data is ICollection <object>))
            {
                throw new Exception("Data is not a collection!");
            }

            var models = new List <TModel>();

            foreach (var data in ((ICollection <object>)source.Data))
            {
                var model = Activator.CreateInstance <TModel>();

                ReflectionsHelper.Copy(data, model);

                models.Add(model);
            }

            return(models);
        }