How are namespace and assembly names used for IronPython types?

You have an IronPython package called Entities. This package contains an Entity.py file that defines the Client class and the Address class.

If I run this program:

customer = Customer() print customer.GetType().AssemblyQualifiedName address = Address() print address.GetType().AssemblyQualifiedName 

I get this output:

 IronPython.NewTypes.System.Object_1$1, Snippets.scripting, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null IronPython.NewTypes.System.Object_1$1, Snippets.scripting, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null 

How it works? Why do both types have the same type name ( Object_1$1 )?

I need to use an API that requires a qualified assembly name for a type to instantiate this type. I would like to use it this way:

 customer = aFactory.Create("Entities.Customer, Entities"); 

How do i do this? Can I specify a namespace name and assembly name?

thanks

+3
source share
1 answer

You want to learn clrtype , which is new in IronPython 2.6. This allows you to control the type that is emitted, and there are good samples with pre-baked solutions, one of which may work here.

The reason the types are the same is because IronPython only needs to work so much with a system like .NET. This includes canceling any virtual methods of the base type and implementing any interfaces you requested by including them in the list of bases. In addition, all types are identical, and they are really determined by dynamic search in their PythonType object. So, for example, in Object_1 $ 1 we define an override of β€œToString”, which will look in the current PythonType permission order to determine if a ToString has been specified, and if so, we call it. This allows members of the PythonType object to change at runtime, and even allows you to change the type of the real python type at runtime. Also, if we did not do something like this, the defining classes will be memory leaks, because .NET types are not collected.

+5
source

All Articles