Hi, Is possible to inherit from SharePoint classes such like: SPWeb, SPList etc. or this classes are sealed? I couldn't find right answer.
Chris
Hi, Is possible to inherit from SharePoint classes such like: SPWeb, SPList etc. or this classes are sealed? I couldn't find right answer.
Chris
According to their MSDN pages, the classes are not sealed:
Even though you may be able to inherit from those classes, I don't see the point since you can't force SharePoint to use them internally.
It may make more sense to provide your added functionality via Extension Methods rather than actually inheriting from the base classes.
SPWeb and SPList are sealed in SharePoint 2007, see: http://blogs.msdn.com/b/francischeung/archive/2008/08/22/unit-testing-sharepoint-2007-applications.aspx
But they are not sealed in SharePoint 2010, see: http://my.safaribooksonline.com/9781435456457/365
According to Reflector, SPWeb is not sealed in either 2007 or 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
However, in both versions, the class only has internal constructors, so while Visual Studio will let you try to inherit from the class, it will not compile:
The type 'Microsoft.SharePoint.SPWeb' has no constructors defined
Thanks for replys. Rich, you are right - the constructors are internal. So it means that I coudn't extend the functionality of these classes in any elegance way?