/// <inheritdoc />
        protected override bool CanDrawProperty(AttributeWrapper wrapper, HideIfAttribute attribute)
        {
            var target = wrapper.Target;

            FieldInfo conditionField = ReflectionUtility.GetField(target, attribute.ConditionName);

            if (conditionField != null &&
                conditionField.FieldType == typeof(bool))
            {
                return(!(bool)conditionField.GetValue(target));
            }

            MethodInfo conditionMethod = ReflectionUtility.GetMethod(target, attribute.ConditionName);

            if (conditionMethod != null &&
                conditionMethod.ReturnType == typeof(bool) &&
                conditionMethod.GetParameters().Length == 0)
            {
                return(!(bool)conditionMethod.Invoke(target, null));
            }

            string warning = attribute.GetType().Name + " needs a valid boolean condition field or method name to work";

            EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning);

            return(true);
        }
Example #2
0
            public NavigatorState(AttributeWrapper attribute)
            {
                if (attribute == null)
                {
                    throw new ArgumentNullException(nameof(attribute));
                }

                Attribute = attribute;
            }
Example #3
0
            public void SetCurrent(NodeWrapper node)
            {
                if (node == null)
                {
                    throw new ArgumentNullException(nameof(node));
                }

                Node      = node;
                Attribute = null;
            }
Example #4
0
            public void SetCurrent(AttributeWrapper attribute)
            {
                if (attribute == null)
                {
                    throw new ArgumentNullException(nameof(attribute));
                }

                Node      = null;
                Attribute = attribute;
            }
Example #5
0
        private void InitiliaseFormulaColumns(AttributeWrapper attributes)
        {
            foreach (FormulaAttribute formulaAttribute in attributes.FormulaAttributes)
            {
                FormulaColumn column = new FormulaColumn(formulaAttribute, this);

                FormulaColumns.Add(column);
                Columns.Add(column);
            }
        }
        private void MapBean()
        {
            AttributeWrapper wrapper = new AttributeWrapper(BaseType);

            foreach (EntityAttribute entityAttribute in wrapper.EntityAttributes)
            {
                MapType(entityAttribute.EntityType);
                MapToBean(entityAttribute);
            }
        }
        private static PropertyGrouper GetPropertyGrouperForField(AttributeWrapper wrapper)
        {
            var groupAttribute = wrapper.GetCustomAttributes <GroupAttribute>().FirstOrDefault();

            if (groupAttribute == null)
            {
                return(null);
            }

            return(PropertyGrouperDatabase.GetGrouperForAttribute(groupAttribute.GetType()));
        }
        public static bool DrawHeader(AttributeWrapper wrapper)
        {
            HeaderAttribute headerAttr = wrapper.GetCustomAttributes <HeaderAttribute>().FirstOrDefault();

            if (headerAttr != null)
            {
                DrawHeader(headerAttr.header);
                return(true);
            }

            return(false);
        }
Example #9
0
        public void TestAttrbuteWrapper_ShouldLoadAllCorrectAttributesForEntityBean()
        {
            // Arrange
            // Act
            AttributeWrapper wrapper = new AttributeWrapper(typeof(BookInfo));

            // Assert
            Assert.IsNotNull(wrapper.EntityAttributes.Where(e => e.EntityType == typeof(Author) && e.EntityProperty == "FirstName").FirstOrDefault());
            Assert.IsNotNull(wrapper.EntityAttributes.Where(e => e.EntityType == typeof(Book) && e.EntityProperty == "Title").FirstOrDefault());

            Assert.IsTrue(wrapper.EntityAttributes.Count == 2);
        }
Example #10
0
        protected bool TryGetTable(Type type, out EntityTable?table)
        {
            AttributeWrapper attributes = new AttributeWrapper(type);

            if (attributes.IsValid())
            {
                table = new EntityTable(type, attributes);
                return(true);
            }

            table = null;
            return(false);
        }
        public AddAttributeViewModel()
        {
            Attribute = new AttributeWrapper(new Attribute
            {
                IsEditable = true,
                IsOptional = true,
                Entity = ConfigurationStaticData.AttributeEntityName
            });

            OkButtonCommand = new DelegateCommand(OkButtonCommandExecute, OkButtonCommandCanExecute);
            AddButtonCommand = new DelegateCommand(AddButtonCommandExecute, AddButtonCommandCanExecute);
            DeleteButtonCommand = new DelegateCommand(DeleteButtonCommandExecute, DeleteButtonCommandCanExecute);
        }
