Example #1
0
        /// <summary>
        /// Populate an object with Example data.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static object PopulateWith(object obj)
        {
            if (obj == null)
            {
                return(null);
            }


#if PLATFORM_USE_SERIALIZATION_DLL
            var isHttpResult = obj.GetType().GetInterfaces().Any(x => x.Name == "IHttpResult"); // No coupling FTW!
            if (isHttpResult)
            {
                obj = new CustomHttpResult();
            }
#endif

            var type = obj.GetType();
            if (type.IsArray() || type.IsValueType() || type.IsGeneric())
            {
                var value = CreateDefaultValue(type, new Dictionary <Type, int>(20));
                return(value);
            }

            return(PopulateObjectInternal(obj, new Dictionary <Type, int>(20)));
        }
        /// <summary>
        /// Populate an object with Example data.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static object PopulateObject(object obj)
        {
            if (obj == null)
            {
                return(null);
            }
            var httpResult = obj as IHttpResult;

            if (httpResult != null)
            {
                obj = new CustomHttpResult();
            }

            var type = obj.GetType();

            if (type.IsArray() || type.IsValueType() || type.IsGeneric())
            {
                var value = CreateDefaultValue(type, new Dictionary <Type, int>(20));
                return(value);
            }

            return(PopulateObjectInternal(obj, new Dictionary <Type, int>(20)));
        }