Exemplo n.º 1
0
        /// <summary>
        /// Parses a URDF &lt;mesh&gt; element from XML.
        /// </summary>
        /// <param name="node">The XML node of a &lt;mesh&gt; element</param>
        /// <returns>A Mesh object parsed from the XML</returns>
        public override Mesh Parse(XmlNode node)
        {
            ValidateXmlNode(node);

            XmlAttribute fileNameAttribute = GetAttributeFromNode(node, UrdfSchema.FILE_NAME_ATTRIBUTE_NAME);
            XmlAttribute scaleAttribute    = GetAttributeFromNode(node, UrdfSchema.SCALE_ATTRIBUTE_NAME);
            XmlAttribute sizeAttribute     = GetAttributeFromNode(node, UrdfSchema.SIZE_ATTRIBUTE_NAME);

            string         fileName = ParseFileName(fileNameAttribute);
            ScaleAttribute scale    = ParseScaleAttribute(scaleAttribute);
            SizeAttribute  size     = ParseSizeAttribute(sizeAttribute);

            Mesh.Builder builder = new Mesh.Builder(fileName);

            if (scale != null)
            {
                builder.SetScale(scale);
            }
            if (size != null)
            {
                builder.SetSize(size);
            }

            return(builder.Build());
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new instance of Mesh with the specified file name, specified scale and specified size.
 /// An Mesh.Builder must be used to instantiate a Mesh with optional properties as specified.
 /// </summary>
 /// <param name="fileName">The mesh object file name. MUST NOT BE EMPTY</param>
 /// <param name="scale">The scale of the mesh object. MUST NOT BE NULL</param>
 /// <param name="size">The size of the mesh object. MAY BE NULL</param>
 private Mesh(string fileName, ScaleAttribute scale, SizeAttribute size)
 {
     Preconditions.IsNotEmpty(fileName, "Mesh file name property must not be null or empty");
     Preconditions.IsNotNull(scale, "Mesh scale property must not be null");
     this.FileName = fileName;
     this.Scale    = scale;
     this.Size     = size;
 }
Exemplo n.º 3
0
        public void ConstructScaleAttribute()
        {
            double         x     = 1;
            double         y     = 2;
            double         z     = 3;
            ScaleAttribute scale = new ScaleAttribute(x, y, z);

            Assert.AreEqual(x, scale.X);
            Assert.AreEqual(y, scale.Y);
            Assert.AreEqual(z, scale.Z);
        }
Exemplo n.º 4
0
        public void EqualsAndHash()
        {
            ScaleAttribute scale = new ScaleAttribute(1, 2, 3);
            ScaleAttribute same  = new ScaleAttribute(1, 2, 3);
            ScaleAttribute diff  = new ScaleAttribute(7, 7, 7);

            Assert.IsTrue(scale.Equals(scale));
            Assert.IsFalse(scale.Equals(null));
            Assert.IsTrue(scale.Equals(same));
            Assert.IsTrue(same.Equals(scale));
            Assert.IsFalse(scale.Equals(diff));
            Assert.AreEqual(scale.GetHashCode(), same.GetHashCode());
            Assert.AreNotEqual(scale.GetHashCode(), diff.GetHashCode());
        }
Exemplo n.º 5
0
        public void ParseMeshNoFileName()
        {
            ScaleAttribute scale = new ScaleAttribute(1, 2, 3);
            SizeAttribute  size  = new SizeAttribute(4, 5, 6);
            string         xml   = String.Format("<mesh scale='{0} {1} {2}' size='{3} {4} {5}'/>",
                                                 scale.X, scale.Y, scale.Z, size.Length, size.Width, size.Height);

            this.xmlDoc.Load(XmlReader.Create(new StringReader(xml)));
            Mesh mesh = this.parser.Parse(this.xmlDoc.DocumentElement);

            Assert.AreEqual(Mesh.DEFAULT_FILE_NAME, mesh.FileName);
            Assert.AreEqual(scale, mesh.Scale);
            Assert.AreEqual(size, mesh.Size);
        }
Exemplo n.º 6
0
        public void ParseMeshNoSize()
        {
            string         fileName = "fileName";
            ScaleAttribute scale    = new ScaleAttribute(1, 2, 3);
            string         xml      = String.Format("<mesh filename='{0}' scale='{1} {2} {3}'/>",
                                                    fileName, scale.X, scale.Y, scale.Z);

            this.xmlDoc.Load(XmlReader.Create(new StringReader(xml)));
            Mesh mesh = this.parser.Parse(this.xmlDoc.DocumentElement);

            Assert.AreEqual(fileName, mesh.FileName);
            Assert.AreEqual(scale, mesh.Scale);
            Assert.AreEqual(null, mesh.Size);
        }
Exemplo n.º 7
0
        public void ParseMesh()
        {
            string         fileName = "fileName";
            ScaleAttribute scale    = new ScaleAttribute(1, 2, 3);
            SizeAttribute  size     = new SizeAttribute(4, 5, 6);
            string         xml      = String.Format("<mesh filename='{0}' scale='{1} {2} {3}' size='{4} {5} {6}'/>",
                                                    fileName, scale.X, scale.Y, scale.Z, size.Length, size.Width, size.Height);

            this.xmlDoc.Load(XmlReader.Create(new StringReader(xml)));
            Mesh mesh = this.parser.Parse(this.xmlDoc.DocumentElement);

            Assert.AreEqual(fileName, mesh.FileName);
            Assert.AreEqual(scale, mesh.Scale);
            Assert.AreEqual(size, mesh.Size);
        }
Exemplo n.º 8
0
        public void ConstructMeshWithScale()
        {
            string         fileName = "fileName";
            double         scaleX   = 1;
            double         scaleY   = 2;
            double         scaleZ   = 3;
            ScaleAttribute scale    = new ScaleAttribute(scaleX, scaleY, scaleZ);
            Mesh           mesh     = new Mesh.Builder(fileName).SetScale(scale).Build();

            Assert.AreEqual(fileName, mesh.FileName);
            Assert.AreEqual(scale, mesh.Scale);
            Assert.IsNull(mesh.Size);
            Assert.AreEqual(scaleX, mesh.Scale.X);
            Assert.AreEqual(scaleY, mesh.Scale.Y);
            Assert.AreEqual(scaleZ, mesh.Scale.Z);
        }
Exemplo n.º 9
0
        public void ConstructMeshWithScaleAndSize()
        {
            string         fileName = "fileName";
            double         scaleX   = 1;
            double         scaleY   = 2;
            double         scaleZ   = 3;
            ScaleAttribute scale    = new ScaleAttribute(scaleX, scaleY, scaleZ);
            double         length   = 11;
            double         width    = 22;
            double         height   = 33;
            SizeAttribute  size     = new SizeAttribute(length, width, height);
            Mesh           mesh     = new Mesh.Builder(fileName).SetScale(scale).SetSize(size).Build();

            Assert.AreEqual(fileName, mesh.FileName);
            Assert.AreEqual(scale, mesh.Scale);
            Assert.AreEqual(scaleX, mesh.Scale.X);
            Assert.AreEqual(scaleY, mesh.Scale.Y);
            Assert.AreEqual(scaleZ, mesh.Scale.Z);
            Assert.AreEqual(size, mesh.Size);
            Assert.AreEqual(length, size.Length);
            Assert.AreEqual(width, size.Width);
            Assert.AreEqual(height, size.Height);
        }
Exemplo n.º 10
0
        private ScaleAttribute ParseScaleAttribute(XmlAttribute scaleAttribute)
        {
            ScaleAttribute scale = null;

            if (scaleAttribute == null)
            {
                LogMissingOptionalAttribute(UrdfSchema.SCALE_ATTRIBUTE_NAME);
            }
            else
            {
                if (!RegexUtils.IsMatchNDoubles(scaleAttribute.Value, 3))
                {
                    LogMalformedAttribute(UrdfSchema.SCALE_ATTRIBUTE_NAME);
                }
                else
                {
                    double[] values = RegexUtils.MatchDoubles(scaleAttribute.Value);
                    scale = new ScaleAttribute(values[0], values[1], values[2]);
                }
            }

            return(scale);
        }
Exemplo n.º 11
0
        public void Initialize()
        {
            if (isInitialized)
            {
                return;
            }

            lock (this.initializeLock)
            {
                Dictionary <string, FieldInfo>    rowFields;
                Dictionary <string, PropertyInfo> rowProperties;
                GetRowFieldsAndProperties(out rowFields, out rowProperties);

                foreach (var fieldInfo in this.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public))
                {
                    if (fieldInfo.FieldType.IsSubclassOf(typeof(Field)))
                    {
                        var field = (Field)fieldInfo.GetValue(this);

                        PropertyInfo property;
                        if (!rowProperties.TryGetValue(fieldInfo.Name, out property))
                        {
                            property = null;
                        }

                        ColumnAttribute         column       = null;
                        DisplayNameAttribute    display      = null;
                        SizeAttribute           size         = null;
                        ExpressionAttribute     expression   = null;
                        ScaleAttribute          scale        = null;
                        MinSelectLevelAttribute selectLevel  = null;
                        ForeignKeyAttribute     foreignKey   = null;
                        LeftJoinAttribute       foreignJoin  = null;
                        DefaultValueAttribute   defaultValue = null;
                        TextualFieldAttribute   textualField = null;
                        DateTimeKindAttribute   dateTimeKind = null;

                        FieldFlags addFlags    = (FieldFlags)0;
                        FieldFlags removeFlags = (FieldFlags)0;

                        if (property != null)
                        {
                            column       = property.GetCustomAttribute <ColumnAttribute>(false);
                            display      = property.GetCustomAttribute <DisplayNameAttribute>(false);
                            size         = property.GetCustomAttribute <SizeAttribute>(false);
                            expression   = property.GetCustomAttribute <ExpressionAttribute>(false);
                            scale        = property.GetCustomAttribute <ScaleAttribute>(false);
                            selectLevel  = property.GetCustomAttribute <MinSelectLevelAttribute>(false);
                            foreignKey   = property.GetCustomAttribute <ForeignKeyAttribute>(false);
                            foreignJoin  = property.GetCustomAttributes <LeftJoinAttribute>(false).FirstOrDefault(x => x.ToTable == null && x.OnCriteria == null);
                            defaultValue = property.GetCustomAttribute <DefaultValueAttribute>(false);
                            textualField = property.GetCustomAttribute <TextualFieldAttribute>(false);
                            dateTimeKind = property.GetCustomAttribute <DateTimeKindAttribute>(false);

                            var insertable = property.GetCustomAttribute <InsertableAttribute>(false);
                            var updatable  = property.GetCustomAttribute <UpdatableAttribute>(false);

                            if (insertable != null && !insertable.Value)
                            {
                                removeFlags |= FieldFlags.Insertable;
                            }

                            if (updatable != null && !updatable.Value)
                            {
                                removeFlags |= FieldFlags.Updatable;
                            }

                            foreach (var attr in property.GetCustomAttributes <SetFieldFlagsAttribute>(false))
                            {
                                addFlags    |= attr.Add;
                                removeFlags |= attr.Remove;
                            }
                        }

                        if (ReferenceEquals(null, field))
                        {
                            if (property == null)
                            {
                                throw new InvalidProgramException(String.Format(
                                                                      "Field {0} in type {1} is null and has no corresponding property in entity!",
                                                                      fieldInfo.Name, rowType.Name));
                            }

                            object[] prm = new object[7];
                            prm[0] = this; // owner
                            prm[1] = column == null ? property.Name : (column.Name.TrimToNull() ?? property.Name);
                            prm[2] = display != null ? new LocalText(display.DisplayName) : null;
                            prm[3] = size != null ? size.Value : 0;
                            prm[4] = (FieldFlags.Default ^ removeFlags) | addFlags;
                            prm[5] = null;
                            prm[6] = null;

                            FieldInfo storage;
                            if (rowFields.TryGetValue("_" + property.Name, out storage) ||
                                rowFields.TryGetValue("m_" + property.Name, out storage) ||
                                rowFields.TryGetValue(property.Name, out storage))
                            {
                                prm[5] = CreateFieldGetMethod(storage);
                                prm[6] = CreateFieldSetMethod(storage);
                            }

                            field = (Field)Activator.CreateInstance(fieldInfo.FieldType, prm);
                            fieldInfo.SetValue(this, field);
                        }
                        else
                        {
                            if (size != null)
                            {
                                throw new InvalidProgramException(String.Format(
                                                                      "Field size '{0}' in type {1} can't be overridden by Size attribute!",
                                                                      fieldInfo.Name, rowType.Name));
                            }

                            if (display != null)
                            {
                                field.Caption = new LocalText(display.DisplayName);
                            }

                            if ((int)addFlags != 0 || (int)removeFlags != 0)
                            {
                                field.Flags = (field.Flags ^ removeFlags) | addFlags;
                            }

                            if (column != null && String.Compare(column.Name, field.Name, StringComparison.OrdinalIgnoreCase) != 0)
                            {
                                throw new InvalidProgramException(String.Format(
                                                                      "Field name '{0}' in type {1} can't be overridden by Column name attribute!",
                                                                      fieldInfo.Name, rowType.Name));
                            }
                        }

                        if (scale != null)
                        {
                            field.Scale = scale.Value;
                        }

                        if (defaultValue != null)
                        {
                            field.DefaultValue = defaultValue.Value;
                        }

                        if (selectLevel != null)
                        {
                            field.MinSelectLevel = selectLevel.Value;
                        }

                        if (expression != null)
                        {
                            field.Expression = expression.Value;
                        }

                        if (foreignKey != null)
                        {
                            field.ForeignTable = foreignKey.Table;
                            field.ForeignField = foreignKey.Field;
                        }

                        if (foreignJoin != null)
                        {
                            field.ForeignJoinAlias = new LeftJoin(this.joins, field.ForeignTable, foreignJoin.Alias,
                                                                  new Criteria(foreignJoin.Alias, field.ForeignField) == new Criteria(field));
                        }

                        if (textualField != null)
                        {
                            field.textualField = textualField.Value;
                        }

                        if (dateTimeKind != null && field is DateTimeField)
                        {
                            ((DateTimeField)field).DateTimeKind = dateTimeKind.Value;
                        }

                        if (property != null)
                        {
                            if (property.PropertyType != null &&
                                field is IEnumTypeField)
                            {
                                if (property.PropertyType.IsEnum)
                                {
                                    (field as IEnumTypeField).EnumType = property.PropertyType;
                                }
                                else
                                {
                                    var nullableType = Nullable.GetUnderlyingType(property.PropertyType);
                                    if (nullableType != null && nullableType.IsEnum)
                                    {
                                        (field as IEnumTypeField).EnumType = nullableType;
                                    }
                                }
                            }

                            foreach (var attr in property.GetCustomAttributes <LeftJoinAttribute>())
                            {
                                if (attr.ToTable != null && attr.OnCriteria != null)
                                {
                                    new LeftJoin(this.joins, attr.ToTable, attr.Alias,
                                                 new Criteria(attr.Alias, attr.OnCriteria) == new Criteria(field));
                                }
                            }

                            field.PropertyName = property.Name;
                            this.byPropertyName[field.PropertyName] = field;

                            field.CustomAttributes = property.GetCustomAttributes(false);
                        }
                    }
                }

                foreach (var attr in this.rowType.GetCustomAttributes <LeftJoinAttribute>())
                {
                    new LeftJoin(this.joins, attr.ToTable, attr.Alias, new Criteria(attr.OnCriteria));
                }

                foreach (var attr in this.rowType.GetCustomAttributes <OuterApplyAttribute>())
                {
                    new OuterApply(this.joins, attr.InnerQuery, attr.Alias);
                }

                var propertyDescriptorArray = new PropertyDescriptor[this.Count];
                for (int i = 0; i < this.Count; i++)
                {
                    var field = this[i];
                    propertyDescriptorArray[i] = new FieldDescriptor(field);
                }

                this.propertyDescriptors = new PropertyDescriptorCollection(propertyDescriptorArray);

                InferTextualFields();
                AfterInitialize();
            }

            isInitialized = true;
        }
