InvokeMember如何了解HighPart属性? [英] How does InvokeMember know about the HighPart property?

查看:124
本文介绍了InvokeMember如何了解HighPart属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用System.Reflection库而不是ActiveD.我在网上将这段代码解析为BigInteger分为HighPart和LowPart.
我不完全了解它,尤其是在哪里定义了"HighPart"和"LowPart"的方法?是在Object类中还是必须对其进行定义?

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?

下面是解析largeInteger的代码:

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);

谢谢!

推荐答案

它是在IADsLargeInteger(它是一个COM接口)中定义的.

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

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

要摆脱ActiveD,您可以自己定义类型(C#):

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;
}

这篇关于InvokeMember如何了解HighPart属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