예제 #1
0
        internal PropertyInfo[] GetPropertiesFromCache(Type type)
        {
            if (type == null)
            {
                return(new PropertyInfo[0]);
            }

            var entityName = type.AssemblyQualifiedName;

            if (PropertyCache.ContainsKey(entityName))
            {
                PropertyCache.TryGetValue(entityName, out var properties);
                return(properties);
            }

            var props = type.GetTypeInfo().GetProperties();

            if (IsAnonymousType(type))
            {
                return(props);
            }

            PropertyCache.TryAdd(entityName, props);
            return(props);
        }
예제 #2
0
        bool IsUniqueProperty <T>(string property)
        {
            var  key = typeof(T).FullName + property;
            bool value;

            if (!PropertyCache.TryGetValue(key, out value))
            {
                value = UniqueAttribute.GetUniqueProperties(typeof(T)).Any(p => p.Name == property);
                PropertyCache[key] = value;
            }

            return(value);
        }
            public PropertyStorage(object value)
            {
                Debug.Assert(value != null);
                Value = value;

                // Cache the properties so we can know if we've already validated them for duplicates.
                var type = Value.GetType();

                if (!_propertyCache.TryGetValue(type, out Properties))
                {
                    Properties = PropertyHelper.GetVisibleProperties(type);
                    ValidatePropertyNames(type, Properties);
                    _propertyCache.TryAdd(type, Properties);
                }
            }
예제 #4
0
        /// <summary>
        /// 处理 <see cref="E:ConfigurationSourceChanged" /> 事件.
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">包含事件信息的 <see cref="ConfigurationChangedEventArgs"/> 类的实例</param>
        protected void OnConfigurationSourceChanged(object sender, ConfigurationChangedEventArgs e)
        {
            e.ChangedProperties.Foreach(item =>
            {
                if (string.IsNullOrWhiteSpace(item.Key))
                {
                    return;
                }

                IProperty property;
                if (PropertyCache.TryGetValue(item.Key, out property))
                {
                    property.Refresh();
                }

                if (OnPropertyChange != null && !string.Equals(item.OldValue, item.NewValue))
                {
                    OnPropertyChange(this, new PropertyChangedEventArgs(item.Key, item.OldValue, item.NewValue, item.ChangedTime));
                }
            });
        }