Click or drag to resize

ObjectExtensionToDictionary Method

Creates a new dictionary whose key value pairs represent all non static public values of the given source. If source is null, an empty dictionary is created. If source has no non static public properties or fields (eg. int), the dictionary contains only one key named "Value" representing the given value itself.

Namespace:  TB.ComponentModel
Assembly:  UniversalTypeConverter (in UniversalTypeConverter.dll) Version: 2.0.0
Syntax
C#
public static Dictionary<string, Object> ToDictionary(
	this Object obj
)

Parameters

obj
Type: SystemObject
The object whose non static public properties and fields are added to the new dictionary.

Return Value

Type: DictionaryString, Object
A dictionary which contains the non static public values of obj.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Object. 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
If obj is a Dictionary{string, object}, obj is returned. If obj implements IDictionary, an new Dictionary{string, object} is returned, which keys are build by using ToString() on the source keys and keeping their original values. If obj is a DataRow, ToDictionary(DataRow) is returned. If obj is a DataRowView, ToDictionary(DataRowView) is returned. If obj is a IDataRecord, ToDictionary(IDataRecord) is returned. If obj is null, an empty dictionary is returned. If obj has no non static public properties or fields (eg. int), an dictionary with its only key named "Value" is returned.
See Also