Class InstanceProvider
Represents a way to obtain an instance of a type.
This can be backed by a zero-parameter constructor, a constructor taking typed parameters, a static method, or a delegate.
Inheritance
Implements
Namespace: Cesil
Assembly: Cesil.dll
Syntax
public sealed class InstanceProvider : Object, IEquatable<InstanceProvider>, IElseSupporting<InstanceProvider>
Methods
AllowNullRows()
Returns a InstanceProvider that differs from this by explicitly allowing null rows to be created by it.
Declaration
public InstanceProvider AllowNullRows()
Returns
| Type | Description |
|---|---|
| InstanceProvider |
Else(InstanceProvider)
Create a new instance provider that will try this instance provider, but if it returns false it will then try the given fallback InstanceProvider.
Declaration
public InstanceProvider Else(InstanceProvider fallbackProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| InstanceProvider | fallbackProvider |
Returns
| Type | Description |
|---|---|
| InstanceProvider |
Equals(InstanceProvider)
Returns true if this object equals the given InstanceProvider.
Declaration
public bool Equals(InstanceProvider instanceProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| InstanceProvider | instanceProvider |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Equals(Object)
Returns true if this object equals the given InstanceProvider.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | obj |
Returns
| Type | Description |
|---|---|
| System.Boolean |
ForbidNullRows()
Returns a InstanceProvider that differs from this by explicitly forbidding null rows be created by it.
If the .NET runtime cannot guarantee that null rows will not be created at runtime, null checks will be injected.
Declaration
public InstanceProvider ForbidNullRows()
Returns
| Type | Description |
|---|---|
| InstanceProvider |
ForConstructorWithParameters(ConstructorInfo)
Create a new InstanceProvider from a constructor that takes parameters.
An InstanceProvider of this type must be paired with Setters that map to the parameters on this constructor.
The constructed type must be concrete, that is:
- not an interface
- not an abstract class
- not a generic parameter
- not an unbound generic type (ie. a generic type definition)
Declaration
public static InstanceProvider ForConstructorWithParameters(ConstructorInfo constructor)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Reflection.ConstructorInfo | constructor |
Returns
| Type | Description |
|---|---|
| InstanceProvider |
ForDelegate<TInstance>(InstanceProviderDelegate<TInstance>)
Create a new InstanceProvider from delegate.
There are no restrictions on what the give delegate may do, but be aware that it may be called from many different contexts.
Declaration
public static InstanceProvider ForDelegate<TInstance>(InstanceProviderDelegate<TInstance> del)
Parameters
| Type | Name | Description |
|---|---|---|
| InstanceProviderDelegate<TInstance> | del |
Returns
| Type | Description |
|---|---|
| InstanceProvider |
Type Parameters
| Name | Description |
|---|---|
| TInstance |
ForMethod(MethodInfo)
Creates a new InstanceProvider from a method.
The method must:
- be static
- return a bool
- have two parameters
- the first must be an in ReadContext
- the second must be an out parameter of the constructed type
Declaration
public static InstanceProvider ForMethod(MethodInfo method)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Reflection.MethodInfo | method |
Returns
| Type | Description |
|---|---|
| InstanceProvider |
ForParameterlessConstructor(ConstructorInfo)
Create a new InstanceProvider from a parameterless constructor.
The constructed type must be concrete, that is:
- not an interface
- not an abstract class
- not a generic parameter
- not an unbound generic type (ie. a generic type definition)
Declaration
public static InstanceProvider ForParameterlessConstructor(ConstructorInfo constructor)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Reflection.ConstructorInfo | constructor |
Returns
| Type | Description |
|---|---|
| InstanceProvider |
GetDefault(TypeInfo)
Returns the default instance provider for the given type, if one exists.
For reference types, it will use the parameterless constructor.
For value types, it will use the all-zero (aka default) value.
Declaration
public static InstanceProvider GetDefault(TypeInfo forType)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Reflection.TypeInfo | forType |
Returns
| Type | Description |
|---|---|
| InstanceProvider |
GetHashCode()
Returns a stable hash for this InstanceProvider.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| System.Int32 |
ToString()
Returns a representation of this InstanceProvider object.
Only for debugging, this value is not guaranteed to be stable.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| System.String |
Operators
Equality(InstanceProvider, InstanceProvider)
Compare two InstanceProviders for equality
Declaration
public static bool operator ==(InstanceProvider a, InstanceProvider b)
Parameters
| Type | Name | Description |
|---|---|---|
| InstanceProvider | a | |
| InstanceProvider | b |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Explicit(Delegate to InstanceProvider)
Convenience operator, equivalent to calling ForDelegate if non-null.
Returns null if del is null.
Declaration
public static explicit operator InstanceProvider(Delegate del)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Delegate | del |
Returns
| Type | Description |
|---|---|
| InstanceProvider |
Explicit(ConstructorInfo to InstanceProvider)
Convenience operator, equivalent to calling ForParameterlessConstructor or ForConstructorWithParameters if non-null.
Returns null if field is null.
Declaration
public static explicit operator InstanceProvider(ConstructorInfo cons)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Reflection.ConstructorInfo | cons |
Returns
| Type | Description |
|---|---|
| InstanceProvider |
Explicit(MethodInfo to InstanceProvider)
Convenience operator, equivalent to calling ForMethod if non-null.
Returns null if method is null.
Declaration
public static explicit operator InstanceProvider(MethodInfo method)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Reflection.MethodInfo | method |
Returns
| Type | Description |
|---|---|
| InstanceProvider |
Inequality(InstanceProvider, InstanceProvider)
Compare two InstanceProvider for inequality
Declaration
public static bool operator !=(InstanceProvider a, InstanceProvider b)
Parameters
| Type | Name | Description |
|---|---|---|
| InstanceProvider | a | |
| InstanceProvider | b |
Returns
| Type | Description |
|---|---|
| System.Boolean |