/// <summary>
        /// Autoes the map properties.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public virtual IEnumerable <AbstractPropertyConfiguration> AutoMapProperties(Type type)
        {
            BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance |
                                 BindingFlags.FlattenHierarchy;
            IEnumerable <PropertyInfo> properties = type.GetProperties(flags);

            if (type.IsInterface)
            {
                foreach (var inter in type.GetInterfaces())
                {
                    properties = properties.Union(inter.GetProperties(flags));
                }
            }

            foreach (var property in properties)
            {
                if (Properties.All(x => x.PropertyInfo != property))
                {
                    //skipped already mapped properties
                    if (_properties.Any(x => x.PropertyInfo.Name == property.Name))
                    {
                        continue;
                    }

                    var propConfig = AutoMapProperty(property);
                    if (propConfig != null)
                    {
                        yield return(propConfig);
                    }
                }
            }
        }
예제 #2
0
        public bool IsNumeric()
        {
            if (Properties.Count == 0)
            {
                if (_ForceNumericWhenUnsure)
                {
                    return(true);
                }
                if (ForceObjectWhenUnsure)
                {
                    return(false);
                }
                return(false);//return true;
            }

            if (Properties.Count == 1 && Properties[0].Key == "0")
            {
                if (_ForceNumericWhenUnsure)
                {
                    return(true);
                }
                if (ForceObjectWhenUnsure)
                {
                    return(false);
                }
                return(false);//return true;
            }

            if (NumericMemo.HasValue)
            {
                return(NumericMemo.Value);
            }

            int tmp;

            if (!Properties.All(dr => int.TryParse(dr.Key, out tmp)))
            {
                return(false);
            }

            var baseQry = Properties.Select(dr => dr.Key);

            if (!baseQry.SequenceEqual(baseQry.Distinct()))
            {
                return(false);
            }

            int  counter        = 0;
            bool orderPreserved = true;

            baseQry.Select(dr => int.Parse(dr)).OrderBy(dr => dr).ToList().ForEach(dr =>
            {
                orderPreserved = orderPreserved && (dr == counter);
                counter++;
            });

            NumericMemo = orderPreserved;
            return(orderPreserved);
        }
예제 #3
0
        public override bool IsValid(ILogger <IValidatable> logger)
        {
            var result = base.IsValid(logger);

            return(result &&
                   BaseTypes.All(t => t.IsValid(logger)) &&
                   Properties.All(p => p.IsValid(logger)) &&
                   Events.All(e => e.IsValid(logger)) &&
                   Functions.All(f => f.IsValid(logger)));
        }
예제 #4
0
        public void SetValue(string id, object value)
        {
            Logger.Debug($"Set property {id} to {value}");

            if (Properties.All(x => x.Id != id))
            {
                throw new ValueNotFoundException("Could not find the specified property", id);
            }

            Properties.First(x => x.Id == id).Set(value);
        }
예제 #5
0
        public GameProperty GetProperty(string id)
        {
            Logger.Debug($"Getting property {id}");

            if (Properties.All(x => x.Id != id))
            {
                throw new ValueNotFoundException("Could not find the specified property", id);
            }

            return(Properties.First(x => x.Id == id));
        }
예제 #6
0
 /// <summary>
 /// If PolymorphicDiscriminator is set, makes sure we have a PolymorphicDiscriminator property.
 /// </summary>
 public void AddPolymorphicPropertyIfNecessary()
 {
     if (!string.IsNullOrEmpty(PolymorphicDiscriminator) && Properties.All(p => p.SerializedName != PolymorphicDiscriminator))
     {
         base.Add(New <Property>(new
         {
             Name           = CodeNamerSwift.Instance.GetPropertyName(PolymorphicDiscriminator),
             SerializedName = PolymorphicDiscriminator,
             ModelType      = DiscriminatorEnum,
         }));
     }
 }
예제 #7
0
 /// <summary>
 /// If PolymorphicDiscriminator is set, makes sure we have a PolymorphicDiscriminator property.
 /// </summary>
 private void AddPolymorphicPropertyIfNecessary()
 {
     if (!string.IsNullOrEmpty(PolymorphicDiscriminator) && Properties.All(p => p.Name != PolymorphicDiscriminator))
     {
         base.Add(New <Property>(new
         {
             IsRequired     = true,
             Name           = PolymorphicDiscriminator,
             SerializedName = PolymorphicDiscriminator,
             Documentation  = "Polymorphic Discriminator",
             ModelType      = New <PrimaryType>(KnownPrimaryType.String)
         }));
     }
 }
예제 #8
0
        public void SetValue(string id, string fromId)
        {
            if (Properties.All(x => x.Id != id))
            {
                throw new Exception($"Could not the specified property '{id}'");
            }

            if (Properties.All(x => x.Id != fromId))
            {
                throw new Exception($"Could not the specified property '{fromId}'");
            }

            Properties.First(x => x.Id == id).Set(Properties.First(x => x.Id == fromId).Value);
        }
