示例#1
0
        private OrmFieldAttribute CreateOrmFieldAttribute(TestAttributeValuesType valuesType)
        {
            OrmFieldAttribute originalAttribute = new OrmFieldAttribute();
            bool isValues1 = valuesType == TestAttributeValuesType.Values1;

            originalAttribute.DefaultValue.Enabled = isValues1 ? true : false;
            originalAttribute.DefaultValue.Value.UseCustomExpression = isValues1 ? false : true;
            if (isValues1)
            {
                originalAttribute.DefaultValue.Value.Value = new Guid("{B4D9F48D-EC7A-4086-AEF4-1E8E439F3865}");
            }
            else
            {
                originalAttribute.DefaultValue.Value.CustomExpression = "System.Drawing.Color.Black";
            }
            originalAttribute.Indexed.SetAsCustom(isValues1 ? false : true);
            originalAttribute.LazyLoad.SetAsCustom(isValues1 ? true : false);
            originalAttribute.Length.SetAsCustom(isValues1 ? 123456789 : 987654321);
            originalAttribute.MappingName.SetAsCustom(isValues1 ? "tField" : "tRevertedField");
            originalAttribute.Nullable.SetAsCustom(isValues1 ? true : false);
            originalAttribute.NullableOnUpgrade.SetAsCustom(isValues1 ? false : true);
            originalAttribute.Precision.SetAsCustom(isValues1 ? 998877 : 778899);
            originalAttribute.Scale.SetAsCustom(isValues1 ? 555 : 550000);
            originalAttribute.TypeDiscriminator.SetAsCustom(isValues1 ? true : false);
            originalAttribute.Version.SetAsCustom(isValues1 ? VersionMode.Skip : VersionMode.Manual);

            return(originalAttribute);
        }
        private void Prefilter(IScalarProperty scalarProperty, OrmFieldAttribute fieldAttribute, Dictionary <string, Defaultable> attributeGroupItems)
        {
            Type clrType = scalarProperty.Type.TryGetClrType(null);

            var propertyTypeIsNumber = clrType != null && clrType.IsNumber();

            // if type is number and length is set, remove 'Length'
            if (fieldAttribute.Length.IsCustom() && propertyTypeIsNumber)
            {
                attributeGroupItems.Remove(OrmFieldAttribute.ATTRIBUTE_GROUP_ITEM_LENGTH);
            }

            // is scale is defined but type is not number remove 'Scale'
            if (fieldAttribute.Scale.IsCustom() && !propertyTypeIsNumber)
            {
                attributeGroupItems.Remove(OrmFieldAttribute.ATTRIBUTE_GROUP_ITEM_SCALE);
            }

            // is Precision is defined but type is not number remove 'Precision'
            if (fieldAttribute.Precision.IsCustom() && !propertyTypeIsNumber)
            {
                attributeGroupItems.Remove(OrmFieldAttribute.ATTRIBUTE_GROUP_ITEM_PRECISION);
            }

            // test if type is byte[] or string to use lazy load
            if (fieldAttribute.LazyLoad.IsCustom() && clrType != null)
            {
                if (!clrType.In(typeof(string), typeof(byte[])))
                {
                    attributeGroupItems.Remove(OrmFieldAttribute.ATTRIBUTE_GROUP_ITEM_LAZY_LOAD);
                }
            }

            attributeGroupItems.Remove(OrmFieldAttribute.ATTRIBUTE_GROUP_ITEM_NULLABLE);
        }
        private void InternalPrefilter(INavigationProperty property, IOrmAttribute attribute, Dictionary <string, Defaultable> attributeGroupItems)
        {
            OrmFieldAttribute fieldAttribute = attribute as OrmFieldAttribute;

            if (fieldAttribute != null)
            {
                Prefilter(property, fieldAttribute, attributeGroupItems);
            }
        }
        private void InternalPrefilter(IScalarProperty property, IOrmAttribute attribute, Dictionary <string, Defaultable> attributeGroupItems)
        {
            OrmFieldAttribute fieldAttribute = attribute as OrmFieldAttribute;

            if (fieldAttribute != null)
            {
                Prefilter(property, fieldAttribute, attributeGroupItems);
            }

            IAssociationInfo associationInfo = attribute as IAssociationInfo;

            if (associationInfo != null)
            {
                // No prefiltering at now...
            }
        }
 private void Prefilter(INavigationProperty scalarProperty, OrmFieldAttribute fieldAttribute, Dictionary <string, Defaultable> attributeGroupItems)
 {
     attributeGroupItems.Remove(OrmFieldAttribute.ATTRIBUTE_GROUP_ITEM_NULLABLE);
     attributeGroupItems.Remove(OrmFieldAttribute.ATTRIBUTE_GROUP_ITEM_LAZY_LOAD);
 }
