Tips for Python Programmers about .NET API Documentation
The current prerelease of the script interface documentation has been generated automatically from the underlying .NET and C# sources. Therefore, the documentation includes some expressions that are not familiar to Python programmers. The following overview provides some tips about how these expressions can be understood from the Python perspective.
An interface is the contract that tells an instance of a class that implements the interface which members (methods, properties) it has to prepare. In IronPython, you can implement one or more .NET interfaces in one class by inheriting from a superclass. If a method is needed for the interface but is not available in the class definition, then an exception is thrown. (The
DeviceImportFromSvn.pyexample shows a class that implements theImportReporterinterface.)Each parameter and each method in .NET is strictly typed. The type of parameter is separated by one space character before the parameter name, and the type of return value from a method by one space character before the method name. You can use instances from subclasses when you define a class (or interface). A method without a return value is marked
void.You can overload methods. As a result, multiple methods with the same name can exist in one class. However, the number or the types of parameters have to be different. IronPython automatically takes care of the most appropriate method overloading being called.
The data type
intcorresponds to an integer from -2,147,483,648 to 2,147,483,647.The data type
boolcorresponds to the Python typebool(TrueandFalse).The data type
stringcorresponds to the Python typesstrorunicode, which are identical in IronPython.The
IDictionary<object, object>data type corresponds to an ordinary Python dictionary. IronPython automatically converts between Python and .NET data types.When a
Ttype is inherited fromIBaseObject<T>, it means that this type can be extended by other plug-ins for additional members. The actual use of this extended type as a parameter or return value is marked byIExtendedObject<T>.The
IEnumerable<T>interface to aTtype means that you can use every Python sequence (generators, lists, tuples, etc.) which returnsTtype values (or a subclass). Returns the sequence of incompatible objects, and throws an exception at runtime.The
IList<T>interface to aTtype identifies a typified list which guarantees to include only elements of typeT(or a subclass). An exception is thrown at runtime when any attempt is made to add an incompatible object.The
params T[] nameid for a parameter of typeTcorresponds to the Python mechanism*namefor variable argument lists.In Python, enumerations (
enum) do not exist as language constructs. Its purpose is to define an exact number of constant values for a specific purpose, for example the days of the week. Access to .NET enumerations from IronPython works by using "Name.Member", for example viaOnlineChangeOption.Try.There are also different approaches to emulate enums in Python.
For example, see: http://pypi.python.org/pypi/enum/
The syntax
T name{ get; set; }defines a property withnameas the name andTas the type. Ifset;is missing, then the property is read-only. In Python, the respective construct is@propertydecorator.