[IronPython] Access to Enumeration Values
Martin Maly
martmaly at exchange.microsoft.com
Thu Aug 4 19:03:47 CEST 2005
Hi Anthony,
I don't think it is a bug. The value you get when getting an enum value
(SocketOptionName.Broadcast) is indeed the value itself:
x = SocketOptions.Broadcast
x becomes a boxed enum object. It is the ToString() method of the enum
object prints the name. Consider following C# code that does exactly the
same:
using System.Net.Sockets;
namespace Test {
public class Program {
static void Main(string[] args) {
Console.WriteLine(SocketOptionName.Broadcast);
}
}
}
Does that answer the question?
Martin
-----Original Message-----
From: users-ironpython.com-bounces at lists.ironpython.com
[mailto:users-ironpython.com-bounces at lists.ironpython.com] On Behalf Of
Anthony Tarlano
Sent: Thursday, August 04, 2005 9:12 AM
To: Discussion of IronPython
Subject: [IronPython] Access to Enumeration Values
the namespace System.Net.Sockets contains an enumation type named
SocketOptionName for retrieving Socket options. It's definition is:
public enum SocketOptionName
{
// Fields
AcceptConnection = 2,
AddMembership = 12,
AddSourceMembership = 15,
BlockSource = 0x11,
Broadcast = 0x20,
BsdUrgent = 2,
ChecksumCoverage = 20,
Debug = 1,
DontFragment = 14,
DontLinger = -129,
DontRoute = 0x10,
DropMembership = 13,
DropSourceMembership = 0x10,
Error = 0x1007,
ExclusiveAddressUse = -5,
Expedited = 2,
HeaderIncluded = 2,
HopLimit = 0x15,
IPOptions = 1,
IpTimeToLive = 4,
IPv6ProtectionLevel = 0x17,
KeepAlive = 8,
Linger = 0x80,
MaxConnections = 0x7fffffff,
MulticastInterface = 9,
MulticastLoopback = 11,
MulticastTimeToLive = 10,
NoChecksum = 1,
NoDelay = 1,
OutOfBandInline = 0x100,
PacketInformation = 0x13,
ReceiveBuffer = 0x1002,
ReceiveLowWater = 0x1004,
ReceiveTimeout = 0x1006,
ReuseAddress = 4,
SendBuffer = 0x1001,
SendLowWater = 0x1003,
SendTimeout = 0x1005,
Type = 0x1008,
TypeOfService = 3,
UnblockSource = 0x12,
UpdateAcceptContext = 0x700b,
UpdateConnectContext = 0x7010,
UseLoopback = 0x40
}
Upon accessing an enumeration value by name IronPython only returns its
name as a string... If this isn't a bug then it should be... see this
output
IronPython 0.9.2036 on .NET 2.0.50215.44 Copyright (c) Microsoft
Corporation. All rights reserved.
>>> from System.Net.Sockets import SocketOptionName SocketOptionName
<type 'System.Net.Sockets.SocketOptionName'>
>>> SocketOptionName.MaxConnections
MaxConnections
>>> SocketOptionName.MaxConnections.value__
2147483647
>>>
Anthony
More information about the Ironpython-users
mailing list