本文整理汇总了C#中System.Runtime.Serialization.DataContractResolver.ResolveName方法的典型用法代码示例。如果您正苦于以下问题:C# DataContractResolver.ResolveName方法的具体用法?C# DataContractResolver.ResolveName怎么用?C# DataContractResolver.ResolveName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Runtime.Serialization.DataContractResolver
的用法示例。
在下文中一共展示了DataContractResolver.ResolveName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolveName
public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
{
if (!typeNamespace.StartsWith("http://tempuri.com"))
{
return knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, null);
}
string PluginName = typeNamespace.Substring("http://tempuri.com".Length + 1);
System.Reflection.Assembly asm = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(p => p.FullName == PluginName);
var t = asm.GetTypes().Where(p => p.GetCustomAttributes(typeof(DataContractAttribute), false).Length > 0).FirstOrDefault(p => p.Name == typeName);
if (t != null)
return t;
return knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, null);
}
示例2: ResolveName
/// <summary>
/// Tries to get a type by name.
/// Is used for deserialization.
/// Gets called by the framework.
/// </summary>
/// <param name="typeName"></param>
/// <param name="typeNamespace"></param>
/// <param name="declaredType"></param>
/// <param name="knownTypeResolver"></param>
/// <returns></returns>
public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
{
Logger.Debug(String.Format("BusDataContractResolver: ResolveName(typeName='{0}', typeNamespace='{1}', declaredType='{2}')", typeName, typeNamespace, declaredType.FullName));
Type type = ServiceHelper.GetServiceValidType(typeName);
if (type == null)
{
Logger.Debug(String.Format("BusDataContractResolver: ResolveName() got invalid type: '{0}'. Trying to get it from declared type: '{1}'.", typeName, declaredType.FullName));
if (ServiceHelper.IsServiceValidType(declaredType))
{
Logger.Warn(String.Format("BusDataContractResolver: ResolveName() was successful using declared type: '{0}.", declaredType));
type = declaredType;
}
}
if(type != null)
{
Logger.Debug(String.Format("BusDataContractResolver: ResolveName() got valid type: '{0}'.", typeName));
return type;
}
Logger.Error(String.Format("BusDataContractResolver: ResolveName() got invalid type: '{0}'.", typeName));
return knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, null);
}
示例3: ResolveName
public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
{
if (!typeNamespace.StartsWith("http://tempuri.com"))
{
return knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, null);
}
string PluginName = typeNamespace.Substring("http://tempuri.com".Length);
IPlugin plugin = PluginHelper.plugins[PluginName];
var lst = plugin.GetType().Assembly.GetTypes().Where(p => p.GetCustomAttributes(typeof(DataContractAttribute), false).Length > 0).ToList();
var t = lst.FirstOrDefault(p => p.Name == typeName);
if (t != null)
return t;
return knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, null);
}
示例4: ResolveName
public override Type ResolveName(string typeName, string typeNamespace, Type declaredType,
DataContractResolver knownTypeResolver)
{
Type type;
int deserializationIndex;
int poundIndex = typeNamespace.IndexOf("#");
if (poundIndex < 0)
{
if (Int32.TryParse(typeNamespace, out deserializationIndex))
{
deserializationDictionary.TryGetValue(deserializationIndex, out typeNamespace);
}
type = knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, null);
}
else
{
if (Int32.TryParse(typeNamespace.Substring(0, poundIndex), out deserializationIndex))
{
typeNamespace = typeNamespace.Substring(poundIndex + 1, typeNamespace.Length - poundIndex - 1);
deserializationDictionary.Add(deserializationIndex, typeNamespace);
}
type = knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, null);
}
return type;
}
示例5: ResolveName
public override Type ResolveName(string typeName, string typeNamespace, Type declaredType,
DataContractResolver knownTypeResolver)
{
if (declaredType == null)
throw new ArgumentNullException("declaredType");
if (knownTypeResolver == null)
throw new ArgumentNullException("knownTypeResolver");
var type = knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, knownTypeResolver);
if (type != null)
return type;
Debug.Print(typeNamespace);
Debug.Print(typeName);
type = Type.GetType(typeName);
if (type != null)
return type;
int lastSlashIndex = typeNamespace.LastIndexOf("/");
if (lastSlashIndex >= 0)
{
string ns = typeNamespace.Substring(lastSlashIndex + 1);
return Type.GetType(string.Format(CultureInfo.InvariantCulture, "{0}.{1}, {0}", ns, typeName));
}
return null;
}
示例6: ResolveName
public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
{
DbHelpers.ThrowIfNullOrWhitespace(typeName, "typeName");
DbHelpers.ThrowIfNullOrWhitespace(typeNamespace, "typeNamespace");
DbHelpers.ThrowIfNull(declaredType, "declaredType");
DbHelpers.ThrowIfNull(knownTypeResolver, "knownTypeResolver");
return knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, null);
}
示例7: ResolveName
/// <summary>During deserialization, maps any xsi:type information to the actual type of the persistence-ignorant object. </summary>
/// <returns>Returns the type that the xsi:type is mapped to. Returns null if no known type was found that matches the xsi:type.</returns>
/// <param name="typeName">The xsi:type information to map.</param>
/// <param name="typeNamespace">The namespace of the xsi:type.</param>
/// <param name="declaredType">The declared type.</param>
/// <param name="knownTypeResolver">
/// An instance of <see cref="T:System.Data.Entity.Core.Objects.ProxyDataContractResolver" />.
/// </param>
public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
{
Check.NotEmpty(typeName, "typeName");
Check.NotEmpty(typeNamespace, "typeNamespace");
Check.NotNull(declaredType, "declaredType");
Check.NotNull(knownTypeResolver, "knownTypeResolver");
return knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, null);
}
示例8: ResolveName
// Used at deserialization
// Allows users to map xsi:type name to any Type
public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
{
Type type = knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, null);
if (type == null)
{
type = Type.GetType(typeName + ", " + typeNamespace);
}
return type;
}
示例9: ResolveName
public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
{
EntityUtil.CheckStringArgument(typeName, "typeName");
EntityUtil.CheckStringArgument(typeNamespace, "typeNamespace");
EntityUtil.CheckArgumentNull(declaredType, "declaredType");
EntityUtil.CheckArgumentNull(knownTypeResolver, "knownTypeResolver");
return knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType ,null);
}
示例10: ResolveName
/// <summary>
/// Resolves a type name to a managed type
/// </summary>
/// <param name="name">
/// The name of the type to resolve
/// </param>
/// <param name="ns">
/// The named type's namespace
/// </param>
/// <param name="declared">
/// Teh declared parameter type
/// </param>
/// <param name="knownTypes">
/// The base known type resolver
/// </param>
/// <returns>
/// The resolved managed type
/// </returns>
public override Type ResolveName(
String name,
String ns,
Type declared,
DataContractResolver knownTypes)
{
return
knownTypes.ResolveName(name, ns, declared, null) ??
Resolve(ns, name, declared);
}
示例11: ResolveName
/// <summary>
/// Override this method to map the specified xsi:type name and namespace to a data contract type during deserialization.
/// </summary>
/// <param name="typeName">The xsi:type name to map.</param>
/// <param name="typeNamespace">The xsi:type namespace to map.</param>
/// <param name="declaredType">The type declared in the data contract.</param>
/// <param name="knownTypeResolver">The known type resolver.</param>
/// <returns>
/// The type the xsi:type name and namespace is mapped to.
/// </returns>
public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
{
if (typeName == "Tag" && typeNamespace == uri)
return typeof(Tag);
else if (typeName == "Entry" && typeNamespace == uri)
return typeof(Entry);
else if (typeName == "LinkEntry" && typeNamespace == uri)
return typeof(LinkEntry);
else if (typeName == "LinkItem" && typeNamespace == uri)
return typeof(LinkItem);
else return knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, null);
}
示例12: ResolveName
public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
{
if (typeNamespace == ResolverNamespace)
{
Type result = DynamicTypeBuilder.Instance.GetDynamicType(typeName);
if (result != null)
{
return result;
}
}
return knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, null);
}
示例13: ResolveName
public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
{
if (string.Compare(typeNamespace, _xmlNamespace, StringComparison.OrdinalIgnoreCase) == 0)
{
Assembly containingAssembly;
if (_typeToAssemblyLookup.TryGetValue(typeName, out containingAssembly))
{
var type = containingAssembly.GetType(typeName);
if (type != null) return type;
}
}
return knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, null);
}
示例14: ResolveName
public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
{
Type type = null;
try
{
type = knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, null);
}
catch (Exception)
{
throw;
}
return type ?? declaredType;
}
示例15: ResolveName
// Used at deserialization
// Allows users to map xsi:type name to any Type
public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
{
XmlDictionaryString tName;
XmlDictionaryString tNamespace;
// If the type is found in the dictionary then extract it from the assembly. Use the default KnownTypeResolver otherwise.
if (dictionary.TryLookup(typeName, out tName) && dictionary.TryLookup(typeNamespace, out tNamespace))
{
return this.assembly.GetType(tNamespace.Value + "." + tName.Value);
}
else
{
return knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, null);
}
}