コード例 #1
0
        public static ValueTypeTraits Full()
        {
            var result = new ValueTypeTraits
            {
                RequireEqualityAndUnequalityOperatorImplementation = true
            };

            return(result);
        }
コード例 #2
0
 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);
     }
 }
コード例 #3
0
        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);
        }
コード例 #4
0
 public static void IsValue <T>()
 {
     IsValue <T>(ValueTypeTraits.Default());
 }