Class Likeness<TSource, TDestination>
Provides convention-based object equality comparison for use when comparing two semantically equivalent, but different, objects.
Inheritance
Implements
Inherited Members
Namespace: SemanticComparison
Assembly: SemanticComparison.dll
Syntax
public class Likeness<TSource, TDestination> : IEquatable<TDestination>
Type Parameters
Name | Description |
---|---|
TSource | The type of the source value (against which the destination value will be compared for equality). |
TDestination | The type of the destination value which will be compared for equality against the source value. |
Constructors
| Improve this Doc View SourceLikeness(TSource)
Initializes a new instance of the Likeness<TSource, TDestination> class with the supplied source value.
Declaration
public Likeness(TSource value)
Parameters
Type | Name | Description |
---|---|---|
TSource | value | The source value against which destination values will be compared when Equals(TDestination) is invoked. |
Properties
| Improve this Doc View SourceValue
Gets the source value against which destination values will be compared when Equals(TDestination) is invoked.
Declaration
public TSource Value { get; }
Property Value
Type | Description |
---|---|
TSource |
Methods
| Improve this Doc View SourceCreateProxy()
Creates a dynamic proxy that overrides Equals using Likeness. This method uses the same semantic heuristics, as the default semantic comparison, to map values from the source constructor parameters to the destination constructor.
Declaration
public TDestination CreateProxy()
Returns
Type | Description |
---|---|
TDestination |
Equals(TDestination)
Determines whether the specified object is semantically equal to the current Value.
Declaration
public bool Equals(TDestination other)
Parameters
Type | Name | Description |
---|---|---|
TDestination | other | The object to compare against Value. |
Returns
Type | Description |
---|---|
System.Boolean | true if |
Equals(Object)
Determines whether the specified System.Object is semantically equal to the current Value.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | The object to compare against Value. |
Returns
Type | Description |
---|---|
System.Boolean | true if |
Overrides
GetHashCode()
Serves as a hash function for Likeness<TSource, TDestination>.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 | The hash code for Value, or 0 if the value is null. |
Overrides
OmitAutoComparison()
Turns off implicit default comparison of properties and fields.
Declaration
public Likeness<TSource, TDestination> OmitAutoComparison()
Returns
Type | Description |
---|---|
Likeness<TSource, TDestination> | A new Likeness<TSource, TDestination> that uses only explicitly defined comparisons of properties and fields. |
ShouldEqual(TDestination)
Verifies that a value matches the encapsulated value, or throws a descriptive exception if this is not the case.
Declaration
public void ShouldEqual(TDestination other)
Parameters
Type | Name | Description |
---|---|---|
TDestination | other | The value to compare against Value. |
Exceptions
Type | Condition |
---|---|
LikenessException |
|
ToString()
Returns a System.String that represents the contained object.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A System.String representation of the contained object. |
Overrides
With<TProperty>(Expression<Func<TDestination, TProperty>>)
Returns a LikenessMember<TSource, TDestination> that can be used to define custom comparison behavior for a particular property or field.
Declaration
public LikenessMember<TSource, TDestination> With<TProperty>(Expression<Func<TDestination, TProperty>> propertyPicker)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Func<TDestination, TProperty>> | propertyPicker | An expression that identifies the property or field. |
Returns
Type | Description |
---|---|
LikenessMember<TSource, TDestination> | A new instance of LikenessMember<TSource, TDestination> that represents
the property or field identified by |
Type Parameters
Name | Description |
---|---|
TProperty | The type of the property or field. |
WithDefaultEquality<TProperty>(Expression<Func<TDestination, TProperty>>)
Opt-in of default equality comparison for a specific property or field. Only relevant if OmitAutoComparison() was previously called.
Declaration
public Likeness<TSource, TDestination> WithDefaultEquality<TProperty>(Expression<Func<TDestination, TProperty>> propertyPicker)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Func<TDestination, TProperty>> | propertyPicker | An expression that identifies the property or field. |
Returns
Type | Description |
---|---|
Likeness<TSource, TDestination> | A new instance of Likeness<TSource, TDestination> that explicitly
includes the member identified by |
Type Parameters
Name | Description |
---|---|
TProperty | The type of the property or field. |
Without<TProperty>(Expression<Func<TDestination, TProperty>>)
Returns a new Likeness<TSource, TDestination> that ignores a particular property when comparing values.
Declaration
public Likeness<TSource, TDestination> Without<TProperty>(Expression<Func<TDestination, TProperty>> propertyPicker)
Parameters
Type | Name | Description |
---|---|---|
System.Linq.Expressions.Expression<System.Func<TDestination, TProperty>> | propertyPicker | An expression that identifies the property or field to be ignored. |
Returns
Type | Description |
---|---|
Likeness<TSource, TDestination> | A new Likeness<TSource, TDestination> that ignores the property
identified by |
Type Parameters
Name | Description |
---|---|
TProperty | The type of the property or field to ignore. |