/// <summary>Migrate internal data model from request type to appropriate type in final form</summary>
        /// <typeparam name="T">Type of data response that should be returned</typeparam>
        /// <param name="json">Json string at immediate data level</param>
        /// <returns>T</returns>
        public static R Migrate <R, I>(string json)
            where R : class
        {
            if (json == null)
            {
                return(null);
            }

            // convert to json object
            I jsonObj = JsonConvert.DeserializeObject <I>(json, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });

            if (jsonObj == null)
            {
                return(null);
            }

            // cast to Migrateable and call its Migrate() method to get result migrated data
            Migrateable <R> mig = (Migrateable <R>)jsonObj;

            if (mig != null)
            {
                return(mig.Migrate());
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        /*
         *      Migrate data of type N to R.
         */
        public static R migrate <R, I>(ref I input)
            where R : new()
        {
            Migrateable <R> mig = input as Migrateable <R>;

            if (mig == null)
            {
                throw new Exception("input data has no migrate ability");
            }

            return((R)(object)mig.migrate());
        }
        /// <summary>Migrate from List (type I) to List (type R)</summary>
        /// <typeparam name="R,I">R,I</typeparam>
        /// <param name="input">List to be migrated</param>
        /// <returns>List<R></returns>
        public static List <R> MigrateList <R, I>(List <I> input)
            where R : class
            where I : class
        {
            List <R> list = new List <R>();

            if (input != null)
            {
                for (int i = 0; i < input.Count; i++)
                {
                    Migrateable <R> mig = (Migrateable <R>)input[i];
                    list.Add(mig.Migrate());
                }
            }

            return(list);
        }