Catel.MVVM.ViewModelBase.InitializeViewModelAttributes C# (CSharp) Method

InitializeViewModelAttributes() protected method

Initializes the view model attributes, such as the ModelAttribute and ViewModelToModelAttribute. This method is automatically invoked by the constructor. Sometimes, dynamic properties are registered after the constructor. Therefore, it is possible to skip the initialization of the attributes and handle this manually.
A mapped model is not registered. A mapped model property is not found.
protected InitializeViewModelAttributes ( ) : void
return void
        protected void InitializeViewModelAttributes()
        {
            if (_areViewModelAttributesIntialized)
            {
                return;
            }

            _areViewModelAttributesIntialized = true;

            SuspendValidation = true;

            InitializePropertiesWithAttributes();

            lock (_modelLock)
            {
                foreach (var modelInfo in _modelObjectsInfo)
                {
                    _modelObjects.Add(modelInfo.Key, null);
                }
            }

            if (SupportIEditableObject)
            {
                lock (_modelLock)
                {
                    foreach (var modelKeyValuePair in _modelObjects)
                    {
                        if (_modelObjectsInfo[modelKeyValuePair.Key].SupportIEditableObject)
                        {
                            var modelKeyValuePairValueAsModelBaseBase = modelKeyValuePair.Value as IModel;
                            if ((modelKeyValuePairValueAsModelBaseBase == null) || !modelKeyValuePairValueAsModelBaseBase.IsInEditSession)
                            {
                                EditableObjectHelper.BeginEditObject(modelKeyValuePair.Value);
                            }
                        }
                    }
                }
            }

            ValidateViewModelToModelMappings();

            if (!_ignoreMultipleModelsWarning)
            {
                lock (_modelLock)
                {
                    if (_modelObjects.Count > 1)
                    {
                        Log.Warning("The view model {0} implements {1} models.\n\n" +
                                    "Normally, a view model only implements 1 model so make sure you are using the Model attribute correctly. If the Model attribute is used correctly (on models only), this warning can be ignored by using a constructor overload.",
                            GetType().Name, _modelObjects.Count);
                    }
                }
            }

            SuspendValidation = false;
        }