Beispiel #1
0
        /// <summary> If Xml properties are defined, they will override the definition of the existing ones.</summary>
        private void OverridePropertiesFromXml(List <XmlModelProperty> properties)
        {
            if (properties == null)
            {
                return;
            }
            try
            {
                foreach (XmlModelProperty property in properties)
                {
                    if (string.IsNullOrEmpty(property.Name))
                    {
                        throw new EtkException("A property name cannot be null or empty");
                    }

                    IModelProperty existingProperty;
                    // Override an existing model property definition
                    if (PropertiesByName.TryGetValue(property.Name.ToUpper(), out existingProperty))
                    {
                        existingProperty.Description = property.Description;
                        if (!string.IsNullOrEmpty(property.NameToUse))
                        {
                            PropertiesByName.Remove(existingProperty.Name.ToUpper());
                            existingProperty.Name = property.NameToUse;
                            PropertiesByName[existingProperty.Name.ToUpper()] = existingProperty;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new EtkException($"Cannot retrieve properties for UnderlyingType '{Name.EmptyIfNull()}': {ex.Message}");
            }
        }
Beispiel #2
0
        /// <summary> Implements <see cref="IModelType.GetProperty"/> </summary>
        public IModelProperty GetProperty(string name)
        {
            if (!dependenciesResolved)
            {
                ResolveDependencies();
            }

            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }

            IModelProperty modelProperty;

            if (PropertiesByName.TryGetValue(name.ToUpper(), out modelProperty))
            {
                return(modelProperty);
            }

            ModelLinkProperty modelLinkProperty;

            if (LinkPropertiesByName != null && LinkPropertiesByName.TryGetValue(name.ToUpper(), out modelLinkProperty))
            {
                return(modelLinkProperty);
            }

            return(null);
        }
 public PropertyInfo GetProperty(string name)
 {
     if (PropertiesByName.TryGetValue(name, out PropertyInfo property) ||
         PropertiesByLogicalName.TryGetValue(name, out property))
     {
         return(property);
     }
     throw new KeyNotFoundException($"The property \"{name}\" was not found in the entity type \"{EntityName}\".");
 }
Beispiel #4
0
        private void ModelOnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (PropertiesByName.ContainsKey(e.PropertyName))
            {
                RaisePropertyChanged(e.PropertyName);
            }

            if (e.PropertyName.IsNullOrEmpty())
            {
                RaisePropertyChangedForAll();
            }

            OnModelPropertyChanged(e.PropertyName);
        }
Beispiel #5
0
 public GenericTypeInfo GatherTypeInfo(AttributeType propertyAttributes = AttributeType.None)
 {
     DetermineObjectType();
     if (IsPoco)
     {
         Properties = GenericType.GetProperties().ToList();
         for (int i = 0; i < Properties.Count; i++)
         {
             var propInfo = Properties[i];
             ThrowIfPropIsIndexer(propInfo);
             PropertyNames.Add(propInfo.Name);
             PropertiesByName.Add(propInfo.Name, propInfo);
             UnderlyingPropType.Add(propInfo, TryGetUnderlyingType(propInfo));
             TryExtractAttribute(propertyAttributes, propInfo);
             RetrieveAdditionalTypeInfo(propInfo, i);
         }
     }
     return(this);
 }
Beispiel #6
0
 /// <summary>
 /// Reads the type information from <see cref="Typ"/>.
 /// </summary>
 /// <returns>The TypeInfo object containing information about the Typ.</returns>
 public TypeInfo GatherTypeInfo()
 {
     IsArray = Typ.IsArray;
     if (typeof(IDynamicMetaObjectProvider).IsAssignableFrom(Typ))
     {
         IsDynamic = true;
     }
     if (!IsArray && !IsDynamic)
     {
         Properties     = Typ.GetProperties();
         PropertyLength = Properties.Length;
         int index = 0;
         foreach (var propInfo in Properties)
         {
             PropertyIndex.Add(propInfo.Name, index);
             PropertiesByName.Add(propInfo.Name, propInfo);
             RetrieveAdditionalTypeInfo(propInfo, index);
             index++;
         }
     }
     return(this);
 }
 public bool ContainsProperty(string name)
 {
     return(PropertiesByName.ContainsKey(name) ||
            PropertiesByLogicalName.ContainsKey(name));
 }