예제 #9
0
        /// <summary>
        /// Autoes the map properties.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public virtual IEnumerable <AbstractPropertyConfiguration> AutoMapProperties(Type type)
        {
            BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance |
                                 BindingFlags.FlattenHierarchy;
            IEnumerable <PropertyInfo> properties = type.GetProperties(flags);

            if (type.IsInterface)
            {
                foreach (var inter in type.GetInterfaces())
                {
                    properties = properties.Union(inter.GetProperties(flags));
                }
            }

            var propList = new List <AbstractPropertyConfiguration>();

            foreach (var property in properties)
            {
                if (Properties.All(x => x.PropertyInfo != property))
                {
                    //skipped already mapped properties
                    if (_properties.Any(x => x.PropertyInfo.Name == property.Name))
                    {
                        continue;
                    }

                    //skip properties that are actually indexers
                    if (property.GetIndexParameters().Length > 0)
                    {
                        continue;
                    }

                    //check for an attribute
                    var propConfig = AttributeTypeLoader.ProcessProperty(property);
                    if (propConfig == null)
                    {
                        //no attribute then automap
                        propConfig = AutoMapProperty(property);
                    }

                    if (propConfig != null)
                    {
                        propList.Add(propConfig);
                    }
                }
            }

            return(propList);
        }
예제 #10
0
 public void RaiseHasCollectionChanges(TrackItem item, string propertyName)
 {
     if (propertyName != null && Properties?.All(p => p.Name != propertyName) == true)
     {
         return;
     }
     OnPropertyChanged(new PropertyChangedEventArgs(nameof(HasCollectionChanges)));
     if (item != null && propertyName != null)
     {
         ItemPropertyChanged?.Invoke(this, new TrackItemEvent <T> {
             Item = item as TrackItem <T>, PropertyNameChanged = propertyName
         });
     }
     ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(nameof(HasErrors)));
 }
예제 #11
0
        public void SyncAttributesAndOperationsFromModel()
        {
            foreach (var umlAttribute in Class.Attributes.Where(umlAttribute => Attributes.All(a => a.UmlAttribute != umlAttribute)))
            {
                Attributes.Add(new UmlDiagramClassAttribute(umlAttribute));
            }

            foreach (var umlProperty in Class.Properties.Where(umlProperty => Properties.All(a => a.UmlProperty != umlProperty)))
            {
                Properties.Add(new UmlDiagramClassProperty(umlProperty));
            }

            foreach (var umlOperation in Class.Operations.Where(umlOperation => Operations.All(c => c.UmlOperation != umlOperation)))
            {
                Operations.Add(new UmlDiagramClassOperation(umlOperation, Class));
            }
        }
예제 #12
0
        public bool Equals(T other)
        {
            if (ReferenceEquals(this, other))
            {
                return(true);
            }
            if (ReferenceEquals(other, null))
            {
                return(false);
            }
            if (GetType() != other.GetType())
            {
                return(false);
            }

            return(Properties.All(property => Equals(property.Get(this), property.Get(other))));
        }
예제 #13
0
        public void AddToValue(string id, int value)
        {
            Console.WriteLine($"[{Format.Time(DateTime.UtcNow)}] Adding {value} to property {id}");

            if (Properties.All(x => x.Id != id))
            {
                throw new Exception($"Could not find the specified property '{id}'");
            }

            GameProperty property = Properties.First(x => x.Id == id);

            if (property.ValueType != typeof(int))
            {
                throw new Exception($"Cannot add to attribute '{id}' as it is not a type of Int32");
            }

            property.Value = (int)property.Value + value;
        }
        /// <summary>
        /// Autoes the map properties.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public virtual IEnumerable <AbstractPropertyConfiguration> AutoMapProperties(Type type)
        {
            IEnumerable <PropertyInfo> properties = Utilities.GetAllProperties(type);

            var propList = new List <AbstractPropertyConfiguration>();

            foreach (var property in properties)
            {
                if (Properties.All(x => x.PropertyInfo != property))
                {
                    //skipped already mapped properties
                    if (_properties.Any(x => x.PropertyInfo.Name == property.Name) || propList.Any(x => x.PropertyInfo.Name == property.Name))
                    {
                        continue;
                    }

                    //skip properties that are actually indexers
                    if (property.GetIndexParameters().Length > 0)
                    {
                        continue;
                    }

                    //check for an attribute
                    var propConfig = AttributeTypeLoader.ProcessProperty(property);
                    if (propConfig == null)
                    {
                        //no attribute then automap
                        propConfig = AutoMapProperty(property);
                    }

                    if (propConfig != null)
                    {
                        propList.Add(propConfig);
                    }
                }
            }

            return(propList);
        }
 protected override bool OnSaveCanExecute()
 {
     return(HasChanges && Properties.All(p => !p.HasErrors));
 }