Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Daniel Rogers 134 posts 712 karma points
    Mar 25, 2022 @ 15:05
    Daniel Rogers
    0

    Porting dataType creation in c# from8 to 9

    I are trying to create a data type in c# but getting stuck.

    Umbraco8

    var exists = current.PropertyEditor.TryGet(alias, out editor);
    if (!exists)
    {
    DataType newDataType = new DataType(editor)
    .......
    }
    

    umbraco9 so far

    IDataType editor = _dataTypeService.GetByEditorAlias(docType).FirstOrDefault();
    if (editor == null)
    {
        var serializer = new IConfigurationEditorJsonSerializer();
        DataType newDataType = new DataType(editor.Editor, serializer, containerId);
    ............
    }
    

    as per https://our.umbraco.com/Documentation/Reference/Management/Models/DataType

    how ever I cant find any implementation on what I supposed to do with IConfigurationEditorJsonSerializer hence the guess in the line.

    any suggestions would be great.

  • Daniel Rogers 134 posts 712 karma points
    Mar 26, 2022 @ 15:51
    Daniel Rogers
    100

    Found the answer

    public class abc
            private readonly IConfigurationEditorJsonSerializer _serializer;
            public IBDInstallService(IPublishedContentQuery publishedContentQuery,
                IDataTypeService dataTypeService, 
                IConfigurationEditorJsonSerializer serializer,
                IShortStringHelper shortStringHelper)
            {
                _dataTypeService = dataTypeService;
                _serializer = serializer;
                _shortStringHelper = shortStringHelper;
            }
    
    public void Create DataType ()
    {
    ......
    var editor = _dataTypeService.GetByEditorAlias(docType).FirstOrDefault();
                    if (editor != null)
                    {
    
                        DataType newDataType = new DataType(editor.Editor, _serializer, containerId);
    .........
    
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft