Archetype.PropertyEditors.ArchetypePropertyEditor.ArchetypePropertyValueEditor.ConvertDbToEditor C# (CSharp) Метод

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

A method used to format the database value to a value that can be used by the editor
The object returned will automatically be serialized into json notation. For most property editors the value returned is probably just a string but in some cases a json structure will be returned.
public ConvertDbToEditor ( Property property, PropertyType propertyType, IDataTypeService dataTypeService ) : object
property Property
propertyType PropertyType
dataTypeService IDataTypeService
Результат object
            public override object ConvertDbToEditor(Property property, PropertyType propertyType, IDataTypeService dataTypeService)
            {
                if(property.Value == null || property.Value.ToString() == "")
                    return string.Empty;

                var archetype = ArchetypeHelper.Instance.DeserializeJsonToArchetype(property.Value.ToString(), propertyType.DataTypeDefinitionId);

                foreach (var fieldset in archetype.Fieldsets)
                {
                    foreach (var propDef in fieldset.Properties.Where(p => p.DataTypeGuid != null))
                    {
                        try
                        {
                            var dtd = ArchetypeHelper.Instance.GetDataTypeByGuid(Guid.Parse(propDef.DataTypeGuid));
                            var propType = new PropertyType(dtd) {Alias = propDef.Alias};
                            var prop = new Property(propType, propDef.Value);
                            var propEditor = PropertyEditorResolver.Current.GetByAlias(dtd.PropertyEditorAlias);
                            propDef.Value = propEditor.ValueEditor.ConvertDbToEditor(prop, propType, dataTypeService);
                        }
                        catch (Exception ex)
                        {
                            LogHelper.Error<ArchetypePropertyValueEditor>(ex.Message, ex);
                        }
                    }
                }

                return archetype;
            }