我想使用System.Reflection库而不是ActiveDs。我在Web上发现了这个代码,它将LargeInteger解析为HighPart和LowPart 我完全不了解它,特别是方法' HighPart'和' LowPart'界定?是在Object类中还是我必须定义它?
以下是解析largeInteger的代码:
de = new DirectoryEntry(curDomain,adUser,adPwd);
object largeInteger = de.Properties["maxPwdAge"].Value;
System.Type type = largeInteger.GetType();
int high = (int)type.InvokeMember("HighPart", BindingFlags.GetProperty, null, largeInteger, null);
int low = (int)type.InvokeMember("LowPart", BindingFlags.GetProperty, null, largeInteger, null);
谢谢!
答案 0 :(得分:1)
它在IADsLargeInteger中定义,它是一个COM接口。
http://msdn.microsoft.com/en-us/library/aa706037%28v=vs.85%29.aspx
要摆脱ActiveD,您可以自己定义类型(C#):
[
ComImport,
InterfaceType(ComInterfaceType.InterfaceIsIDispatch),
Guid("9068270B-0939-11D1-8BE1-00C04FD8D503")
]
public interface IADsLargeInteger
{
int HighPart{get;set;}
int LowPart{get;set;}
}
private long? GetLargeInt(DirectoryEntry de, string attrName)
{
long? ret = null;
IADsLargeInteger largeInt = de.Properties[attrName].Value as IADsLargeInteger;
if (largeInt != null)
{
ret = (long)largeInt.HighPart << 32 | largeInt.LowPart;
}
return ret;
}