Jak zmienić wartość atrybutu „uSNChanged” System.DirectoryEntry na Int64
Usiłuję uzyskać wartość Int64 wartości „uSNChanged” obiektu Usług katalogowych. Niestety, zawsze wraca jako jakiś przedmiot COM. Próbowałem użyć rzutowania na Int64, wywołując Int64.Parse () i wywołując Convert.ToInt64 (). Żadna z tych rzeczy nie działa.
Dla danego obiektu DirectoryEntry ten kod wyświetli właściwości:
private static void DisplaySelectedProperties(DirectoryEntry objADObject)
{
try
{
string[] properties = new string[] {
"displayName",
"whenCreated",
"whenChanged",
"uSNCreated",
"uSNChanged",
};
Console.WriteLine(String.Format("Displaying selected properties of {0}", objADObject.Path));
foreach (string strAttrName in properties)
{
foreach (var objAttrValue in objADObject.Properties[strAttrName])
{
string strAttrValue = objAttrValue.ToString();
Console.WriteLine(String.Format(" {0, -22} : {1}", strAttrName, strAttrValue));
}
}
Console.WriteLine();
}
catch (Exception ex)
{
throw new ApplicationException(string.Format("Fatal error accessing: {0} - {1}", objADObject.Path, ex.Message), ex);
}
}
To jest wyjście:
Displaying selected properties of LDAP://server/o=org/cn=obj displayName : Display Name whenCreated : 7/8/2009 7:29:02 PM whenChanged : 7/8/2009 10:42:23 PM uSNCreated : System.__ComObject uSNChanged : System.__ComObject
Jak przekonwertować ten system .__ ComObject na Int64?
Zastosowane rozwiązanie:Jest to rozwiązanie, którego użyłem na podstawie rozwiązania marc_s poniżej:
public static Int64 ConvertADSLargeIntegerToInt64(object adsLargeInteger)
{
var highPart = (Int32)adsLargeInteger.GetType().InvokeMember("HighPart", System.Reflection.BindingFlags.GetProperty, null, adsLargeInteger, null);
var lowPart = (Int32)adsLargeInteger.GetType().InvokeMember("LowPart", System.Reflection.BindingFlags.GetProperty, null, adsLargeInteger, null);
return highPart * ((Int64)UInt32.MaxValue + 1) + lowPart;
}