需要用构造它的另一个类覆盖命名空间中的方法
我正在尝试重写社区服务器 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题似乎出在您的覆盖 FormatTags
您正在使用剥离的标签创建一个新字符串,但随后将旧字符串发送到基础中。
旧字符串尚未更改,因此您的覆盖没有执行任何操作。
尝试
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