示例#6
0
        private static void CustomReadPropertiesFromElements(SerializationContext serializationContext, PropertyBase element, XmlReader reader)
        {
            while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
            {
                switch (reader.LocalName)
                {
                    case "field":	// field
                    {
                        if (reader.IsEmptyElement)
                        {	// No serialized value, must be default one.
                            SerializationUtilities.Skip(reader);  // Skip this tag.
                        }
                        else
                        {
                            OrmFieldAttribute fieldAttribute = new OrmFieldAttribute();
                            fieldAttribute.DeserializeFromXml(reader);
                            element.FieldAttribute = fieldAttribute;

                            SerializationUtilities.SkipToNextElement(reader);
                            reader.SkipToNextElementFix();
                        }
                        break;
                    }
                    case "constraints":	// field
                    {
                        if (reader.IsEmptyElement)
                        {	// No serialized value, must be default one.
                            SerializationUtilities.Skip(reader);  // Skip this tag.
                        }
                        else
                        {
                            OrmPropertyConstraints constraints = new OrmPropertyConstraints();
                            constraints.DeserializeFromXml(reader);
                            element.Constraints = constraints;

                            SerializationUtilities.SkipToNextElement(reader);
                            reader.SkipToNextElementFix();
                        }
                        break;
                    }
                    case "dataMember":	// field
                    {
                        if (reader.IsEmptyElement)
                        {	// No serialized value, must be default one.
                            SerializationUtilities.Skip(reader);  // Skip this tag.
                        }
                        else
                        {
                            DataMemberDescriptor dataMemberDescriptor = new DataMemberDescriptor();
                            dataMemberDescriptor.DeserializeFromXml(reader);
                            element.DataMember = dataMemberDescriptor;

                            SerializationUtilities.SkipToNextElement(reader);
                            reader.SkipToNextElementFix();
                        }
                        break;
                    }
                    case "propertyAccess":	// field
                    {
                        if (reader.IsEmptyElement)
                        {	// No serialized value, must be default one.
                            SerializationUtilities.Skip(reader);  // Skip this tag.
                        }
                        else
                        {
                            PropertyAccessModifiers modifiers = new PropertyAccessModifiers();
                            modifiers.DeserializeFromXml(reader, "propertyAccess");
                            element.PropertyAccess = modifiers;

                            SerializationUtilities.SkipToNextElement(reader);
                            reader.SkipToNextElementFix();
                        }
                        break;
                    }
                    default:
                        return;  // Don't know this element.
                }
            }
        }
