1

The C#/.NET library (.dll) I interface with has many user defined enumerated types that I wish to pass as parameters, for example,

    public enum fieldType_e
    {
        FIELDTYPE_NONE = 0,   // 0 - Field 
        FIELDTYPE_1,          // 1 - Field 
        FIELDTYPE_2,          // 2 - Field 
        FIELDTYPE_3,          // 3 - Field 
        FIELDTYPE_LAST
    }

to a member function:

    public bool CMD_AddUser(int UserNumb, String PrimaryField, fieldType_e FieldType )
    {
    .
    .
    .
    }

When I call, for example, CMD_AddUser( 1, '2222', 3) from IronPython, it accepts the first two parameters (int and string), but rejects type fieldType_e.

Here is a sample IronPython session:

C:\>ipy
IronPython 2.7.5 (2.7.5.0) on .NET 4.0.30319.34209 (32-bit)
Type "help", "copyright", "credits" or "license" for more information.
>>> import clr
>>> clr.AddReferenceToFileAndPath('Library.dll')
>>> import Library.Protocols.R3
>>> type(Library.Protocols.R3)
<type 'namespace#'>
>>> from Library.Protocols.R3 import R3Serial
>>> from Library.Protocols.R3 import R3_App
>>> 
>>> # Instantiate Library.Protocols.R3 classes
>>> App = R3_App()
>>> R3_Serial = R3Serial("COM3", 115200, 0)
>>> R3_Serial.App.CMD_Handshake()
True
>>> R3_Serial.App.CMD_AddUser( 1, '2222', 3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Cannot convert numeric value 3 to fieldType_e.  The value must be zero.

IronPython recognizes the enum fieldType_e, and the element FIELDTYPE_NONE, but throws an AttributeError when I try to use it.

>>> AHG_Library.fieldType_e.FIELDTYPE_NONE
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'namespace#' object attribute 'fieldType_e' is read-only
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
onch
  • 43
  • 6
  • 2
    possible duplicate of [Accessing .Net enums in Iron python](http://stackoverflow.com/questions/27017429/accessing-net-enums-in-iron-python) – theB Sep 02 '15 at 20:03
  • 1
    I fully expected "possible duplicate of Accessing .Net enums in Iron python" to resolve my issue, and think I am replicating the procedure accurately, but IronPython 2.7.5 still throws the AttributeError... – onch Sep 04 '15 at 17:36
  • you passed integer (3) instead of enum fieldType_e.FIELDTYPE_3 – denfromufa Sep 07 '15 at 21:46
  • 1
    You are correct!!! Here's the way to do it... >>> R3_App.fieldType_e.FIELDTYPE_NONE AHG_Library.Protocols.R3.R3_App+fieldType_e.FIELDTYPE_NONE Thank you all... – onch Sep 09 '15 at 12:41

1 Answers1

1

you passed integer (3) instead of enum fieldType_e.FIELDTYPE_3

denfromufa
  • 5,610
  • 13
  • 81
  • 138