请纠正我,对我来说听起来像Serializer.PrepareSerializer和RuntTimeTypeModel.CompileInPlace做同样的事情?
他们字面意思是一样的:
在通用的Serializer
API中,我们有:
/// <summary>
/// Precompiles the serializer for a given type.
/// </summary>
public static void PrepareSerializer<T>()
{
NonGeneric.PrepareSerializer(typeof(T));
}
在非通用的Serializer
API中:
/// <summary>
/// Precompiles the serializer for a given type.
/// </summary>
public static void PrepareSerializer(Type t)
{
#if FEAT_COMPILER
RuntimeTypeModel model = RuntimeTypeModel.Default;
model[model.MapType(t)].CompileInPlace();
#endif
}
这里的主要区别是PrepareSerializer
是一个v1 API,而在v1中只有一个“模型”(即一组运行时配置数据),并且只有一个编译机制。在v2中,这扩展了一些 - 所以v1 API现在只在默认的“模型”上调用CompileInPlace
。
(MapType
是不相关的东西,它与一些不再存在的代码联系在一起; MapType
已经在一个未合并的分支中被完全删除)