Exemplo n.º 12
0
        public void Initialize()
        {
            if (isInitialized)
            {
                return;
            }

            lock (this.initializeLock)
            {
                Dictionary <string, FieldInfo>     rowFields;
                Dictionary <string, IPropertyInfo> rowProperties;
                GetRowFieldsAndProperties(out rowFields, out rowProperties);

                var expressionSelector  = new DialectExpressionSelector(connectionKey);
                var rowCustomAttributes = this.rowType.GetCustomAttributes().ToList();

                foreach (var fieldInfo in this.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public))
                {
                    if (fieldInfo.FieldType.IsSubclassOf(typeof(Field)))
                    {
                        var field = (Field)fieldInfo.GetValue(this);

                        IPropertyInfo property;
                        if (!rowProperties.TryGetValue(fieldInfo.Name, out property))
                        {
                            property = null;
                        }

                        ColumnAttribute         column           = null;
                        DisplayNameAttribute    display          = null;
                        SizeAttribute           size             = null;
                        ExpressionAttribute     expression       = null;
                        ScaleAttribute          scale            = null;
                        MinSelectLevelAttribute selectLevel      = null;
                        ForeignKeyAttribute     foreignKey       = null;
                        LeftJoinAttribute       leftJoin         = null;
                        InnerJoinAttribute      innerJoin        = null;
                        DefaultValueAttribute   defaultValue     = null;
                        TextualFieldAttribute   textualField     = null;
                        DateTimeKindAttribute   dateTimeKind     = null;
                        PermissionAttributeBase readPermission   = null;
                        PermissionAttributeBase insertPermission = null;
                        PermissionAttributeBase updatePermission = null;

                        FieldFlags addFlags    = (FieldFlags)0;
                        FieldFlags removeFlags = (FieldFlags)0;

                        OriginPropertyDictionary propertyDictionary = null;

                        if (property != null)
                        {
                            var origin = property.GetAttribute <OriginAttribute>();

                            column  = property.GetAttribute <ColumnAttribute>();
                            display = property.GetAttribute <DisplayNameAttribute>();
                            size    = property.GetAttribute <SizeAttribute>();

                            var expressions = property.GetAttributes <ExpressionAttribute>();
                            if (expressions.Any())
                            {
                                expression = expressionSelector.GetBestMatch(expressions, x => x.Dialect);
                            }

                            scale       = property.GetAttribute <ScaleAttribute>();
                            selectLevel = property.GetAttribute <MinSelectLevelAttribute>();
                            foreignKey  = property.GetAttribute <ForeignKeyAttribute>();
                            leftJoin    = property.GetAttributes <LeftJoinAttribute>()
                                          .FirstOrDefault(x => x.ToTable == null && x.OnCriteria == null);
                            innerJoin = property.GetAttributes <InnerJoinAttribute>()
                                        .FirstOrDefault(x => x.ToTable == null && x.OnCriteria == null);
                            defaultValue     = property.GetAttribute <DefaultValueAttribute>();
                            textualField     = property.GetAttribute <TextualFieldAttribute>();
                            dateTimeKind     = property.GetAttribute <DateTimeKindAttribute>();
                            readPermission   = property.GetAttribute <ReadPermissionAttribute>();
                            insertPermission = property.GetAttribute <InsertPermissionAttribute>() ??
                                               property.GetAttribute <ModifyPermissionAttribute>() ?? readPermission;
                            updatePermission = property.GetAttribute <UpdatePermissionAttribute>() ??
                                               property.GetAttribute <ModifyPermissionAttribute>() ?? readPermission;

                            if (origin != null)
                            {
                                propertyDictionary = propertyDictionary ?? OriginPropertyDictionary.GetPropertyDictionary(this.rowType);
                                try
                                {
                                    if (!expressions.Any() && expression == null)
                                    {
                                        expression = new ExpressionAttribute(propertyDictionary.OriginExpression(
                                                                                 property.Name, origin, expressionSelector, "", rowCustomAttributes));
                                    }

                                    if (display == null)
                                    {
                                        display = new DisplayNameAttribute(propertyDictionary.OriginDisplayName(property.Name, origin));
                                    }

                                    if (size == null)
                                    {
                                        size = propertyDictionary.OriginAttribute <SizeAttribute>(property.Name, origin);
                                    }

                                    if (scale == null)
                                    {
                                        scale = propertyDictionary.OriginAttribute <ScaleAttribute>(property.Name, origin);
                                    }
                                }
                                catch (DivideByZeroException)
                                {
                                    throw new InvalidProgramException(String.Format(
                                                                          "Infinite recursion detected while determining origins " +
                                                                          "for property '{0}' on row type '{1}'",
                                                                          property.Name, rowType.FullName));
                                }
                            }

                            var insertable = property.GetAttribute <InsertableAttribute>();
                            var updatable  = property.GetAttribute <UpdatableAttribute>();

                            if (insertable != null && !insertable.Value)
                            {
                                removeFlags |= FieldFlags.Insertable;
                            }

                            if (updatable != null && !updatable.Value)
                            {
                                removeFlags |= FieldFlags.Updatable;
                            }

                            foreach (var attr in property.GetAttributes <SetFieldFlagsAttribute>())
                            {
                                addFlags    |= attr.Add;
                                removeFlags |= attr.Remove;
                            }
                        }

                        if (ReferenceEquals(null, field))
                        {
                            if (property == null)
                            {
                                throw new InvalidProgramException(String.Format(
                                                                      "Field {0} in type {1} is null and has no corresponding property in entity!",
                                                                      fieldInfo.Name, rowType.Name));
                            }

                            object[] prm = new object[7];
                            prm[0] = this; // owner
                            prm[1] = column == null ? property.Name : (column.Name.TrimToNull() ?? property.Name);
                            prm[2] = display != null ? new LocalText(display.DisplayName) : null;
                            prm[3] = size != null ? size.Value : 0;

                            var defaultFlags = FieldFlags.Default;
                            if (fieldInfo.FieldType.GetCustomAttribute <NotMappedAttribute>() != null)
                            {
                                defaultFlags |= FieldFlags.NotMapped;
                            }

                            prm[4] = (defaultFlags ^ removeFlags) | addFlags;
                            prm[5] = null;
                            prm[6] = null;

                            FieldInfo storage;
                            if (rowFields.TryGetValue("_" + property.Name, out storage) ||
                                rowFields.TryGetValue("m_" + property.Name, out storage) ||
                                rowFields.TryGetValue(property.Name, out storage))
                            {
                                prm[5] = CreateFieldGetMethod(storage);
                                prm[6] = CreateFieldSetMethod(storage);
                            }

                            field = (Field)Activator.CreateInstance(fieldInfo.FieldType, prm);
                            fieldInfo.SetValue(this, field);
                        }
                        else
                        {
                            if (size != null)
                            {
                                throw new InvalidProgramException(String.Format(
                                                                      "Field size '{0}' in type {1} can't be overridden by Size attribute!",
                                                                      fieldInfo.Name, rowType.FullName));
                            }

                            if (display != null)
                            {
                                field.Caption = new LocalText(display.DisplayName);
                            }

                            if ((int)addFlags != 0 || (int)removeFlags != 0)
                            {
                                field.Flags = (field.Flags ^ removeFlags) | addFlags;
                            }

                            if (column != null && String.Compare(column.Name, field.Name, StringComparison.OrdinalIgnoreCase) != 0)
                            {
                                throw new InvalidProgramException(String.Format(
                                                                      "Field name '{0}' in type {1} can't be overridden by Column name attribute!",
                                                                      fieldInfo.Name, rowType.FullName));
                            }
                        }

                        if (scale != null)
                        {
                            field.Scale = scale.Value;
                        }

                        if (defaultValue != null)
                        {
                            field.DefaultValue = defaultValue.Value;
                        }

                        if (selectLevel != null)
                        {
                            field.MinSelectLevel = selectLevel.Value;
                        }

                        if (expression != null)
                        {
                            field.Expression = expression.Value;
                        }

                        if (foreignKey != null)
                        {
                            field.ForeignTable = foreignKey.Table;
                            field.ForeignField = foreignKey.Field;
                        }

                        if ((leftJoin != null || innerJoin != null) && field.ForeignTable.IsEmptyOrNull())
                        {
                            throw new InvalidProgramException(String.Format("Property {0} of row type {1} has a [LeftJoin] or [InnerJoin] attribute " +
                                                                            "but its foreign table is undefined. Make sure it has a valid [ForeignKey] attribute!",
                                                                            fieldInfo.Name, rowType.FullName));
                        }

                        if ((leftJoin != null || innerJoin != null) && field.ForeignField.IsEmptyOrNull())
                        {
                            throw new InvalidProgramException(String.Format("Property {0} of row type {1} has a [LeftJoin] or [InnerJoin] attribute " +
                                                                            "but its foreign field is undefined. Make sure it has a valid [ForeignKey] attribute!",
                                                                            fieldInfo.Name, rowType.FullName));
                        }

                        if (leftJoin != null)
                        {
                            field.ForeignJoinAlias = new LeftJoin(this.joins, field.ForeignTable, leftJoin.Alias,
                                                                  new Criteria(leftJoin.Alias, field.ForeignField) == new Criteria(field));
                        }

                        if (innerJoin != null)
                        {
                            field.ForeignJoinAlias = new InnerJoin(this.joins, field.ForeignTable, innerJoin.Alias,
                                                                   new Criteria(innerJoin.Alias, field.ForeignField) == new Criteria(field));
                        }

                        if (textualField != null)
                        {
                            field.textualField = textualField.Value;
                        }

                        if (dateTimeKind != null && field is DateTimeField)
                        {
                            ((DateTimeField)field).DateTimeKind = dateTimeKind.Value;
                        }

                        if (readPermission != null)
                        {
                            field.readPermission = readPermission.Permission ?? "?";
                        }

                        if (insertPermission != null)
                        {
                            field.insertPermission = insertPermission.Permission ?? "?";
                        }

                        if (updatePermission != null)
                        {
                            field.updatePermission = updatePermission.Permission ?? "?";
                        }

                        if (property != null)
                        {
                            if (property.PropertyType != null &&
                                field is IEnumTypeField)
                            {
                                if (property.PropertyType.IsEnum)
                                {
                                    (field as IEnumTypeField).EnumType = property.PropertyType;
                                }
                                else
                                {
                                    var nullableType = Nullable.GetUnderlyingType(property.PropertyType);
                                    if (nullableType != null && nullableType.IsEnum)
                                    {
                                        (field as IEnumTypeField).EnumType = nullableType;
                                    }
                                }
                            }

                            foreach (var attr in property.GetAttributes <LeftJoinAttribute>())
                            {
                                if (attr.ToTable != null && attr.OnCriteria != null)
                                {
                                    new LeftJoin(this.joins, attr.ToTable, attr.Alias,
                                                 new Criteria(attr.Alias, attr.OnCriteria) == new Criteria(field));
                                }
                            }

                            foreach (var attr in property.GetAttributes <InnerJoinAttribute>())
                            {
                                if (attr.ToTable != null && attr.OnCriteria != null)
                                {
                                    new InnerJoin(this.joins, attr.ToTable, attr.Alias,
                                                  new Criteria(attr.Alias, attr.OnCriteria) == new Criteria(field));
                                }
                            }

                            field.PropertyName = property.Name;
                            this.byPropertyName[field.PropertyName] = field;

                            field.customAttributes = property.GetAttributes <Attribute>().ToArray();
                        }
                    }
                }

                foreach (var attr in rowCustomAttributes.OfType <LeftJoinAttribute>())
                {
                    new LeftJoin(this.joins, attr.ToTable, attr.Alias, new Criteria(attr.OnCriteria));
                }

                foreach (var attr in rowCustomAttributes.OfType <InnerJoinAttribute>())
                {
                    new InnerJoin(this.joins, attr.ToTable, attr.Alias, new Criteria(attr.OnCriteria));
                }

                foreach (var attr in rowCustomAttributes.OfType <OuterApplyAttribute>())
                {
                    new OuterApply(this.joins, attr.InnerQuery, attr.Alias);
                }

#if !COREFX
                var propertyDescriptorArray = new PropertyDescriptor[this.Count];
                for (int i = 0; i < this.Count; i++)
                {
                    var field = this[i];
                    propertyDescriptorArray[i] = new FieldDescriptor(field);
                }

                this.propertyDescriptors = new PropertyDescriptorCollection(propertyDescriptorArray);
#endif

                InferTextualFields();
                AfterInitialize();
            }

            isInitialized = true;
        }
Exemplo n.º 13
0
 public Builder SetScale(ScaleAttribute scale)
 {
     Preconditions.IsNotNull(scale, "Mesh scale property cannot be set to null");
     this.scale = scale;
     return(this);
 }
Exemplo n.º 14
0
 protected bool Equals(ScaleAttribute other)
 {
     return(X.Equals(other.X) && Y.Equals(other.Y) && Z.Equals(other.Z));
 }