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
Пример #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);
                }
            }
        }
        /// <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="setParent">if set to <c>true</c>, the parent of the property will be set.</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, bool setParent, EventHandler <AdvancedPropertyChangedEventArgs> propertyChangedEventHandler,
                                        bool isSerializable, bool includeInSerialization, bool includeInBackup, bool isModelBaseProperty, bool lateRegistration, bool isCalculatedProperty)
        {
            var objectType = GetType();

            if ((defaultValue == 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);
            }

            lock (_initializedTypesLock)
            {
                if (!_initializedTypes.Contains(objectType) || lateRegistration)
                {
                    if (!IsPropertyRegistered(name))
                    {
                        var propertyData = new PropertyData(name, type, defaultValue, setParent, propertyChangedEventHandler,
                                                            isSerializable, includeInSerialization, includeInBackup, isModelBaseProperty, isCalculatedProperty);
                        PropertyDataManager.RegisterProperty(objectType, name, propertyData);

#if !WINDOWS_PHONE && !NETFX_CORE && !PCL && !NET35
                        // Skip validation for modelbase properties
                        if (propertyData.IsModelBaseProperty)
                        {
                            _propertyValuesIgnoredOrFailedForValidation[type].Add(propertyData.Name);
                        }
#endif
                    }
                }
            }

            lock (_propertyValuesLock)
            {
                if (!_propertyBag.IsPropertyAvailable(name))
                {
                    SetValueFast(name, defaultValue);
                }
            }
        }