修复所需非静态字段的错误

fixing error of required non-static field

我想在我的模块迁移中创建一篇文章作为内容类型的内容部分,但是当我添加文章时,代码显示错误。 这是代码:

public int UpdateFrom3() {
            ContentDefinitionManager.AlterPartDefinition(typeof(TourPart).Name, cfg => cfg.Attachable());
            ContentDefinitionService.AddPartToType("Article" + "Part", "Tour");
            ContentDefinitionManager.AlterPartDefinition(
                   "Article" + "Part",
                   b => b
                .WithField("Name", f => f
                     .OfType("InputField").WithDisplayName("Name"))
                .WithField("ImageField", f => f
                    .OfType("MediaLibraryPickerField").WithDisplayName("Images")
                    .WithSetting("MediaLibraryPickerField.Hint", "Images everywhere!").WithSetting("MediaLibraryPickerFieldSettings.Required", "False")
                    .WithSetting("MediaLibraryPickerFieldSettings.Multiple", "True"))
               .WithField("ShortDesc", f => f
                   .OfType("TextField").WithDisplayName("Short Description")
                   .WithSetting("TextFieldSettings.Flavor", "Html"))
               .WithField("LongDesc", f => f
                   .OfType("TextField").WithDisplayName("Long Description")
                   .WithSetting("TextFieldSettings.Flavor", "Html")));


            return 4;
        }

ContentDefinitionService.AddPartToType("Article" + "Part", "Tour"); 部分,代码显示如下: 非静态字段需要对象引用 我可以对我的代码做些什么来接受这个?

我自己找到了答案,这是解决方案:

public int UpdateFrom3()
        {
            ContentDefinitionManager.AlterPartDefinition(typeof(TourPart).Name, cfg => cfg.Attachable());

            ContentDefinitionManager.AlterTypeDefinition("Tour",
                cfg => cfg
                    .WithPart(typeof(TourPart).Name)
                    .WithPart("General")
                   );

            ContentDefinitionManager.AlterPartDefinition(
                   "General",
                   b => b
                .WithField("Name", f => f
                     .OfType("InputField").WithDisplayName("Name"))
                .WithField("NameManage", f => f
                     .OfType("InputField").WithDisplayName("NameManage"))
                .WithField("TourTypes", f => f
                     .OfType("InputField").WithDisplayName("TourTypes"))
                .WithField("TourTitle", f => f
                     .OfType("InputField").WithDisplayName("TourTitle"))
                .WithField("TourSubTitle", f => f
                     .OfType("InputField").WithDisplayName("TourSubTitle"))
                .WithField("TourSummary", f => f
                     .OfType("InputField").WithDisplayName("TourSummary"))

               .WithField("AboutTour", f => f
                   .OfType("TextField").WithDisplayName("AboutTour")
                   .WithSetting("TextFieldSettings.Flavor", "Html"))
               .WithField("Duration", f => f
                     .OfType("InputField").WithDisplayName("Duration"))

               .WithField("Cities", f => f
                   .OfType("TextField").WithDisplayName("Cities")
                   .WithSetting("TextFieldSettings.Flavor", "Html"))
               .WithField("TourIncludes", f => f
                   .OfType("TextField").WithDisplayName("TourIncludes")
                   .WithSetting("TextFieldSettings.Flavor", "Html"))
               .WithField("TourDestination", f => f
                     .OfType("InputField").WithDisplayName("TourDestination")));


            return 4;
        }