public static T DeserializeObj <T>(JSONSerializedElement obj, params object[] constructorArgs) where T : class
        {
            if (!obj.typeInfo.IsValid() || string.IsNullOrEmpty(obj.JSONnodeData))
            {
                return(null);
            }

            var type = GetTypeFromSerializedString(obj.typeInfo);

            if (type == null)
            {
                Debug.LogWarningFormat("Could not find node of type {0} in loaded assemblies", obj.typeInfo.SearchString());
                return(null);
            }

            T instance;

            try
            {
                instance = Activator.CreateInstance(type, constructorArgs) as T;
            }
            catch (Exception e)
            {
                Debug.LogWarningFormat("Could not construct instance of: {0} - {1}", type, e);
                return(null);
            }

            if (instance != null)
            {
                JsonUtility.FromJsonOverwrite(obj.JSONnodeData, instance);
                return(instance);
            }

            return(null);
        }
        public static T Deserialize <T>(JSONSerializedElement item, Dictionary <TypeSerializationInfo, TypeSerializationInfo> remapper, params object[] constructorArgs) where T : class
        {
            if (!item.typeInfo.IsValid() || string.IsNullOrEmpty(item.JSONnodeData))
            {
                throw new ArgumentException(string.Format("Can not deserialize {0}, it is invalid", item));
            }

            TypeSerializationInfo info = item.typeInfo;

            info.fullName = info.fullName.Replace("UnityEngine.MaterialGraph", "UnityEditor.ShaderGraph");
            info.fullName = info.fullName.Replace("UnityEngine.Graphing", "UnityEditor.Graphing");
            if (remapper != null)
            {
                info = DoTypeRemap(info, remapper);
            }

            var type = GetTypeFromSerializedString(info);

            if (type == null)
            {
                throw new ArgumentException(string.Format("Can not deserialize ({0}), type is invalid", info.fullName));
            }

            T instance;

            try
            {
                var culture = CultureInfo.CurrentCulture;
                var flags   = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
                instance = Activator.CreateInstance(type, flags, null, constructorArgs, culture) as T;
            }
            catch (Exception e)
            {
                throw new Exception(string.Format("Could not construct instance of: {0}", type), e);
            }

            if (instance != null)
            {
                JsonUtility.FromJsonOverwrite(item.JSONnodeData, instance);
                return(instance);
            }
            return(null);
        }
 public static T Deserialize <T>(JSONSerializedElement item, Dictionary <TypeSerializationInfo, TypeSerializationInfo> remapper, params object[] constructorArgs) where T : class
 {
     return(Deserialize <T>(item.JSONnodeData, item.typeInfo, remapper, constructorArgs));
 }