Пример #1
0
        /// <summary>
        /// try to create an instance of an object with only it's type name
        /// returns null if the creation failed
        /// </summary>
        /// <param name="typeString"></param>
        /// <returns></returns>
        private static object TryCreateInstance(string typeString)
        {
            if (provider?.IsTypeStringValid(typeString) == true)
            {
                ICreatable creatableNode = provider.CreateFromTypeString(typeString);
                //CreatableNode creatableNode = CreatableNode.CreateDynamic(FindFileWithName(typeString));
                if (creatableNode == null)
                {
#if LOGGER
                    Logger.WriteLine("coudln't create CreatableNode python object");
#endif
                    return(null);
                }
                return(creatableNode.CreateInstance());
            }
            else
            {
                Type type = Type.GetType(typeString);
                if (type != null)
                {
                    return(TryCreateInstance(type));
                }
                else
                {
#if LOGGER
                    Logger.WriteLine("couldn't create type from string:" + typeString);
#endif
                    return(null);
                }
            }
        }