SerializationInfo.AddValue Method

Definition

Adds a value into the SerializationInfo.

Overloads

AddValue(String, Object, Type)

Adds a value into the SerializationInfo store, where value is associated with name and is serialized as being of Typetype.

AddValue(String, UInt64)

Adds a 64-bit unsigned integer value into the SerializationInfo store.

AddValue(String, UInt32)

Adds a 32-bit unsigned integer value into the SerializationInfo store.

AddValue(String, UInt16)

Adds a 16-bit unsigned integer value into the SerializationInfo store.

AddValue(String, Single)

Adds a single-precision floating-point value into the SerializationInfo store.

AddValue(String, SByte)

Adds an 8-bit signed integer value into the SerializationInfo store.

AddValue(String, Object)

Adds the specified object into the SerializationInfo store, where it is associated with a specified name.

AddValue(String, Int64)

Adds a 64-bit signed integer value into the SerializationInfo store.

AddValue(String, Int32)

Adds a 32-bit signed integer value into the SerializationInfo store.

AddValue(String, Int16)

Adds a 16-bit signed integer value into the SerializationInfo store.

AddValue(String, Double)

Adds a double-precision floating-point value into the SerializationInfo store.

AddValue(String, Decimal)

Adds a decimal value into the SerializationInfo store.

AddValue(String, DateTime)

Adds a DateTime value into the SerializationInfo store.

AddValue(String, Char)

Adds a Unicode character value into the SerializationInfo store.

AddValue(String, Byte)

Adds an 8-bit unsigned integer value into the SerializationInfo store.

AddValue(String, Boolean)

Adds a Boolean value into the SerializationInfo store.

AddValue(String, Object, Type)

Source:
SerializationInfo.cs
Source:
SerializationInfo.cs
Source:
SerializationInfo.cs

Adds a value into the SerializationInfo store, where value is associated with name and is serialized as being of Typetype.

C#
public void AddValue(string name, object? value, Type type);
C#
public void AddValue(string name, object value, Type type);

Parameters

name
String

The name to associate with the value, so it can be deserialized later.

value
Object

The value to be serialized. Any children of this object will automatically be serialized.

type
Type

The Type to associate with the current object. This parameter must always be the type of the object itself or of one of its base classes.

Exceptions

If name or type is null.

A value has already been associated with name.

Remarks

The assigned type is always the type of the object, or one of its parents.

If two values are added with names that differ only by case, no exception will be thrown, which is not a recommended practice. However, adding two values with the exact same name will cause the SerializationException to be thrown.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AddValue(String, UInt64)

Source:
SerializationInfo.cs
Source:
SerializationInfo.cs
Source:
SerializationInfo.cs

Important

This API is not CLS-compliant.

Adds a 64-bit unsigned integer value into the SerializationInfo store.

C#
[System.CLSCompliant(false)]
public void AddValue(string name, ulong value);

Parameters

name
String

The name to associate with the value, so it can be deserialized later.

value
UInt64

The value to serialize.

Attributes

Exceptions

The name parameter is null.

A value has already been associated with name.

Remarks

If two values are added with names that differ only by case, no exception will be thrown, which is not a recommended practice. However, adding two values with the exact same name will cause the SerializationException to be thrown.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AddValue(String, UInt32)

Source:
SerializationInfo.cs
Source:
SerializationInfo.cs
Source:
SerializationInfo.cs

Important

This API is not CLS-compliant.

Adds a 32-bit unsigned integer value into the SerializationInfo store.

C#
[System.CLSCompliant(false)]
public void AddValue(string name, uint value);

Parameters

name
String

The name to associate with the value, so it can be deserialized later.

value
UInt32

The UInt32 value to serialize.

Attributes

Exceptions

The name parameter is null.

A value has already been associated with name.

Remarks

If two values are added with names that differ only by case, no exception will be thrown, which is not a recommended practice. However, adding two values with the exact same name will cause the SerializationException to be thrown.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AddValue(String, UInt16)

Source:
SerializationInfo.cs
Source:
SerializationInfo.cs
Source:
SerializationInfo.cs

Important

This API is not CLS-compliant.

