我正在使用自定义DataContractResolver
public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
{
Type knownType = knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, null);
if (knownType != null)
{
return knownType;
}...
同样的情况是使用TryResolve方法(我不需要)
public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
{
return knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace);
Resharper告诉我,最后一个参数不应为null,因为它标有[NotNull]
属性。
ResolveName方法也被System.Runtime.Serialization.KnownTypeDataContractResolver
类覆盖。
这是实施:
public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
{
if (typeName == null || typeNamespace == null)
return (Type) null;
else
return this.context.ResolveNameFromKnownTypes(new XmlQualifiedName(typeName, typeNamespace));
}
甚至没有使用参数knownTypeResolver
!
我看到的所有例子都像我一样使用它。 什么是正确的实施?