本文整理汇总了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));
}
示例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;
}
}
示例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");
}
}
示例4: GetObjectData
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.SetType(typeof(SerializablePhotonPlayer));
info.AddValue("ID", ID);
}
示例5:
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) {
info.SetType(typeof(SingletonSerializationHelper));
// No other values need to be added
}