我创建了一个类和派生类。如何从另一个类调用派生类?请参阅下面的类、派生类(扩展类)以及我调用派生类的地方。
UserPrincipal
班级:
private UserPrincipal GetUserFromAD1(string userLoginName)
{
String currentUser = userLoginName;
String domainName = userLoginName.Split('\\')[0];
UserPrincipal user = null;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, domainName))
{
user = UserPrincipal.FindByIdentity(pc, System.DirectoryServices.AccountManagement.IdentityType.SamAccountName, currentUser);
}
});
return user;
}
扩展UserPrincipal
类:
[DirectoryObjectClass("user")]
[DirectoryRdnPrefix("CN")]
public class UserPrincipalExtended : UserPrincipal
{
public UserPrincipalExtended(PrincipalContext context): base(context)
{
}
[DirectoryProperty("department")]
public string department
{
get
{
if (ExtensionGet("department").Length != 1)
return null;
return (string)ExtensionGet("department")[0];
}
set { this.ExtensionSet("department", value); }
}
方法
private void GetUserInfoFromAD1()
{
try
{
XPathNavigator rootNode = this.MainDataSource.CreateNavigator();
this.initialData = rootNode.SelectSingleNode("/my:myFields/my:Wrapper", this.NamespaceManager).OuterXml;
using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{
using (SPWeb web = site.OpenWeb())
{
UserPrincipalExtended userFromAD = this.GetUserFromAD1(web.CurrentUser.LoginName);
在代码行
this.GetUserFromAD1(web.CurrentUser.LoginName)
我收到一个错误:
无法隐式转换类型.......