Table of Contents

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 bool

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.

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

Func<Type, bool>

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

IObjectResolver

ResolveFunction

The function that creates an object from a given type.

public Func<Type, object[], object> ResolveFunction { get; }

Property Value

Func<Type, object[], object>

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

bool

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 Type

The 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

object

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.