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


C# SerializationInfo.SetType方法代码示例

本文整理汇总了C#中SerializationInfo.SetType方法的典型用法代码示例。如果您正苦于以下问题:C# SerializationInfo.SetType方法的具体用法?C# SerializationInfo.SetType怎么用?C# SerializationInfo.SetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SerializationInfo的用法示例。


在下文中一共展示了SerializationInfo.SetType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetObjectData

        /// <summary>
        /// Support for <see cref="ISerializable"/>.
        /// </summary>
        public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            if (info == null)
            {
                throw PSTraceSource.NewArgumentNullException("info");
            }

            string serializedContent = this.ToString();
            info.AddValue("ScriptText", serializedContent);
            info.SetType(typeof(ScriptBlockSerializationHelper));
        }
开发者ID:40a,项目名称:PowerShell,代码行数:14,代码来源:CompiledScriptBlock.cs

示例2: runTest

	public bool runTest()
	{
		Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer);
		int iCountErrors = 0;
		int iCountTestcases = 0;
		String strLoc = "Loc_000oo";
		SerializationInfo serinfo1 = null;
		Type type = null;
		String strValue;
		try {
			type = typeof(Int32);
			serinfo1 = new SerializationInfo(type, new FormatterConverter());
			iCountTestcases++;
			if(!type.FullName.Equals(serinfo1.FullTypeName)){
				iCountErrors++;
				Console.WriteLine("Err_0256csd! Wrong type long name, " + serinfo1.FullTypeName + " " + type.FullName);
			}
			type = typeof(String);
			serinfo1.SetType(type);
			if(!type.FullName.Equals(serinfo1.FullTypeName)){
				iCountErrors++;
				Console.WriteLine("Err_39745sg! Wrong type long name, " + serinfo1.FullTypeName + " " + type.FullName);
			}
			type = typeof(System.Runtime.Serialization.SerializationInfo);
			serinfo1.SetType(type);
			iCountTestcases++;
			if(!type.FullName.Equals(serinfo1.FullTypeName)){
				iCountErrors++;
				Console.WriteLine("Err_02346fsd! Wrong type name, " + serinfo1.FullTypeName + " " + type.FullName);
			}
			type = typeof(UserDefined);
			serinfo1.SetType(type);
			iCountTestcases++;
			if(!serinfo1.FullTypeName.Equals("UserDefined")){
				iCountErrors++;
				Console.WriteLine("Err_02346fsd! Wrong type name, " + serinfo1.FullTypeName + " " + type.FullName);
			}
			if(serinfo1.AssemblyName.IndexOf("co8634settype_type")<0){
				iCountErrors++;
				Console.WriteLine("Err_02346fsd! Wrong type name, " + serinfo1.FullTypeName + " " + serinfo1.AssemblyName);
			}
			iCountTestcases++;
			try{
				serinfo1.SetType(null);
				iCountErrors++;
				Console.WriteLine("Err_39475sdg! Exception not thrown");
			}catch(ArgumentException){
			}catch(Exception ex){
				iCountErrors++;
				Console.WriteLine("Err_39475sdg! Wrong Exception thrown" + ex.GetType().Name);
			}
		} catch (Exception exc_general ) {
			++iCountErrors;
			Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general==\n"+exc_general.StackTrace);
		}
		if ( iCountErrors == 0 )
		{
			Console.WriteLine( "paSs.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
			return true;
		}
		else
		{
			Console.WriteLine("FAiL!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
			return false;
		}
	}
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:66,代码来源:co8634settype_type.cs

示例3: GetObjectData

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            if (context.State == StreamingContextStates.CrossAppDomain)
            {
                GenericIdentity gIdent = new GenericIdentity(this.Name, this.AuthenticationType);
                info.SetType(gIdent.GetType());

                System.Reflection.MemberInfo[] serializableMembers;
                object[] serializableValues;

                serializableMembers = FormatterServices.GetSerializableMembers(gIdent.GetType());
                serializableValues = FormatterServices.GetObjectData(gIdent, serializableMembers);

                for (int i = 0; i < serializableMembers.Length; i++)
                {
                    info.AddValue(serializableMembers[i].Name, serializableValues[i]);
                }
            }
            else
            {
                throw new InvalidOperationException("Serialization not supported");
            }
        }
开发者ID:kyallbarrows,项目名称:LifeguardServer,代码行数:23,代码来源:BaseController.cs

示例4: GetObjectData

 public void GetObjectData(SerializationInfo info, StreamingContext context)
 {
     info.SetType(typeof(SerializablePhotonPlayer));
     info.AddValue("ID", ID);
 }
开发者ID:EranYaacobi,项目名称:Centipede,代码行数:5,代码来源:PhotonPlayer.cs

示例5:

 void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) {
    info.SetType(typeof(SingletonSerializationHelper));
    // No other values need to be added
 }
开发者ID:Helen1987,项目名称:edu,代码行数:4,代码来源:Ch24-1-RuntimeSerialization.cs


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