这就是我想要做的事情
2017-06-14 19:11:00] local.ERROR: ReflectionException: Class UserTablesSeeder does not exist in /var/www/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:749
Stack trace:
#0 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(749): ReflectionClass->__construct('UserTablesSeede...')
#1 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(644): Illuminate\Container\Container->build('UserTablesSeede...', Array)
#2 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(709): Illuminate\Container\Container->make('UserTablesSeede...', Array)
#3 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Seeder.php(55): Illuminate\Foundation\Application->make('UserTablesSeede...')
#4 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Seeder.php(43): Illuminate\Database\Seeder->resolve('UserTablesSeede...')
#5 /var/www/laravel/database/seeds/DatabaseSeeder.php(14): Illuminate\Database\Seeder->call('UserTablesSeede...')
#6 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php(63): DatabaseSeeder->run()
#7 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(2292): Illuminate\Database\Console\Seeds\SeedCommand->Illuminate\Database\Console\Seeds\{closure}()
#8 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php(64): Illuminate\Database\Eloquent\Model::unguarded(Object(Closure))
#9 [internal function]: Illuminate\Database\Console\Seeds\SeedCommand->fire()
#10 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(508): call_user_func_array(Array, Array)
#11 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php(169): Illuminate\Container\Container->call(Array)
#12 /var/www/laravel/vendor/symfony/console/Command/Command.php(261): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/laravel/vendor/symfony/console/Application.php(817): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /var/www/laravel/vendor/symfony/console/Application.php(185): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Database\Console\Seeds\SeedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /var/www/laravel/vendor/symfony/console/Application.php(116): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(121): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /var/www/laravel/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 {main}
转换函数需要知道如何从MyEnumType中的内容到实际的,声明的枚举,并且适用于传递的任何类型。编译时间转换是不可能的。
编辑:我想创建一个函数“Convert”,它将接受两个字符串 - 一个命名枚举类型的字符串和一个枚举值的字符串。它不会特定于任何给定的枚举类型。该函数将枚举值返回给该类型的变量。
这是可行的还是我只是在做梦?
答案 0 :(得分:0)
如果您可以提供枚举的完全限定名称空间,则可以使用所提到的Enum.Parse。
public enum SpaghettiDiameter
{
Value1,
NEEDS_ALL_SAUCE
}
class Program
{
static void Main(string[] args)
{
string MyEnumType = "TestAppCore.SpaghettiDiameter";
string MyEnumValue = "NEEDS_ALL_SAUCE";
SpaghettiDiameter result = (SpaghettiDiameter)Enum.Parse(Type.GetType(MyEnumType), MyEnumValue);
}
}
答案 1 :(得分:0)
我在做梦。我不认为我在编辑中描述的内容是可行的。