Class ObjectResolver
- Namespace
- CsvHelper
- Assembly
- CsvHelper.dll
Creates objects from a given type.
public class ObjectResolver : IObjectResolver
- Inheritance
-
ObjectResolver
- Implements
- Inherited Members
Constructors
ObjectResolver()
Creates an instance of the object resolver using default values.
public ObjectResolver()
ObjectResolver(Func<Type, bool>, Func<Type, object[], object>, bool)
Creates an instance of the object resolver using the given can create function and create function.
public ObjectResolver(Func<Type, bool> canResolve, Func<Type, object[], object> resolveFunction, bool useFallback = true)
Parameters
canResolve
Func<Type, bool>A function that returns a value indicating if the resolver is able to resolve the given type. True if the type can be resolved, otherwise false.
resolveFunction
Func<Type, object[], object>The function that creates an object from a given type.
useFallback
boolA value indicating if the resolver's CanResolve returns false that an object will still be created using CsvHelper's object creation. True to fallback, otherwise false. Default value is true.
Properties
CanResolve
A function that returns a value indicating if the resolver is able to resolve the given type. True if the type can be resolved, otherwise false.
public Func<Type, bool> CanResolve { get; }
Property Value
Current
Gets or sets the current resolver. Use an instance of this instead if at all possible.
public static IObjectResolver Current { get; set; }
Property Value
ResolveFunction
The function that creates an object from a given type.
public Func<Type, object[], object> ResolveFunction { get; }
Property Value
UseFallback
A value indicating if the resolver's CanResolve returns false that an object will still be created using CsvHelper's object creation. True to fallback, otherwise false. Default value is true.
public bool UseFallback { get; }
Property Value
Methods
Resolve(Type, params object[])
Creates an object from the given type using the ResolveFunction function. If CanResolve is false, the object will be created using CsvHelper's default object creation. If UseFallback is false, an exception is thrown.
public object Resolve(Type type, params object[] constructorArgs)
Parameters
type
TypeThe type to create an instance from. The created object may not be the same type as the given type.
constructorArgs
object[]Constructor arguments used to create the type.
Returns
Resolve<T>(params object[])
Creates an object from the given type using the ResolveFunction function. If CanResolve is false, the object will be created using CsvHelper's default object creation. If UseFallback is false, an exception is thrown.
public T Resolve<T>(params object[] constructorArgs)
Parameters
constructorArgs
object[]Constructor arguments used to create the type.
Returns
- T
Type Parameters
T
The type to create an instance from. The created object may not be the same type as the given type.