public static ValueTypeTraits Full() { var result = new ValueTypeTraits { RequireEqualityAndUnequalityOperatorImplementation = true }; return(result); }
public static void IsValue <T>(ValueTypeTraits traits) { if (!ValueObjectWhiteList.Contains <T>()) { var activator = ValueObjectActivator.FreshInstance(typeof(T), Generator); var constraints = CreateConstraintsBasedOn(typeof(T), traits, activator); XAssert.TypeAdheresTo(constraints); } }
private static IEnumerable <IConstraint> CreateConstraintsBasedOn( Type type, ValueTypeTraits traits, ValueObjectActivator activator) { var constraints = new List <IConstraint>(); constraints.Add(new HasToBeAConcreteClass(type)); if (traits.RequireAllFieldsReadOnly) { constraints.Add(new AllFieldsMustBeReadOnly(type)); } constraints.Add(new ThereMustBeNoPublicPropertySetters(type)); constraints.Add(new StateBasedEqualityWithItselfMustBeImplementedInTermsOfEqualsMethod(activator)); constraints.Add(new StateBasedEqualityMustBeImplementedInTermsOfEqualsMethod(activator)); constraints.Add(new StateBasedUnEqualityMustBeImplementedInTermsOfEqualsMethod(activator, traits.IndexesOfConstructorArgumentsIndexesThatDoNotContituteAValueIdentify.ToArray())); constraints.Add(new HashCodeMustBeTheSameForSameObjectsAndDifferentForDifferentObjects(activator, traits.IndexesOfConstructorArgumentsIndexesThatDoNotContituteAValueIdentify.ToArray())); if (traits.RequireSafeUnequalityToNull) { constraints.Add(new UnEqualityWithNullMustBeImplementedInTermsOfEqualsMethod(activator)); } if (traits.RequireEqualityAndUnequalityOperatorImplementation) { //equality operator constraints.Add(new StateBasedEqualityShouldBeAvailableInTermsOfEqualityOperator(type)); constraints.Add(new StateBasedEqualityMustBeImplementedInTermsOfEqualityOperator(activator)); constraints.Add(new StateBasedEqualityWithItselfMustBeImplementedInTermsOfEqualityOperator(activator)); constraints.Add(new StateBasedUnEqualityMustBeImplementedInTermsOfEqualityOperator(activator, traits.IndexesOfConstructorArgumentsIndexesThatDoNotContituteAValueIdentify.ToArray())); constraints.Add(new UnEqualityWithNullMustBeImplementedInTermsOfEqualityOperator(activator)); //inequality operator constraints.Add(new StateBasedEqualityShouldBeAvailableInTermsOfInequalityOperator(type)); constraints.Add(new StateBasedEqualityMustBeImplementedInTermsOfInequalityOperator(activator)); constraints.Add(new StateBasedEqualityWithItselfMustBeImplementedInTermsOfInequalityOperator(activator)); constraints.Add(new StateBasedUnEqualityMustBeImplementedInTermsOfInequalityOperator(activator, traits.IndexesOfConstructorArgumentsIndexesThatDoNotContituteAValueIdentify.ToArray())); constraints.Add(new UnEqualityWithNullMustBeImplementedInTermsOfInequalityOperator(activator)); } return(constraints); }
public static void IsValue <T>() { IsValue <T>(ValueTypeTraits.Default()); }