Click or drag to resize

SerializationGetOrDefaultT Method

Gets SerializationInfo value for specified name; otherwise defaultValue.

Namespace: GSF
Assembly: GSF.Core (in GSF.Core.dll) Version: 2.4.218-beta+101eee949414e414795e55a6e73d88938f0177b8
Syntax
public static T GetOrDefault<T>(
	this SerializationInfo info,
	string name,
	T defaultValue
)
View Source

Parameters

info  SerializationInfo
SerializationInfo object that contains deserialized values.
name  String
Name of deserialized parameter to retrieve.
defaultValue  T
Default value to return if name does not exist or cannot be deserialized.

Type Parameters

T
Type of parameter to get from SerializationInfo.

Return Value

T
Value for specified name; otherwise defaultValue

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type SerializationInfo. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Remarks
SerializationInfo do not have a direct way of determining if an item with a specified name exists, so when calling one of the Get(n) functions you will simply get a SerializationException if the parameter does not exist; similarly you will receive this exception if the parameter fails to properly deserialize. This extension method protects against both of these failures and returns a default value if the named parameter does not exist or cannot be deserialized.
See Also