Как превратить экземпляр Типа в общий аргумент типа

Этот код абсолютно неверен. Это трудно исправить, потому что объединяет несколько ошибок в одном процессе.

Я попытаюсь перечислить некоторые из ваших ошибок:

  1. Список чувствительности не должен использовать output и reset_done.
  2. output <= output + 1; не могут быть синтезированы или создадут бесконечный цикл в симуляции
  3. , вам нужно разделить комбинационную и последовательную логику на два процесса
  4. reset_done и reset_cnt бесполезны, поскольку они всегда '1'
  5. reset_cnt является целым числом, это не может быть AND с булевым значением из выражения counter = 24
  6. никогда не писать output <= output;
[ 1118] Я предлагаю изучить комбинационные и последовательные процессы, а также шаблоны кодирования для VHDL.

9
задан Rytmis 13 May 2009 в 08:54
поделиться

5 ответов

If ty is known at compile-time, why don't just

void Foo<T>()
{
    var result = serializer.Deserialize<T>(inputContext);
}

Otherwise,

MethodInfo genericDeserializeMethod = serializer.GetType().GetMethod("Deserialize");
MethodInfo closedDeserializeMethod = genericDeserializeMethod.MakeGenericMethod(ty);
closedDeserializeMethod.Invoke(serializer, new object[] { inputContext });
6
ответ дан 4 December 2019 в 12:20
поделиться

Используйте

void Foo<T>(){ var result = serializer.Deserialize<T>(inputContent); }

со следующим вызовом

Foo<Person>();
2
ответ дан 4 December 2019 в 12:20
поделиться

Which serializer is that? If you only know the Type at runtime (not compile time), and it doesn't have a non-generic API, then you might have to use MakeGenericMethod:

void Foo(Type ty)
{
    object result = typeof(ContainingClass).GetMethod("Bar").
        .MakeGenericMethod(ty).Invoke(null, new object[] {inputContent});
}
public static T Bar<T>(SomeType inputContent) {
    return serializer.Deserialize<T>(inputContent);
}
7
ответ дан 4 December 2019 в 12:20
поделиться

In this case, just do this:

void Foo<ty>()
{
    var result = serializer.Deserialize<ty>(inputContent);
}

Foo<Person>();

Otherwise, you need to call the generic method late-bound, since you have to get the correct generic method for it first (it is not known at compile time). Have a look at the MethodInfo.MakeGenericMethod method.

1
ответ дан 4 December 2019 в 12:20
поделиться

Like Lucero said,

void Foo<ty>()
{
    var result = serializer.Deserialize<ty>(inputContent);
}

Foo<Person>();

typeof(Person) is not the same thing as Person. Person is a compile-time type, whereas typeof(Person) is an expression that returns a Type instance representing the runtime type information of Person.

1
ответ дан 4 December 2019 в 12:20
поделиться
Другие вопросы по тегам:

Похожие вопросы: