2010-08-20 64 views

回答

0

該數據可通過內部方法獲得。所以,我有一個調用的輔助方法:

[NotNull] 
public static T Call<T>([CanBeNull] ref T cachedInvoker, [NotNull] Type subject, [NotNull] string methodName) where T : class 
{ 
    if (cachedInvoker == null) 
    { 
     var method = subject.GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic); 
     cachedInvoker = Delegate.CreateDelegate(typeof(T), method) as T; 
     if (cachedInvoker == null) 
      throw new ApplicationException(string.Format("Unable to create invoker for [{0}].[{1}].", subject, methodName)); 
    } 
    return cachedInvoker; 
} 

然後我得到的數據:

[NotNull] 
public static SPFolder Documents([NotNull] this PublishingWeb web) 
{ 
    return web.Lists[web.GetDocumentsListId()].RootFolder; 
} 

[NotNull] 
public static string GetDocumentsListName([NotNull] this PublishingWeb web) 
{ 
    return web.Lists[web.GetDocumentsListId()].Title; 
} 

private static Func<PublishingWeb, Guid> getDocumentsListIdInvoker; 

[NotNull] 
public static Guid GetDocumentsListId([NotNull] this PublishingWeb web) 
{ 
    return 
     Internal.Call(ref getDocumentsListIdInvoker, typeof (PublishingWeb), 
      "get_DocumentsListId")(web); 
} 

[NotNull] 
public static string GetImagesListName([NotNull] this PublishingWeb web) 
{ 
    return web.Lists[web.GetImagesListId()].Title; 
} 

private static Func<PublishingWeb, Guid> getImagesListIdInvoker; 

[NotNull] 
public static Guid GetImagesListId([NotNull] this PublishingWeb web) 
{ 
    return 
     Internal.Call(ref getImagesListIdInvoker, typeof(PublishingWeb), 
     "get_ImagesListId")(web); 
}