Adds a 16-bit unsigned integer value into the SerializationInfo store.

C#
[System.CLSCompliant(false)]
public void AddValue(string name, ushort value);

Parameters

name
String

The name to associate with the value, so it can be deserialized later.

value
UInt16

The UInt16 value to serialize.

Attributes

Exceptions

The name parameter is null.

A value has already been associated with name.

Remarks

If two values are added with names that differ only by case, no exception will be thrown, which is not a recommended practice. However, adding two values with the exact same name will cause the SerializationException to be thrown.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AddValue(String, Single)

Source:
SerializationInfo.cs
Source:
SerializationInfo.cs
Source:
SerializationInfo.cs

Adds a single-precision floating-point value into the SerializationInfo store.

C#
public void AddValue(string name, float value);

Parameters

name
String

The name to associate with the value, so it can be deserialized later.

value
Single

The single value to serialize.

Exceptions

The name parameter is null.

A value has already been associated with name.

Remarks

If two values are added with names that differ only by case, no exception will be thrown, which is not a recommended practice. However, adding two values with the exact same name will cause the SerializationException to be thrown.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AddValue(String, SByte)

Source:
SerializationInfo.cs
Source:
SerializationInfo.cs
Source:
SerializationInfo.cs

Important

This API is not CLS-compliant.

Adds an 8-bit signed integer value into the SerializationInfo store.

C#
[System.CLSCompliant(false)]
public void AddValue(string name, sbyte value);

Parameters

name
String

The name to associate with the value, so it can be deserialized later.

value
SByte

The Sbyte value to serialize.

Attributes

Exceptions

The name parameter is null.

A value has already been associated with name.

Remarks

If two values are added with names that differ only by case, no exception will be thrown, which is not a recommended practice. However, adding two values with the exact same name will cause the SerializationException to be thrown.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AddValue(String, Object)

Source:
SerializationInfo.cs
Source:
SerializationInfo.cs
Source:
SerializationInfo.cs

Adds the specified object into the SerializationInfo store, where it is associated with a specified name.

C#
public void AddValue(string name, object? value);
C#
public void AddValue(string name, object value);

Parameters

name
String

The name to associate with the value, so it can be deserialized later.

value
Object

The value to be serialized. Any children of this object will automatically be serialized.

Exceptions

name is null.

A value has already been associated with name.

Remarks

The object contained in the value parameter is serialized as the type returned by value.

If two values are added with names that differ only by case, no exception will be thrown, which is not a recommended practice. However, adding two values with the exact same name will cause the SerializationException to be thrown.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AddValue(String, Int64)

Source:
SerializationInfo.cs
Source:
SerializationInfo.cs
Source:
SerializationInfo.cs

Adds a 64-bit signed integer value into the SerializationInfo store.

C#
public void AddValue(string name, long value);

Parameters

name
String

The name to associate with the value, so it can be deserialized later.

value
Int64

The Int64 value to serialize.

Exceptions

The name parameter is null.

A value has already been associated with name.

Remarks

If two values are added with names that differ only by case, no exception will be thrown, which is not a recommended practice. However, adding two values with the exact same name will cause the SerializationException to be thrown.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AddValue(String, Int32)

Source:
SerializationInfo.cs
Source:
SerializationInfo.cs
Source:
SerializationInfo.cs

Adds a 32-bit signed integer value into the SerializationInfo store.

C#
public void AddValue(string name, int value);

Parameters

name
String

The name to associate with the value, so it can be deserialized later.

value
Int32

The Int32 value to serialize.

Exceptions

The name parameter is null.

A value has already been associated with name.

Remarks

If two values are added with names that differ only by case, no exception will be thrown, which is not a recommended practice. However, adding two values with the exact same name will cause the SerializationException to be thrown.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AddValue(String, Int16)

Source:
SerializationInfo.cs
Source:
SerializationInfo.cs
Source:
SerializationInfo.cs

Adds a 16-bit signed integer value into the SerializationInfo store.

C#
public void AddValue(string name, short value);

Parameters

name
String

The name to associate with the value, so it can be deserialized later.

value
Int16

The Int16 value to serialize.

Exceptions

The name parameter is null.

A value has already been associated with name.

