可以继承SPWeb吗?

时间:2010-10-14 12:53:03

标签: sharepoint inheritance spsite spweb splist

可以从SharePoint类继承,例如:SPWeb,SPList等。 或者这个课程是密封的?我找不到正确答案。

克里斯


感谢您的回复。 Rich,你是对的 - 构造函数是内部的。所以这意味着我不能以任何优雅的方式扩展这些类的功能?

5 个答案:

答案 0 :(得分:2)

根据Reflector的说法,SPWeb在2007年或2010年都没有封存。

2007:

[SharePointPermission(SecurityAction.LinkDemand, ObjectModel=true), 
SharePointPermission(SecurityAction.LinkDemand, ObjectModel=true), 
SharePointPermission(SecurityAction.LinkDemand, ObjectModel=true), 
SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel=true)]
public class SPWeb : IDisposable, ISecurableObject

2010:

[SubsetCallableType, 
ClientCallableType(Name="Web", ServerTypeId="{A489ADD2-5D3A-4de8-9445-49259462DCEB}", FactoryType=typeof(SPObjectFactory), ObjectIdentityPropertyName="CanonicalId"), 
SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel=true), 
SharePointPermission(SecurityAction.LinkDemand, ObjectModel=true), 
SharePointPermission(SecurityAction.LinkDemand, ObjectModel=true), 
SharePointPermission(SecurityAction.LinkDemand, ObjectModel=true)]
public class SPWeb : SPSecurableObject, IDisposable

但是,在这两个版本中,该类只有内部构造函数,因此虽然Visual Studio允许您尝试从类继承,但它不会编译:

  

“Microsoft.SharePoint.SPWeb”类型   没有定义构造函数

答案 1 :(得分:0)

根据他们的MSDN页面,这些课程没有密封:

SPWeb Class

SPList Class

即使您可以从这些类继承,但我没有看到这一点,因为您无法强制SharePoint在内部使用它们。

通过扩展方法提供添加的功能可能更有意义,而不是实际从基类继承。

答案 2 :(得分:0)

SPWeb和SPList密封在SharePoint 2007中,请参阅:http://blogs.msdn.com/b/francischeung/archive/2008/08/22/unit-testing-sharepoint-2007-applications.aspx

但它们未在SharePoint 2010中封存,请参阅:http://my.safaribooksonline.com/9781435456457/365

答案 3 :(得分:0)

当然,只需使用扩展方法 - http://msdn.microsoft.com/en-us/library/bb383977.aspx

即可扩展它们

作为一个例子,我试图推动一下,你可以看一下https://github.com/kerray/NAVERTICA-SPTools中的ItemTools,ListTools或其他源文件

答案 4 :(得分:0)

我认为很多SharePoint服务器对象模型程序员都遇到过这个问题。

首先,我简单地从一个辅助类开始,作为SPWeb的包装器,它使用托管导航。

随着要求变得更加复杂,我必须处理多种类型的SPWeb。因此,我重新编写了代码,创建了一个Factory类来实例化类型化的SPSite和SPWeb。它将SPWeb与托管元数据术语绑定,并将类型信息存储在SPWeb属性和术语定制属性中。

我想帮助Microsoft了解这是否是一个有意义的设计。如果微软有必要为此启动一个开源项目。由于有时程序员必须专注于业务逻辑,不要一次又一次地实现Factory,Abstract Factory。

https://social.msdn.microsoft.com/Forums/office/en-US/62c1355f-0b71-49b7-967a-648830bd6dfa/creating-a-factory-class-with-sharepoint-server-side-api-to-instantiate-a-wrapper-class-around#62c1355f-0b71-49b7-967a-648830bd6dfa

相关问题