How does InvokeMember know about the HighPart property?

回眸只為那壹抹淺笑 提交于 2020-01-25 08:54:25

问题


I want to use the System.Reflection library and not ActiveDs. I found this code on the web that parses the LargeInteger into HighPart and LowPart.
I don't understand it completely, particularly where is the method 'HighPart' and 'LowPart' defined? Is that within the Object class or do I have to define it?

Below is the code that parses the 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);

Thanks!


回答1:


It's defined in the IADsLargeInteger, which is a COM interface.

http://msdn.microsoft.com/en-us/library/aa706037%28v=vs.85%29.aspx

To get rid of ActiveDs, you may defined the type yourself (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;
}


来源:https://stackoverflow.com/questions/27987996/how-does-invokemember-know-about-the-highpart-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!