Example #12
0
        public void TestAttrbuteWrapper_ShouldLoadAllCorrectAttributesForEntityWithoutForeignKey()
        {
            // Arrange
            // Act
            AttributeWrapper wrapper = new AttributeWrapper(typeof(Author));

            // Assert
            Assert.AreEqual(wrapper.TableAttribute.TableName, "authors");

            Assert.IsNotNull(wrapper.ColumnAttributes.Where(c => c.ColumnName == "id").FirstOrDefault());
            Assert.IsNotNull(wrapper.ColumnAttributes.Where(c => c.ColumnName == "first_name").FirstOrDefault());
            Assert.IsNotNull(wrapper.ColumnAttributes.Where(c => c.ColumnName == "last_name").FirstOrDefault());

            Assert.IsTrue(wrapper.ColumnForeignKeys.Keys.Count() == 0);
            Assert.IsTrue(wrapper.ColumnPrimaryKeys.Keys.Count() == 1);
            Assert.IsTrue(wrapper.ColumnPrimaryKeys.Keys.First().ColumnName == "id");
        }
Example #13
0
        public void TestAttrbuteWrapper_ShouldLoadAllCorrectAttributesForEntityWithForeignKey()
        {
            // Arrange
            // Act
            AttributeWrapper wrapper = new AttributeWrapper(typeof(Book));

            // Assert
            Assert.AreEqual(wrapper.TableAttribute.TableName, "books");

            Assert.IsNotNull(wrapper.ColumnAttributes.Where(c => c.ColumnName == "id").FirstOrDefault());
            Assert.IsNotNull(wrapper.ColumnAttributes.Where(c => c.ColumnName == "author_id").FirstOrDefault());
            Assert.IsNotNull(wrapper.ColumnAttributes.Where(c => c.ColumnName == "title").FirstOrDefault());
            Assert.IsNotNull(wrapper.FormulaAttributes.Where(f => f.Alias == "avg_score").FirstOrDefault());

            Assert.IsTrue(wrapper.ColumnForeignKeys.Keys.Count() == 1);
            Assert.IsTrue(wrapper.ColumnForeignKeys.Keys.First().ColumnName == "author_id");
            Assert.IsTrue(wrapper.ColumnPrimaryKeys.Keys.Count() == 1);
            Assert.IsTrue(wrapper.ColumnPrimaryKeys.Keys.First().ColumnName == "id");
        }
Example #14
0
        private void InitialiseEntityColumns(AttributeWrapper attributes)
        {
            foreach (ColumnAttribute columnAttribute in attributes.ColumnAttributes)
            {
                EntityColumn column     = new EntityColumn(columnAttribute, this);
                DataColumn   dataColumn = column.DataColumn;

                if (attributes.ColumnForeignKeys.ContainsKey(columnAttribute))
                {
                    ForeignKeyAttribute key = attributes.ColumnForeignKeys[columnAttribute];

                    column.ForeignKeyTableMapping = key.ForeignTable;
                    column.KeyType = (byte)KeyTypes.ForeignKey;

                    foreignKeyColumns.Add(column);
                    foreignKeyColumnsDict.Add(column.ForeignKeyTableMapping, column);
                }

                if (attributes.ColumnPrimaryKeys.ContainsKey(columnAttribute))
                {
                    PrimaryKeyAttribute key = attributes.ColumnPrimaryKeys[columnAttribute];

                    column.KeyType = (byte)KeyTypes.PrimaryKey;

                    primaryKeyColumn = column;
                }

                /*
                 * Bulk inserts can only be performed on data that is mapped to a physical column in the database. These are
                 * represented by instances of the EntityColumn class, and contain specific methods which determine key type
                 * etc.
                 */

                if (!column.IsPrimaryKey())
                {
                    DataTable.Columns.Add(dataColumn);
                }

                EntityColumns.Add(column);
                Columns.Add(column);
            }
        }
Example #15
0
        public void TestAttributeWrapper_ShouldFailOnMalformedEntityBean()
        {
            // Arrange
            // Act
            // Assert
            try
            {
                AttributeWrapper wrapper = new AttributeWrapper(typeof(MalformedBookInfo));

                Assert.Fail();
            }
            catch (MappingException e)
            {
                Assert.AreEqual("Cannot define Formula columns for an Entity based mapping for class MalformedBookInfo", e.Message);
            }
            catch (Exception e)
            {
                Assert.Fail();
            }
        }
        /// <inheritdoc />
        protected override bool IsPropertyEnabled(AttributeWrapper wrapper, DisableIfAttribute attribute)
        {
            bool drawDisabled   = false;
            bool validCondition = false;

            var target = wrapper.Target;

            var conditionField    = ReflectionUtility.GetField(target, attribute.ConditionName);
            var conditionMethod   = ReflectionUtility.GetMethod(target, attribute.ConditionName);
            var conditionProperty = ReflectionUtility.GetProperty(target, attribute.ConditionName);

            if (conditionField != null && conditionField.FieldType == typeof(bool))
            {
                drawDisabled   = (bool)conditionField.GetValue(target);
                validCondition = true;
            }
            else if (conditionMethod != null &&
                     conditionMethod.ReturnType == typeof(bool) &&
                     conditionMethod.GetParameters().Length == 0)
            {
                drawDisabled   = (bool)conditionMethod.Invoke(target, null);
                validCondition = true;
            }
            else if (conditionProperty != null &&
                     conditionProperty.PropertyType == typeof(bool))
            {
                drawDisabled   = (bool)conditionProperty.GetValue(target);
                validCondition = true;
            }

            if (validCondition)
            {
                return(!drawDisabled);
            }

            string warning = attribute.GetType().Name + " needs a valid boolean condition field or method name to work";

            EditorDrawUtility.DrawHelpBox(warning, MessageType.Warning);
            return(true);
        }
