views:

43

answers:

4

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

A: 

According to their MSDN pages, the classes are not sealed:

SPWeb Class

SPList Class

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.

Justin Niessner
A: 

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

Shiraz Bhaiji
Interesting. If you look at the MSDN docs for those classes, you can clearly see that the sealed keyword is not mentioned (as it is for other sealed classes on MSDN).
Justin Niessner
@justin, it was a difference between 2007 and 2010, I have updated the answer
Shiraz Bhaiji
@Shiraz - But even if you switch the MSDN Documentation to WSS 3.0 (which was the WSS used in SharePoint 2007), they still do not appear sealed.
Justin Niessner
+2  A: 

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

Rich Bennema
A: 

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?

Chris
Chris.. might I suggest using the "add comment" link instead of posting an answer. :)
Kit Menke