コード例 #1
0
ファイル: _StaticMethods.cs プロジェクト: jeiea/osuDownloader
        /// <summary>
        /// Converts an object to a dynamic object of type T.
        /// </summary>
        ///
        /// <typeparam name="T">
        /// The type of object to create. This must be an IDynamicMetaObjectProvider that also implements
        /// IDictionary&lt;string,object&gt;
        /// </typeparam>
        /// <param name="obj">
        /// The object.
        /// </param>
        ///
        /// <returns>
        /// A new object of type T.
        /// </returns>

        public static T ToDynamic <T>(object obj) where T : IDynamicMetaObjectProvider, IDictionary <string, object>, new()
        {
            if (obj is IDictionary <string, object> )
            {
                return(Objects.Dict2Dynamic <T>((IDictionary <string, object>)obj));
            }
            else
            {
                return(Objects.ToExpando <T>(obj));
            }
        }
コード例 #2
0
 public static T ToExpando <T>(object source, bool deep, IEnumerable <Type> ignoreAttributes) where T : IDictionary <string, object>, IDynamicMetaObjectProvider, new()
 {
     if (Objects.IsExpando(source) && !deep)
     {
         return(Objects.Dict2Dynamic <T>((IDictionary <string, object>)source));
     }
     else
     {
         return(ToNewExpando <T>(source, deep, ignoreAttributes));
     }
 }
コード例 #3
0
ファイル: _StaticMethods.cs プロジェクト: jeiea/osuDownloader
        /// <summary>
        /// Convert a dictionary to a dynamic object. Use to get another expando object from a sub-
        /// object of an expando object, e.g. as returned from JSON data.
        /// </summary>
        ///
        /// <param name="obj">
        /// The object.
        /// </param>
        ///
        /// <returns>
        /// obj as a JsObject.
        /// </returns>

        public static JsObject ToExpando(object obj)
        {
            JsObject result;


            if (obj is IDictionary <string, object> )
            {
                result = Objects.Dict2Dynamic <JsObject>((IDictionary <string, object>)obj);
            }
            else
            {
                return(Objects.ToExpando(obj));
            }
            return(result);
        }