本文整理汇总了C#中System.Runtime.Serialization.DataContractResolver.TryResolveType方法的典型用法代码示例。如果您正苦于以下问题:C# DataContractResolver.TryResolveType方法的具体用法?C# DataContractResolver.TryResolveType怎么用?C# DataContractResolver.TryResolveType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Runtime.Serialization.DataContractResolver
的用法示例。
在下文中一共展示了DataContractResolver.TryResolveType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryResolveType
public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver,
out System.Xml.XmlDictionaryString typeName,
out System.Xml.XmlDictionaryString typeNamespace)
{
if (type == null)
throw new ArgumentNullException("type");
if (declaredType == null)
throw new ArgumentNullException("declaredType");
if (knownTypeResolver == null)
throw new ArgumentNullException("knownTypeResolver");
if (knownTypeResolver.TryResolveType(type, declaredType, knownTypeResolver, out typeName, out typeNamespace))
return true;
if (type.IsPrimitive && declaredType == typeof(object))
{
return knownTypeResolver.TryResolveType(type, type, knownTypeResolver, out typeName, out typeNamespace);
}
XmlDictionary dict = new XmlDictionary();
typeNamespace = dict.Add(xmlNamespace);
typeName = dict.Add(type.AssemblyQualifiedName);
return true;
}
示例2: TryResolveType
public override bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
{
var res = knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace);
if (res)
return res;
System.Reflection.Assembly asm = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(p => p == dataContractType.Assembly);
if (asm != null)
{
XmlDictionary dictionary = new XmlDictionary();
typeName = dictionary.Add(dataContractType.Name);
typeNamespace = dictionary.Add("http://tempuri.com/" + asm.FullName);
return true;
}
foreach (IPlugin plugin in PluginHelper.plugins.Values)
{
if (plugin.GetType().Assembly == dataContractType.Assembly){
XmlDictionary dictionary = new XmlDictionary();
typeName = dictionary.Add(dataContractType.Name);
typeNamespace = dictionary.Add("http://tempuri.com/"+ plugin.Name);
return true;
}
}
return false;
}
示例3: TryResolveType
public override bool TryResolveType(
Type type, Type declaredType, DataContractResolver knownTypeResolver,
out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
{
// bool r = false;
// if (declaredType.IsSubclassOf(typeof(System.Linq.IQueryable)))
// {
// typeName = _typeDictionary.Add(type.Name);
// typeNamespace = _typeDictionary.Add(type.Namespace);
// r = true;
// }
// else
// {
if (!type.IsPrimitive)
{
typeName = _typeDictionary.Add(GetTypeName(type));
typeNamespace = _typeDictionary.Add(type.Namespace);
// r = true;
// }
// if (r)
// {
string typeKey = typeName + "." + typeNamespace;
if (!_typeNames.ContainsKey(typeKey))
_typeNames.Add(typeKey, type);
return true;
}
else
return knownTypeResolver.TryResolveType(type, declaredType, knownTypeResolver, out typeName, out typeNamespace);
}
示例4: TryResolveType
public override bool TryResolveType (Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
{
//Console.WriteLine ("TryResolveType: {0} {1}", type, declaredType);
if (knownTypeResolver.TryResolveType (type, declaredType, null, out typeName, out typeNamespace))
return true;
return SafeResolveType (type, out typeName, out typeNamespace);
}
示例5: TryResolveType
public override bool TryResolveType(
Type type,
Type declaredType,
DataContractResolver knownTypeResolver,
out XmlDictionaryString typeName,
out XmlDictionaryString typeNamespace)
{
if (!MessageType.AllKnownTypes.Contains(type))
{
typeName = null;
typeNamespace = null;
return false;
}
knownTypeResolver.TryResolveType(
type, declaredType, knownTypeResolver, out typeName, out typeNamespace);
if (this.NamespaceShouldBeReplaced(typeNamespace))
{
typeName = new XmlDictionaryString(XmlDictionary.Empty, type.Name, 0);
typeNamespace = new XmlDictionaryString(XmlDictionary.Empty, type.Namespace, 0);
}
return true;
}
示例6: TryResolveType
public override bool TryResolveType(Type type, Type declaredType,
DataContractResolver knownTypeResolver,
out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
{
if (knownTypeResolver.TryResolveType(type, declaredType,
null, out typeName, out typeNamespace))
return true;
string typeNameString = null;
if (Resolver.IsCollection(type))
{
TryGetCollectionTypeName(type, knownTypeResolver, out typeNameString);
}
else if (Resolver.IsArray(type))
{
TryGetArrayTypeName(type, knownTypeResolver, out typeNameString);
}
if (typeNameString != null)
{
typeNamespace = new XmlDictionaryString(XmlDictionary.Empty, Namespaces.DEFAULT, 0);
typeName = new XmlDictionaryString(XmlDictionary.Empty, typeNameString, 0);
return true;
}
return false;
}
示例7: TryResolveType
public override bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
{
var result = knownTypeResolver.TryResolveType(dataContractType, declaredType, knownTypeResolver, out typeName, out typeNamespace);
if (!result)
return true;
return result;
}
示例8: TryResolveType
/// <summary>
/// Override this method to map a data contract type to an xsi:type name and namespace during serialization.
/// </summary>
/// <param name="type">The type to map.</param>
/// <param name="declaredType">The type declared in the data contract.</param>
/// <param name="knownTypeResolver">The known type resolver.</param>
/// <param name="typeName">The xsi:type name.</param>
/// <param name="typeNamespace">The xsi:type namespace.</param>
/// <returns>
/// true if mapping succeeded; otherwise, false.
/// </returns>
public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out System.Xml.XmlDictionaryString typeName, out System.Xml.XmlDictionaryString typeNamespace)
{
if (type == typeof(Tag))
{
XmlDictionary dictionary = new XmlDictionary();
typeName = dictionary.Add("Tag");
typeNamespace = dictionary.Add(uri);
return true;
}
else if (type == typeof(Entry))
{
XmlDictionary dictionary = new XmlDictionary();
typeName = dictionary.Add("Entry");
typeNamespace = dictionary.Add(uri);
return true;
}
else if (type == typeof(LinkEntry))
{
XmlDictionary dictionary = new XmlDictionary();
typeName = dictionary.Add("LinkEntry");
typeNamespace = dictionary.Add(uri);
return true;
}
else if (type == typeof(LinkItem))
{
XmlDictionary dictionary = new XmlDictionary();
typeName = dictionary.Add("LinkItem");
typeNamespace = dictionary.Add(uri);
return true;
}
else
return knownTypeResolver.TryResolveType(type, declaredType, knownTypeResolver, out typeName, out typeNamespace);
}
示例9: TryResolveType
// Serialization
public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out System.Xml.XmlDictionaryString typeName, out System.Xml.XmlDictionaryString typeNamespace)
{
Type[] genericTypes = type.GetGenericArguments();
string ns = string.Empty;
Type genericType = null;
foreach (Type genType in genericTypes)
{
if (typesByType.ContainsKey(genType) == true)
{
typesByType.TryGetValue(genType, out ns);
genericType = genType;
break;
}
}
if (string.IsNullOrEmpty(ns) == false)
{
XmlDictionary dictionary = new XmlDictionary();
typeName = dictionary.Add(genericType.Name);
typeNamespace = dictionary.Add(ns);
return true;
}
else
{
return knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace);
}
}
示例10: TryResolveType
public override bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
{
if (!knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace))
{
XmlDictionary dictionary = new XmlDictionary();
typeName = dictionary.Add(dataContractType.FullName);
typeNamespace = dictionary.Add(dataContractType.Assembly.FullName);
}
return true;
}
示例11: TryResolveType
public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver,
out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
{
if (!knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace))
{
typeName = new XmlDictionaryString(XmlDictionary.Empty, type.Name, 0);
typeNamespace = new XmlDictionaryString(XmlDictionary.Empty, type.Namespace, 0);
}
return true;
}
示例12: TryResolveType
public override bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
{
if (Identity.ContainsKey(dataContractType))
{
var dictionary = new XmlDictionary();
typeName = dictionary.Add(Identity[dataContractType]);
typeNamespace = dictionary.Add(dataContractType.FullName);
return true;
}
// Defer to the known type resolver
return knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace);
}
示例13: TryResolveType
public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
{
if (type.Assembly.GetName().Name == DynamicTypeBuilder.AssemblyName)
{
XmlDictionary dic = new XmlDictionary();
typeName = dic.Add(type.Name);
typeNamespace = dic.Add(ResolverNamespace);
return true;
}
else
{
return knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace);
}
}
示例14: TryResolveType
// These methods are necessary for standard .Net serialisation
// For JSon we use different means, have a look in JsonBinSerializer for its custom Json.NET handler.
public override bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
{
if (TypeIdentity.Instance.ContainsKey(dataContractType))
{
XmlDictionary dictionary = new XmlDictionary();
typeName = dictionary.Add(TypeIdentity.Instance[dataContractType].Alias);
typeNamespace = dictionary.Add(dataContractType.FullName);
return true; // indicating that this resolver knows how to handle
}
else
{
// Defer to the known type resolver
return knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace);
}
}
示例15: TryResolveType
public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out System.Xml.XmlDictionaryString typeName, out System.Xml.XmlDictionaryString typeNamespace)
{
Debug.WriteLine("TryResolveType ", type.Name);
var retVal = _typeToNames.ContainsKey(type);
if (retVal)
{
XmlDictionary dictionary = new XmlDictionary();
typeNamespace = dictionary.Add(_typeToNames[type].Item1);
typeName = dictionary.Add(_typeToNames[type].Item2);
}
else
{
retVal = knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace);
}
return retVal;
}