Como alterar o valor do atributo System.DirectoryEntry “uSNChanged” para um Int64
Eu estou tentando obter o valor Int64 de um valor "uSNChanged" do objeto de serviços de diretório. Infelizmente, está sempre voltando como um objeto COM de algum tipo. Eu tentei usar o casting para Int64, chamando Int64.Parse () e chamando Convert.ToInt64 (). Nenhum desses trabalhos.
Para um determinado objeto DirectoryEntry, esse código exibirá as propriedades:
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);
}
}
Esta é a saída:
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
Como converter esse sistema .__ ComObject em um Int64?
Solução Usada:Esta é a solução que usei com base na solução da marc_s abaixo:
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;
}