Catel.Data.PropertyDataManager.RegisterProperty C# (CSharp) Метод

RegisterProperty() публичный Метод

Registers a property for a specific type.
The is null. The is null or whitespace. The is null. A property with the same name is already registered.
public RegisterProperty ( Type type, string name, PropertyData propertyData ) : void
type System.Type The type for which to register the property.
name string The name of the property.
propertyData PropertyData The property data.
Результат void
        public void RegisterProperty(Type type, string name, PropertyData propertyData)
        {
            Argument.IsNotNull("type", type);
            Argument.IsNotNullOrWhitespace("name", name);
            Argument.IsNotNull("propertyData", propertyData);

            lock (_propertyDataLock)
            {
                if (!_propertyData.ContainsKey(type))
                {
                    _propertyData[type] = new CatelTypeInfo(type);
                }

                _propertyData[type].RegisterProperty(name, propertyData);
            }
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Initializes a specific property for this object.
        /// </summary>
        /// <param name="name">Name of the property.</param>
        /// <param name="type">Type of the property.</param>
        /// <param name="defaultValue">Default value of the property.</param>
        /// <param name="propertyChangedEventHandler">The property changed event handler.</param>
        /// <param name="isSerializable">if set to <c>true</c>, the property is serializable.</param>
        /// <param name="includeInSerialization">if set to <c>true</c>, the property should be included in the serialization.</param>
        /// <param name="includeInBackup">if set to <c>true</c>, the property should be included in the backup when handling IEditableObject.</param>
        /// <param name="isModelBaseProperty">if set to <c>true</c>, the property is declared by the <see cref="ModelBase"/>.</param>
        /// <param name="lateRegistration">if set to <c>true</c>, the property is assumed to be registered after the official initialization.</param>
        /// <param name="isCalculatedProperty">if set to <c>true</c>, the property is a calculated property.</param>
        /// <exception cref="InvalidPropertyException">The <paramref name="name"/> is <c>null</c> or whitespace.</exception>
        /// <exception cref="PropertyAlreadyRegisteredException">The property is already registered.</exception>
        private void InitializeProperty(string name, Type type, object defaultValue, EventHandler <AdvancedPropertyChangedEventArgs> propertyChangedEventHandler,
                                        bool isSerializable, bool includeInSerialization, bool includeInBackup, bool isModelBaseProperty, bool lateRegistration, bool isCalculatedProperty)
        {
            var objectType = GetType();

            if ((defaultValue is null) && !type.IsNullableType())
            {
                throw Log.ErrorAndCreateException(msg => new PropertyNotNullableException(name, objectType),
                                                  "Property '{0}' is not nullable, please provide a valid (not null) default value", name);
            }

            if (!IsPropertyRegistered(name))
            {
                var propertyData = new PropertyData(name, type, defaultValue, propertyChangedEventHandler,
                                                    isSerializable, includeInSerialization, includeInBackup, isModelBaseProperty, isCalculatedProperty);
                PropertyDataManager.RegisterProperty(objectType, name, propertyData);
            }

            lock (_lock)
            {
                if (!_propertyBag.IsPropertyAvailable(name))
                {
                    SetValueToPropertyBag(name, defaultValue);
                }
            }
        }
All Usage Examples Of Catel.Data.PropertyDataManager::RegisterProperty