In 3ds Max 9 and higher, 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.
There is a difference between a dotNetClass and a dotNetObject that wraps the same type.
Accessing the dotNetClass accesses the System::Type while accessing the dotNetObject access the object type described by the System::Type.
So, for example, if you called showProperties() on a dotNetObject you will get the properties of the System::Type the dotNetObject wraps, but on a dotNetClass that wraps the same type you will get the properties of System::Type itself.
Constructs a dotNetClassobject. 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.
This resolution is done using the following steps:
1. Attempt to resolve as a fully qualified name. A fully qualified name includes both the class name and the assembly name.
2. Attempt to resolve as a class name by looking for the name in each assembly loaded into the current AppDomain.
3. If no match is found, the name is prepended with "System." and another attempt will be made.
4. If no match is found, the name is prepended with "System.Windows.Forms." and another attempt will be made.
5. Finally, an attempt is made to match against built-in C# data type names to the matching .NET system type. The mappings are:
C# Built-in Type Name | .NET Framework Type |
---|---|
bool | System.Boolean |
byte | System.Byte |
sbyte | System.SByte |
char | System.Char |
decimal | System.Decimal |
float | System.Single |
int | System.Int32 |
uint | System.UInt32 |
long | System.Int64 |
ulong | System.UInt64 |
object | System.Object |
short | System.Int16 |
ushort | System.UInt16 |
string | System.String |
EXAMPLE |
---|
type = dotnetclass "bool[]" --> dotNetClass:System.Boolean[] v = dotnet.ValueToDotNetObject #(false,true) type --> dotNetObject:System.Boolean[] v.get 0 --> false type = dotnetclass "byte[]" --> dotNetClass:System.Byte[] v = dotnet.ValueToDotNetObject #(1,2) type --> dotNetObject:System.Byte[] v.get 0 --> 1 type = dotnetclass "char[]" --> dotNetClass:System.Char[] v = dotnet.ValueToDotNetObject #("A","B") type --> dotNetObject:System.Char[] v.get 0 --> "A" |
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 AppDomainvia methods exposed by the dotNetClass itself:
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.
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.
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 Listener, 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 Listener, 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 Listener, 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.
Displays the constructors exposed by the class.
If to is not specified, the output goes to Listener, otherwise the output goes to the specified stream.
The results are sorted by name. Secondary sort is performed based on the number of parameters.