Remarks

If two values are added with names that differ only by case, no exception will be thrown, which is not a recommended practice. However, adding two values with the exact same name will cause the SerializationException to be thrown.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AddValue(String, Double)

Source:
SerializationInfo.cs
Source:
SerializationInfo.cs
Source:
SerializationInfo.cs

Adds a double-precision floating-point value into the SerializationInfo store.

C#
public void AddValue(string name, double value);

Parameters

name
String

The name to associate with the value, so it can be deserialized later.

value
Double

The double value to serialize.

Exceptions

The name parameter is null.

A value has already been associated with name.

Remarks

If two values are added with names that differ only by case, no exception will be thrown, which is not a recommended practice. However, adding two values with the exact same name will cause the SerializationException to be thrown.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AddValue(String, Decimal)

Source:
SerializationInfo.cs
Source:
SerializationInfo.cs
Source:
SerializationInfo.cs

Adds a decimal value into the SerializationInfo store.

C#
public void AddValue(string name, decimal value);

Parameters

name
String

The name to associate with the value, so it can be deserialized later.

value
Decimal

The decimal value to serialize.

Exceptions

If The name parameter is null.

If a value has already been associated with name.

Remarks

If two values are added with names that differ only by case, no exception will be thrown, which is not a recommended practice. However, adding two values with the exact same name will cause the SerializationException to be thrown.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AddValue(String, DateTime)

Source:
SerializationInfo.cs
Source:
SerializationInfo.cs
Source:
SerializationInfo.cs

Adds a DateTime value into the SerializationInfo store.

C#
public void AddValue(string name, DateTime value);

Parameters

name
String

The name to associate with the value, so it can be deserialized later.

value
DateTime

The DateTime value to serialize.

Exceptions

The name parameter is null.

A value has already been associated with name.

Remarks

If two values are added with names that differ only by case, no exception will be thrown, which is not a recommended practice. However, adding two values with the exact same name will cause the SerializationException to be thrown.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AddValue(String, Char)

Source:
SerializationInfo.cs
Source:
SerializationInfo.cs
Source:
SerializationInfo.cs

Adds a Unicode character value into the SerializationInfo store.

C#
public void AddValue(string name, char value);

Parameters

name
String

The name to associate with the value, so it can be deserialized later.

value
Char

The character value to serialize.

Exceptions

The name parameter is null.

A value has already been associated with name.

Remarks

If two values are added with names that differ only by case, no exception will be thrown, which is not a recommended practice. However, adding two values with the exact same name will cause the SerializationException to be thrown.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AddValue(String, Byte)

Source:
SerializationInfo.cs
Source:
SerializationInfo.cs
Source:
SerializationInfo.cs

Adds an 8-bit unsigned integer value into the SerializationInfo store.

C#
public void AddValue(string name, byte value);

Parameters

name
String

The name to associate with the value, so it can be deserialized later.

value
Byte

The byte value to serialize.

Exceptions

The name parameter is null.

A value has already been associated with name.

Remarks

If two values are added with names that differ only by case, no exception will be thrown, which is not a recommended practice. However, adding two values with the exact same name will cause the SerializationException to be thrown.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AddValue(String, Boolean)

Source:
SerializationInfo.cs
Source:
SerializationInfo.cs
Source:
SerializationInfo.cs

Adds a Boolean value into the SerializationInfo store.

C#
public void AddValue(string name, bool value);

Parameters

name
String

The name to associate with the value, so it can be deserialized later.

value
Boolean

The Boolean value to serialize.

Exceptions

The name parameter is null.

A value has already been associated with name.

Remarks

If two values are added with names that differ only by case, no exception will be thrown, which is not a recommended practice. However, adding two values with the exact same name will cause the SerializationException to be thrown. For example:

C#
void ISerializable.GetObject(SerializationInfo info, StreamingContext context)  
{  
   // This will not cause an exception to be thrown.  
   info.AddValue("ABC", true);  
   info.AddValue("abc", false);  
   // However, this will cause the SerializationException to be thrown.  
   info.AddValue("XYZ", true);  
   info.AddValue("XYZ", false);  
}  

Applies to

.NET 9 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1