简体   繁体   中英

How to invoke a .Net method with unsigned integer argument from IronPython

The method in CSharp have two variants

    public class MmsValue
    {
        public MmsValue (int value)
        {
            valueReference = MmsValue_newIntegerFromInt32 (value);
        }

        public MmsValue (UInt32 value)
        {
            valueReference = MmsValue_newUnsignedFromUint32(value);
        }

When I call it from IronPython, it always invokes MmsValue(int value) . Is there a way to call MmsValue(UInt32 value) ?

Taken from the IronPython documentation: http://ironpython.net/documentation/dotnet/

If you want to control the exact overload that gets called, you can use the Overloads method on method objects:

import clr
clr.AddReference('ClassLibrary1')
from ClassLibrary1 import MmsValue
from System import UInt32    

uint32_mmsValue = MmsValue.__new__.Overloads[UInt32](MmsValue, 1)

This will create a instance of MmsValue using the UInt32 constructor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM