System.Runtime.Serialization.Formatters.Binary.BinaryCommon.CheckSerializable C# (CSharp) Method

CheckSerializable() public static method

public static CheckSerializable ( Type type, ISurrogateSelector selector, StreamingContext context ) : void
type System.Type
selector ISurrogateSelector
context StreamingContext
return void
		public static void CheckSerializable (Type type, ISurrogateSelector selector, StreamingContext context)
		{
			if (!type.IsSerializable && !type.IsInterface) 
			{
				if (selector != null && selector.GetSurrogate (type, context, out selector) != null)
					return;

				throw new SerializationException ("Type " + type + " is not marked as Serializable.");
			}
		}
		

Usage Example

示例#1
0
 public void WriteValue(BinaryWriter writer, Type valueType, object val)
 {
     if (val == null)
     {
         BinaryCommon.CheckSerializable(valueType, this._surrogateSelector, this._context);
         writer.Write(10);
     }
     else if (BinaryCommon.IsPrimitive(val.GetType()))
     {
         if (!BinaryCommon.IsPrimitive(valueType))
         {
             writer.Write(8);
             this.WriteTypeSpec(writer, val.GetType());
         }
         ObjectWriter.WritePrimitiveValue(writer, val);
     }
     else if (valueType.IsValueType)
     {
         this.WriteObjectInstance(writer, val, true);
     }
     else if (val is string)
     {
         bool flag;
         long id = this._idGenerator.GetId(val, out flag);
         if (flag)
         {
             this.WriteObjectInstance(writer, val, false);
         }
         else
         {
             this.WriteObjectReference(writer, id);
         }
     }
     else
     {
         bool flag2;
         long id2 = this._idGenerator.GetId(val, out flag2);
         if (flag2)
         {
             this._pendingObjects.Enqueue(val);
         }
         this.WriteObjectReference(writer, id2);
     }
 }
All Usage Examples Of System.Runtime.Serialization.Formatters.Binary.BinaryCommon::CheckSerializable