示例#7
0
        private void TestSerializationForOrmFieldAttribute()
        {
            const string referentialXml =
                "<field><mappingName valueType=\"Custom\"><value>tField</value></mappingName><indexed valueType=\"Custom\" value=\"False\" /><lazyLoad valueType=\"Custom\" value=\"True\" /><length valueType=\"Custom\" value=\"123456789\" /><nullable valueType=\"Custom\" value=\"True\" /><nullableOnUpgrade valueType=\"Custom\" value=\"False\" /><precision valueType=\"Custom\" value=\"998877\" /><scale valueType=\"Custom\" value=\"555\" /><typeDiscriminator valueType=\"Custom\" value=\"True\" /><version valueType=\"Custom\"><value>Skip</value></version><defaultValue valueType=\"Enabled\"><content><value useCustomExpression=\"0\"><Value type=\"System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\">b4d9f48d-ec7a-4086-aef4-1e8e439f3865</Value></value></content></defaultValue><constraints><constraint type=\"0\" valueType=\"Used\"><content mode=\"1\"><error message=\"error for Email\" /></content></constraint><constraint type=\"1\" valueType=\"Used\"><content mode=\"1\"><error message=\"error for Future\" /></content></constraint><constraint type=\"2\" valueType=\"Used\"><content mode=\"1\" max=\"10\"><error message=\"error for Length\" /></content></constraint><constraint type=\"3\" valueType=\"Used\"><content mode=\"1\"><error message=\"error for NotEmpty\" /></content></constraint><constraint type=\"4\" valueType=\"Used\"><content mode=\"1\"><error message=\"error for NotNull\" /></content></constraint><constraint type=\"5\" valueType=\"Used\"><content mode=\"1\"><error message=\"error for NotNullOrEmpty\" /></content></constraint><constraint type=\"6\" valueType=\"Used\"><content mode=\"1\"><error message=\"error for Past\" /></content></constraint><constraint type=\"7\" valueType=\"Used\"><content mode=\"1\"><error message=\"error for Range\" /><min valueType=\"Enabled\"><content><value useCustomExpression=\"0\"><Value type=\"System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\">120</Value></value></content></min><max valueType=\"Disabled\" /></content></constraint><constraint type=\"8\" valueType=\"Used\"><content mode=\"1\" pattern=\"1234@11\" options=\"273\"><error message=\"error for Regex\" /></content></constraint></constraints></field>";

            OrmFieldAttribute originalAttribute = CreateOrmFieldAttribute(TestAttributeValuesType.Values1);
            //SetPropertyConstraintsValues(originalAttribute.Constraints);

            string xml = originalAttribute.SerializeToString();

            Assert.IsTrue(Util.StringEqual(xml, referentialXml, true),
                          "Serialized xml form of 'OrmFieldAttribute' type differs from referential xml.");

            OrmFieldAttribute clonedAttribute = null;

            Action cloneAttribute = () => clonedAttribute = originalAttribute.Clone();

            cloneAttribute();
            Assert.IsTrue(originalAttribute.EqualsTo(clonedAttribute));

            Action testClonedNotEquals = () => Assert.IsFalse(originalAttribute.EqualsTo(clonedAttribute));

            cloneAttribute();
            clonedAttribute.DefaultValue.Enabled = false;
            testClonedNotEquals();

            cloneAttribute();
            clonedAttribute.DefaultValue.Value.UseCustomExpression = true;
            testClonedNotEquals();

            cloneAttribute();
            clonedAttribute.DefaultValue.Value.CustomExpression = "System.Color";
            testClonedNotEquals();

            cloneAttribute();
            clonedAttribute.Indexed.SetAsCustom(true);
            testClonedNotEquals();

            cloneAttribute();
            clonedAttribute.Indexed.SetAsDefault();
            testClonedNotEquals();

            cloneAttribute();
            clonedAttribute.LazyLoad.SetAsDefault();
            testClonedNotEquals();

            cloneAttribute();
            clonedAttribute.Length.SetAsDefault();
            testClonedNotEquals();

            cloneAttribute();
            clonedAttribute.Length.SetAsCustom(120);
            testClonedNotEquals();

            cloneAttribute();
            clonedAttribute.MappingName.SetAsDefault();
            testClonedNotEquals();

            cloneAttribute();
            clonedAttribute.MappingName.SetAsCustom("field2");
            testClonedNotEquals();

            cloneAttribute();
            clonedAttribute.Nullable.SetAsDefault();
            testClonedNotEquals();

            cloneAttribute();
            clonedAttribute.NullableOnUpgrade.SetAsDefault();
            testClonedNotEquals();

            cloneAttribute();
            clonedAttribute.Precision.SetAsDefault();
            testClonedNotEquals();

            cloneAttribute();
            clonedAttribute.Scale.SetAsDefault();
            testClonedNotEquals();

            cloneAttribute();
            clonedAttribute.TypeDiscriminator.SetAsDefault();
            testClonedNotEquals();

            cloneAttribute();
            clonedAttribute.Version.SetAsDefault();
            testClonedNotEquals();
        }