Пример #1
0
        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);
        }
Пример #2
0
        protected override void Prefilter(IOrmAttribute attribute, Dictionary <string, Defaultable> attributeGroupItems)
        {
            switch (propertyOwner.PropertyKind)
            {
            case PropertyKind.Scalar:
            {
                IScalarProperty scalarProperty = (IScalarProperty)propertyOwner;
                InternalPrefilter(scalarProperty, attribute, attributeGroupItems);
                break;
            }

            case PropertyKind.Structure:
            {
                IStructureProperty structureProperty = (IStructureProperty)propertyOwner;
                InternalPrefilter(structureProperty, attribute, attributeGroupItems);
                break;
            }

            case PropertyKind.Navigation:
            {
                INavigationProperty navigationProperty = (INavigationProperty)propertyOwner;
                InternalPrefilter(navigationProperty, attribute, attributeGroupItems);
                break;
            }
            }
        }
Пример #3
0
        public bool IsImplementedBy(IInterface @interface)
        {
            bool result = false;

            if (@interface != null)
            {
                switch (this.PropertyKind)
                {
                case PropertyKind.Scalar:
                {
                    IScalarProperty thisProperty = (IScalarProperty)this;

                    result = @interface.Properties.Any(delegate(IPropertyBase propertyItem)
                        {
                            IScalarProperty scalarProperty = (IScalarProperty)propertyItem;

                            return(Util.StringEqual(thisProperty.Name, scalarProperty.Name, true) &&
                                   thisProperty.Type.EqualsTo(scalarProperty.Type));
                        });

                    break;
                }

                case PropertyKind.Structure:
                {
                    IStructureProperty thisProperty = (IStructureProperty)this;
                    result = @interface.Properties.Any(delegate(IPropertyBase propertyItem)
                        {
                            IStructureProperty structureProperty = (IStructureProperty)propertyItem;

                            return(Util.StringEqual(thisProperty.Name, structureProperty.Name, true) &&
                                   thisProperty.TypeOf == structureProperty.TypeOf &&
                                   thisProperty.TypeOf != null);
                        });

                    break;
                }

                case PropertyKind.Navigation:
                {
                    INavigationProperty thisProperty = (INavigationProperty)this;
                    result = @interface.NavigationProperties.Any(delegate(INavigationProperty navigationProperty)
                        {
                            var thisAssociations = thisProperty.PersistentTypeHasAssociations;

                            return(Util.StringEqual(thisProperty.Name, navigationProperty.Name, true) &&
                                   thisAssociations.TargetPersistentType == navigationProperty.PersistentTypeHasAssociations.TargetPersistentType &&
                                   thisAssociations.TargetPersistentType != null);
                        });

                    break;
                }
                }
            }

            return(result);
        }
Пример #4
0
        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...
            }
        }
Пример #5
0
    public string EscapeType(IPropertyBase property)
    {
        string result = null;

        if (property is IScalarProperty)
        {
            IScalarProperty scalarProperty = (IScalarProperty)property;
            Type            clrType        = scalarProperty.Type.TryGetClrType(null);
            string          typeName;

            if (clrType != null)
            {
                typeName = Escape(clrType);
                Defaultable <bool> nullable = scalarProperty.FieldAttribute.Nullable;
                bool isNullable             = !nullable.IsDefault() && nullable.Value;
                if (clrType.IsValueType && isNullable)
                {
                    typeName = String.Format(CultureInfo.InvariantCulture, SYSTEM_NULLABLE_FORMAT, typeName);
                }
            }
            else
            {
                typeName = scalarProperty.Type.FullName;
            }

            result = typeName;
        }
        else if (property is INavigationProperty)
        {
            INavigationProperty navigationProperty = (INavigationProperty)property;
            result = navigationProperty.GetPropertyType(_code, EscapeNameWithNamespace,
                                                        delegate(OrmType type, string s)
            {
                return(BuildXtensiveType(type, s));
            });
        }
        else if (property is IStructureProperty)
        {
            IStructureProperty structureProperty = (IStructureProperty)property;
            result = EscapeNameWithNamespace(structureProperty.TypeOf, property.Owner);
        }

        return(result);
    }