Example #17
0
        private static IodineObject AttributeOff(VirtualMachine vm, IodineObject self, IodineObject[] args)
        {
            if (args.Length == 0)
            {
                vm.RaiseException(new IodineArgumentException(1));
                return(null);
            }

            AttributeWrapper attrWrapper = args [0] as AttributeWrapper;

            if (attrWrapper == null)
            {
                vm.RaiseException(new IodineTypeException("TerminalAttribute"));
                return(null);
            }

            TerminalAttributes attr = attrWrapper.Value;

            activeTerminal.AttributesOff(attr);

            return(null);
        }
Example #18
0
        internal EntityTable(Type type, AttributeWrapper attributes)
            : base()
        {
            Type            = type;
            EntityActivator = ReflectionUtil.GetActivator(Type);
            Name            = attributes.TableAttribute?.TableName ?? throw new TableMappingException(type, "Unknown");
            Alias           = type.Name;
            Entities        = new List <IEntity>();
            DataTable       = new DataTable(Name);
            ChildTables     = new List <EntityTable>();

            _attributes           = attributes;
            primaryKeyColumn      = null;
            foreignKeyColumnsDict = new Dictionary <string, EntityColumn?>();
            foreignKeyColumns     = new List <EntityColumn>();
            dataRows = new Dictionary <IEntity, DataRow>();

            InitialiseEntityColumns(attributes);
            InitiliaseFormulaColumns(attributes);

            StagingTable = new StagingTable(this);

            Logger.Trace($"Loaded database mapping for Entity '{Type.Name}' (Table '{Name}')");
        }
 /// <inheritdoc />
 protected override bool IsPropertyEnabled(AttributeWrapper wrapper, DisableInEditorModeAttribute attribute)
 {
     return(EditorApplication.isPlaying);
 }
Example #20
0
 public abstract bool IsPropertyEnabled(AttributeWrapper wrapper, NaughtyAttribute attribute);
 /// <inheritdoc />
 protected override bool CanDrawProperty(AttributeWrapper wrapper, HideInEditorModeAttribute attribute)
 {
     return(EditorApplication.isPlaying);
 }
Example #22
0
 public GumboNavigator(GumboWrapper gumbo, AttributeWrapper attribute)
 {
     _Gumbo = gumbo;
     _State = new NavigatorState(attribute);
 }
Example #23
0
            public void CanRunTestThatWasDiscoveredWithoutReflection()
            {
                var typeUnderTest = typeof(ClassUnderTest);
                var methodUnderTest = typeUnderTest.GetMethod("TestMethod");
                var factAttributeUnderTest = CustomAttributeData.GetCustomAttributes(methodUnderTest).Single(a => a.AttributeType == typeof(FactAttribute));

                var assembly = new AssemblyWrapper(Reflector.Wrap(typeUnderTest.Assembly));
                var type = new TypeWrapper(Reflector.Wrap(typeUnderTest));
                var method = new MethodWrapper(Reflector.Wrap(methodUnderTest));
                var attribute = new AttributeWrapper(Reflector.Wrap(factAttributeUnderTest));
                var testCase = TestableXunitTestCase.Create(assembly, type, method, attribute);

                testCase.RunTests();

                Assert.Collection(testCase.Messages,
                    message => Assert.IsAssignableFrom<ITestStarting>(message),
                    message => Assert.IsAssignableFrom<ITestClassConstructionStarting>(message),
                    message => Assert.IsAssignableFrom<ITestClassConstructionFinished>(message),
                    message =>
                    {
                        var failed = Assert.IsAssignableFrom<ITestFailed>(message);
                        Assert.Equal(typeof(TrueException).FullName, failed.ExceptionType);
                    },
                    message => Assert.IsAssignableFrom<ITestFinished>(message)
                );
            }
 /// <inheritdoc />
 protected override bool IsPropertyEnabled(AttributeWrapper wrapper, ReadOnlyAttribute attribute)
 {
     return(false);
 }
 public abstract void Run(AttributeWrapper wrapper, NaughtyAttribute attribute);
Example #26
0
 public abstract bool CanDrawProperty(AttributeWrapper wrapper, NaughtyAttribute attribute);