Exemplo n.º 1
0
        internal static CObject CObject(string typeName)
        {
            DesignByContract.Check.Require(!string.IsNullOrEmpty(typeName), string.Format(CommonStrings.XMustNotBeNullOrEmpty, "typeName"));

            CObject cObject = null;

            switch (typeName)
            {
            case "C_COMPLEX_OBJECT":
                cObject = new CComplexObject();
                break;

            case "C_PRIMITIVE_OBJECT":
                cObject = new CPrimitiveObject();
                break;

            case "ARCHETYPE_INTERNAL_REF":
                cObject = new ArchetypeInternalRef();
                break;

            case "CONSTRAINT_REF":
                cObject = new ConstraintRef();
                break;

            case "ARCHETYPE_SLOT":
                cObject = new ArchetypeSlot();
                break;

            case "C_CODE_PHRASE":
                cObject = new CCodePhrase();
                break;

            case "C_DV_STATE":
                cObject = new CDvState();
                break;

            case "C_DV_ORDINAL":
                cObject = new CDvOrdinal();
                break;

            case "C_DV_QUANTITY":
                cObject = new CDvQuantity();
                break;

            default:
                throw new NotSupportedException("type not supported: " + typeName);
            }

            DesignByContract.Check.Ensure(cObject != null, "cObject must not be null.");

            return(cObject);
        }
Exemplo n.º 2
0
        protected void Validate(CDvQuantity cDvQuantity)
        {
            this.Validate((CDomainType)cDvQuantity);

            Invariant(cDvQuantity.List == null || !cDvQuantity.List.IsEmpty(), "cDvQuantity.List is not null, implies it must not be empty.");
            Invariant(cDvQuantity.AnyAllowed() ^ (cDvQuantity.List != null || cDvQuantity.Property != null),
                      "cDvQuantity.AnyAllowed() XOR (cDvQuantity.List != null or cDvQuantity.Property != null.)");

            if (cDvQuantity.List != null)
            {
                foreach (CQuantityItem quantityItem in cDvQuantity.List)
                {
                    this.Validate(quantityItem);
                }
            }

            if (cDvQuantity.Property != null)
            {
                this.Validate(cDvQuantity.Property);
            }
        }