Composite.Data.DynamicTypes.DataTypeDescriptorFormsHelper.BindingsToObject C# (CSharp) Méthode

BindingsToObject() public méthode

public BindingsToObject ( object>.Dictionary bindings, IData dataObject ) : string>.Dictionary
bindings object>.Dictionary
dataObject IData
Résultat string>.Dictionary
        public Dictionary<string, string> BindingsToObject(Dictionary<string, object> bindings, IData dataObject)
        {
            var errorMessages = new Dictionary<string, string>();

            foreach (var fieldDescriptor in _dataTypeDescriptor.Fields)
            {
                if (_readOnlyFields.Contains(fieldDescriptor.Name))
                {
                    continue;
                }

                var bindingName = GetBindingName(fieldDescriptor);

                if (!bindings.ContainsKey(bindingName))
                {
                    Verify.That(fieldDescriptor.IsNullable, "Missing value for field '{0}'", fieldDescriptor.Name);
                    continue;
                }

                var propertyInfo = dataObject.GetType().GetProperty(fieldDescriptor.Name);

                if (propertyInfo.CanWrite)
                {
                    var newValue = bindings[bindingName];

                    if (newValue is string && (newValue as string) == "" && IsNullableStringReference(propertyInfo))
                    {
                        newValue = null;
                    }

                    try
                    {
                        newValue = ValueTypeConverter.Convert(newValue, propertyInfo.PropertyType);

                        propertyInfo.GetSetMethod().Invoke(dataObject, new[] { newValue });
                    }
                    catch (Exception ex)
                    {
                        errorMessages.Add(bindingName, ex.Message);
                    }
                }
            }

            if (_showPublicationStatusSelector &&
                _dataTypeDescriptor.SuperInterfaces.Contains(typeof(IPublishControlled)))
            {
                var publishControlled = dataObject as IPublishControlled;

                publishControlled.PublicationStatus = (string)bindings[PublicationStatusBindingName];
            }

            if (errorMessages.Count > 0)
            {
                return errorMessages;
            }

            return null;
        }

Usage Example

        private void finalizeCodeActivity_Finalize_ExecuteCode(object sender, EventArgs e)
        {
            Type selectedMetaDataType = this.GetBinding<Type>(SelectedTypeBindingName);
            DataTypeDescriptor dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(selectedMetaDataType.GetImmutableTypeId());

            PageMetaDataDescription dataAssociationVisabilityRule = this.GetBinding<PageMetaDataDescription>(DataAssociationVisabilityDescriptionBindingName);
            Guid metaDataContainerId = this.GetBinding<Guid>(SelectedContainerBindingName);
            string metaDataDefinitionName = this.GetBinding<string>(FieldGroupNameBindingName);
            string metaDataDefinitionLabel = this.GetBinding<string>(FieldGroupLabelBindingName);

            IData newDataTemplate = null;
            if (IsAnyPagesAffected())
            {
                DataTypeDescriptorFormsHelper helper = new DataTypeDescriptorFormsHelper(dataTypeDescriptor);

                GeneratedTypesHelper generatedTypesHelper = new GeneratedTypesHelper(dataTypeDescriptor);
                helper.AddReadOnlyFields(generatedTypesHelper.NotEditableDataFieldDescriptorNames);

                newDataTemplate = DataFacade.BuildNew(selectedMetaDataType);
                helper.BindingsToObject(this.Bindings, newDataTemplate);
            }
            

            using (TransactionScope transactionScope = TransactionsFacade.CreateNewScope())
            {
                IPage page = GetCurrentPage();

                page.AddMetaDataDefinition(metaDataDefinitionName, metaDataDefinitionLabel, selectedMetaDataType.GetImmutableTypeId(), metaDataContainerId, dataAssociationVisabilityRule.StartLevel, dataAssociationVisabilityRule.Levels);

                if (newDataTemplate != null)
                {
                    page.AddNewMetaDataToExistingPages(metaDataDefinitionName, newDataTemplate);
                }

                transactionScope.Complete();
            }

            ParentTreeRefresher parentTreeRefresher = this.CreateParentTreeRefresher();
            parentTreeRefresher.PostRefreshMesseges(this.EntityToken);
        }
All Usage Examples Of Composite.Data.DynamicTypes.DataTypeDescriptorFormsHelper::BindingsToObject