DictionaryExtensionTryCreateT Method (IDictionaryString, Object, T, CultureInfo) |
Creates a new instance of the given type by mapping the key value pairs of the dictionary to constructor parameters, public properties and public fields of the given type.
The
default converter is used for conversion if needed.
Returns true if creation succeeded. For success, at least on key value pair must be used as a constructor parameter, public property or public field.
If the dictionary contains only one key value pair, its value is returned if it is exactly of the demanded type.
Namespace:
TB.ComponentModel
Assembly:
UniversalTypeConverter (in UniversalTypeConverter.dll) Version: 2.0.0
Syntax public static bool TryCreate<T>(
this IDictionary<string, Object> propertyValues,
out T newInstance,
CultureInfo culture = null
)
Parameters
- propertyValues
- Type: System.Collections.GenericIDictionaryString, Object
Values which are mapped to constructor parameters, public properties and public fields of the same name as their key.
Names are compared case insensitive.
The constructor with most of the resolvable parameters is used.
- newInstance
- Type: T
The created instance. - culture (Optional)
- Type: System.GlobalizationCultureInfo
The culture to use on conversion. If not given or null, the DefaultCulture is used.
Type Parameters
- T
- The type of the instance to create.
Return Value
Type:
BooleanTrue, if a new instance was created.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type
IDictionaryString,
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).
See Also