是否可以从SharePoint类继承,如: SPWeb、SPList等,或者这个类是密封的?我找不到正确的答案。
克里斯
谢谢你的回复。里奇,你说得对--构造器是内部的。所以这意味着我不能以任何优雅的方式扩展这些类的功能?
发布于 2010-10-14 15:34:57
根据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, ISecurableObject2010年:
[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将允许您尝试从类继承,但它不会编译:
类型'Microsoft.SharePoint.SPWeb‘没有定义构造函数
发布于 2010-10-14 12:55:39
根据它们的MSDN页面,类不被密封:
SPWeb类
SPList类
尽管您可能能够继承这些类,但我不明白这一点,因为您不能强迫SharePoint在内部使用它们。
通过扩展方法而不是实际从基类继承来提供添加的功能可能更有意义。
发布于 2010-10-14 12:56:35
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
https://stackoverflow.com/questions/3933270
复制相似问题