需要用构造它的另一个类覆盖命名空间中的方法

发布于 2024-07-15 12:34:36 字数 1708 浏览 3 评论 0原文

我正在尝试重写社区服务器 SDK 中名为“InlineTagsContainerTagEditor”的控件上的方法。

当我找到该控件的源代码时,它位于另一个名为“TaggableContentTagEditableList”的类的文件内。

我认为相关部分如下:

namespace CommunityServer.Controls
{
    public class TaggableContentTagEditableList : WrappedContentBase, ICallbackEventHandler
    {
       protected virtual InlineTagsContainerTagEditor GetInlineTagEditor(ITagsContainer container)
        {
            return new InlineTagsContainerTagEditor(container);
        }

    }
    public class InlineTagsContainerTagEditor : TWC.InlineEditor
    {
        ITagsContainer _container;

        public InlineTagsContainerTagEditor(ITagsContainer container)
            : base()
        {
            _container = container;
        }

    }
}

我只是想创建一个删除某些“标签”的 TaggableContentEditableList 版本。 我尝试在下面覆盖该方法 - 但我非常迷失。 我是否必须重写 TaggableContentTagEditableList 的构造函数才能让构造函数使用我的重写方法查找正确的类型?

public partial class TaggableContentEditableListExclude : TaggableContentTagEditableList
{
    protected override InlineTagsContainerTagEditor GetInlineTagEditor(ITagsContainer container)
    {
        return new TagExcludeOption(container);
    }
}

public partial class TagExcludeOption : InlineTagsContainerTagEditor
{
    ITagsContainer _container;

    public TagExcludeOption(ITagsContainer container) : base(container)
     {
        _container = container;
    }

    public override string FormatTags(string[] tagList)
    {
        // strip special tags
        string[] newTagList = stripTags(tagList);
        return base.FormatTags(newTagList);
    }

    private string[] stripTags(string[] tagList)
    {
        //doing something here
    }
}

I am trying to override a method on a control in the Community Server SDK called 'InlineTagsContainerTagEditor'.

When I find the source for this control, it is inside of a file with another class called 'TaggableContentTagEditableList'.

Here is what I think the relevant parts are:

namespace CommunityServer.Controls
{
    public class TaggableContentTagEditableList : WrappedContentBase, ICallbackEventHandler
    {
       protected virtual InlineTagsContainerTagEditor GetInlineTagEditor(ITagsContainer container)
        {
            return new InlineTagsContainerTagEditor(container);
        }

    }
    public class InlineTagsContainerTagEditor : TWC.InlineEditor
    {
        ITagsContainer _container;

        public InlineTagsContainerTagEditor(ITagsContainer container)
            : base()
        {
            _container = container;
        }

    }
}

I am just trying to create a version of the TaggableContentEditableList which removes certain 'tags'. The method for that I have attempted to override below - but I get very lost. Do I have to override the constructor for TaggableContentTagEditableList in order to have the constructor look for the correct type with my overriden method?

public partial class TaggableContentEditableListExclude : TaggableContentTagEditableList
{
    protected override InlineTagsContainerTagEditor GetInlineTagEditor(ITagsContainer container)
    {
        return new TagExcludeOption(container);
    }
}

public partial class TagExcludeOption : InlineTagsContainerTagEditor
{
    ITagsContainer _container;

    public TagExcludeOption(ITagsContainer container) : base(container)
     {
        _container = container;
    }

    public override string FormatTags(string[] tagList)
    {
        // strip special tags
        string[] newTagList = stripTags(tagList);
        return base.FormatTags(newTagList);
    }

    private string[] stripTags(string[] tagList)
    {
        //doing something here
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

喵星人汪星人 2024-07-22 12:34:36

您的问题似乎出在您的覆盖 FormatTags

您正在使用剥离的标签创建一个新字符串,但随后将旧字符串发送到基础中。

旧字符串尚未更改,因此您的覆盖没有执行任何操作。

尝试

public override string FormatTags(string[] tagList)
{
    // strip special tags
    string[] newTagList = stripTags(tagList);
    return base.FormatTags(newTagList);
}

Your problem seems to be in your override FormatTags

You are creating a new string with your stripped tags but then you send the old string into the base.

The old string hasn't been altered so your override isn't doing anything.

Try

public override string FormatTags(string[] tagList)
{
    // strip special tags
    string[] newTagList = stripTags(tagList);
    return base.FormatTags(newTagList);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文