SharePoint WebPart 类型问题
我想根据传递给方法的 WebPart 类型对 WebPart 执行一些操作。 我发现我正在做:
if(obj is Microsoft.SharePoint.WebPartPages.ContentEditorWebPart)
...
else if (obj is SummaryLinkWebPart)
对所有 WebPart 继续这样做听起来很有趣。我应该使用一种设计模式吗?
I want to do some stuff to WebParts based on the type of WebPart is being passed to a method.
I'm finding that I'm doing:
if(obj is Microsoft.SharePoint.WebPartPages.ContentEditorWebPart)
...
else if (obj is SummaryLinkWebPart)
It smells funny to keep doing this for all WebParts. Is there a design pattern that I should be using instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您需要访问特定于某种类型的成员,那么实际上没有任何超级干净的方法可以做到这一点。如果需要,您可以使用
as
运算符来实现与上面相同的效果:If you need to access members specific to a certain type then there really isn't any superclean way of doing so. If you want, you can use the
as
operator to achieve the same effect as above: