当前位置: 首页>>代码示例>>C#>>正文


C# DataContractResolver.TryResolveType方法代码示例

本文整理汇总了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;
		}
开发者ID:aries544,项目名称:eXpand,代码行数:27,代码来源:XpandDataContractResolver.cs

示例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;
        }
开发者ID:amoraller,项目名称:AptekaAutoOrder,代码行数:25,代码来源:MyDataContractResolver.cs

示例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);
        }
开发者ID:jbowwww,项目名称:ArtefactService,代码行数:29,代码来源:WCFTypeResolver.cs

示例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);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:DataContractResolverTest.cs

示例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;
        }
开发者ID:paulkearney,项目名称:brnkly,代码行数:25,代码来源:BusReceiverDataContractResolver.cs

示例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;
        }
开发者ID:sunoru,项目名称:PBO,代码行数:26,代码来源:Resolver.cs

示例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; 
		}
开发者ID:fstn,项目名称:WindowsPhoneApps,代码行数:7,代码来源:NullEntityCollectionSerializerAttribute.cs

示例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);
 }
开发者ID:StevenLaw,项目名称:DataBox,代码行数:44,代码来源:DataboxResolver.cs

示例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);
            }
        }
开发者ID:PeaceCode,项目名称:Elasticity,代码行数:31,代码来源:SchedulerTaskDataContractResolver.cs

示例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;
 }
开发者ID:BredStik,项目名称:WindsorWcfIntegration,代码行数:10,代码来源:SharedTypeResolver.cs

示例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;
        }
开发者ID:BrettJaner,项目名称:solidservices,代码行数:11,代码来源:KnownTypesDataContractResolver.cs

示例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);
        }
开发者ID:smakhtin,项目名称:vvvv-Message,代码行数:13,代码来源:MessageResolver.cs

示例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);
     }
 }
开发者ID:GusLab,项目名称:WCFSamples,代码行数:14,代码来源:DynamicTypeResolver.cs

示例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);
     }
 }
开发者ID:velcrome,项目名称:vvvv-Message,代码行数:17,代码来源:MessageResolver.cs

示例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;
		}
开发者ID:gitter-badger,项目名称:vc-community-1.x,代码行数:17,代码来源:ContractResolver.cs


注:本文中的System.Runtime.Serialization.DataContractResolver.TryResolveType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。