dotNetClass

new.gif NEW in 3ds Max 9: The dotNetClass wraps a DotNet System::Type and exposes the static properties, methods, and events associated with the class via reflection.

Property access uses MAXScript number data types (widened as necessary), String, Boolean, dotNetControl, dotNetObject, and dotNetClass values. Properties are accessed via the normal property access specification [control.property] and getProperty() / setProperty() methods.

Accessing a class method will create a dotNetMethod instance.

New methods are used to add and manage event handlers. These methods register and unregister callback functions to be called when the event is fired. The arguments passed back to the functions will include the class, the event name, and the arguments passed by the event handler. See dotNet Struct Methods for details.

 

Note

There is a difference between a dotNetClass and a dotNetObject that wraps the same type. Accessing the dotNetObject accesses the System::Type while accessing the dotNetClass access the object type described by the System::Type. So, for example, if you called showProperties() on a dotNetClass you will get the properties of the System::Type the dotNetClass wraps, but on a dotNetObject that wraps the same type you will get the properties of System::Type itself.

Constructor:

dotNetClass {<dotNetObject> | <dotNetControl> | <class_type_string>}

Constructs a dotNetClass object. If the argument is a dotNetObject or dotNetControl object, the dotNetClass will wrap the System::Type of that object. If the argument is a string, MXS will attempt to resolve the string as a System::Type name.

Example:

theClass = dotNetClass "System.Drawing.Size"

 

This resolution is done using the following steps:

Example:

dotNetClass "System.Windows.Forms.MonthCalendar, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

Assemblies can be loaded to the Current AppDomain. See the dotNet.LoadAssembly() method in dotNet Struct Methods

An example of adding an assembly to the current AppDomain via methods exposed by the dotNetClass itsef is:

Example:

assembly = dotNetClass "System.Reflection.Assembly"

r = assembly.loadfrom "F:\\FlashTrackBar\\bin\\Debug\\FlashTrackBar.dll"

 

Note:

Assemblies can not be unloaded once loaded.

Methods:

getProperty <dotNetClass> <prop name> [asDotNetObject:<bool>]

Returns the value of the specified property. If asDotNetObject is false (the default) the value will converted to a native MAXScript value if possible; if true, the value will always be returned as a dotNetControl or dotNetObject value.

For example:

o = dotNetObject "System.Windows.Forms.ImageList"

mxs_bool = getproperty o #HandleCreated -- mxs boolean

net_bool = getproperty o #HandleCreated asDotNetObject:true -- .net System::Boolean

If the property accessed is an indexed property, a dotNetMethod will be returned.

For example:

o1 = dotNetObject "System.String" "hello!"

chars = getProperty o1 #chars

chars[1] -- "e"

o1.chars[1] -- "e"

Note:

Indexed access is 0-based!

 

setProperty <dotNetClass> <prop name> <value>

Sets the value of the specified property. If the value specified is a native MAXScript value, it will be converted to the proper DotNet value if possible.

getPropNames <dotNetClass> [showStaticOnly:<bool>] [declaredOnTypeOnly:<bool>]

Returns an array of property names exposed by the class.

If showStaticOnly is true (the default), only static properties are shown; if false both static and instance properties are shown.

If declaredOnTypeOnly is true, only properties declared on the specified class are shown; if false (the default) properties on the class and the classes it derives from are shown.

The results of this method are sorted by name. The properties returned actually contain two different things in terms of DotNet - properties and fields. The properties are shown first in sorted order, then the fields are shown in sorted order.

showProperties <dotNetClass> ["prop_pat"] [to:<stream>] [showStaticOnly:<bool>] [showMethods:<bool>] [showAttributes:<bool>] [declaredOnTypeOnly:<bool>]

Displays the properties exposed by the class whose name matches the property pattern.

If to is not specified, the output goes to Listerner, otherwise the output goes to the specified stream.

If showStaticOnly is true (the default), only static properties are shown; if false both static and instance properties are shown.

If showMethods is true, the signature of the get and set methods (if any) are shown; defaults to false.

If showAttributes is true, the attributes associated with the property are shown; defaults to false.

If declaredOnTypeOnly is true, only properties declared on the specified class are shown; if false (the default) properties on the class and the classes it derives from are shown.

The results of this method are sorted by name. The properties returned actually contain two different things in terms of DotNet - properties and fields. The properties are shown first in sorted order, then the fields are shown in sorted order.

showMethods <dotNetClass> ["prop_pat"] [to:<stream>] [showStaticOnly:<bool>] [showSpecial:<bool>] [showAttributes:<bool>] [declaredOnTypeOnly:<bool>]

Displays the methods exposed by the class whose name matches the property pattern.

If to is not specified, the output goes to Listerner, otherwise the output goes to the specified stream.

If showStaticOnly is true (the default), only static properties are shown; if false both static and instance properties are shown.

If showSpecial is true, methods that are not normally called by the user (such as a method to set a property value or to invoke an event handler) are shown; defaults to false.

If showAttributes is true, the attributes associated with the property are shown; defaults to false.

If declaredOnTypeOnly is true, only properties declared on the specified class are shown; if false (the default) properties on the class and the classes it derives from are shown.

The results are sorted by name. Secondary sort is performed based on the number of parameters.

showEvents <dotNetClass> ["prop_pat"] [to:<stream>] [showStaticOnly:<bool>] [declaredOnTypeOnly:<bool>]

Displays the events exposed by the class whose name matches the property pattern.

If to is not specified, the output goes to Listerner, otherwise the output goes to the specified stream.

If showStaticOnly is true (the default), only static properties are shown; if false both static and instance properties are shown.

If declaredOnTypeOnly is true, only properties declared on the specified class are shown; if false (the default) properties on the class and the classes it derives from are shown.

The results are sorted by name.

dotNet.showConstructors <dotNetClass> [to:<stream>]

Displays the constructors exposed by the class.

If to is not specified, the output goes to Listerner, otherwise the output goes to the specified stream.

The results are sorted by name. Secondary sort is performed based on the number of parameters.

See also

DotNet In MAXScript

dotNet Struct Methods