2010-10-14 79 views
1

是否可以繼承SharePoint類,如:SPWeb,SPList等。 或者這些類是密封的?我找不到正確的答案。是否可以從SPWeb繼承?

克里斯


感謝回信。 富有,你是對的 - 構造函數是內部的。所以這意味着我不會以任何優雅的方式擴展這些類的功能?

回答

0

根據自己的MSDN頁面,類不是密封:

SPWeb Class

SPList Class

即使你可能能夠從這些類繼承,我不明白這一點,因爲您不能強制SharePoint在內部使用它們。

通過擴展方法提供添加的功能可能更有意義,而不是實際從基類繼承。

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

+0

有趣。如果您查看這些類的MSDN文檔,您可以清楚地看到密封關鍵字未提及(因爲它是MSDN上的其他密封類)。 – 2010-10-14 12:58:45

+0

@justin,這是2007年和2010年之間的差異,我更新了答案 – 2010-10-14 13:00:42

+0

但即使您將MSDN文檔切換到WSS 3.0(這是SharePoint 2007中使用的WSS),它們仍然不會顯示爲密封。 – 2010-10-14 13:01:45

2

根據反射器,的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」 沒有構造定義

0

我覺得很多SharePoint服務器對象模型程序員都遇到過這個問題。

起初,我只是從輔助類開始,將其作爲SPWeb的包裝器,它使用託管導航。

隨着要求變得更加複雜,我必須處理多種類型的SPWeb。所以,我重寫了代碼,創建了一個Factory類來實例化SPSite和SPWeb。它將帶有託管元數據術語的SPWeb綁定在一起,並將類型信息存儲在SPWeb屬性和Term定製屬性中。

我想幫助微軟找出這是否是一種有意義的設計。如果微軟爲此開啓一個開源項目是值得的。由於有時程序員必須專注於業務邏輯,因此不想一次又一次地實施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

相關問題