Class TypeCast
Provides generated QML cast helpers for bridged C# reference types.
public class TypeCast
- Inheritance
-
TypeCast
- Inherited Members
Remarks
TypeCast is exposed to QML as a singleton named TypeCast. The class
itself is only a marker in the API assembly. During code generation, the bridge adds one
as_* method for each supported bridged object type.
Use these generated methods when QML receives an object reference, and you want to treat it
as a specific bridged C# type. If the runtime object is assignable to the target type, the
method returns the typed wrapper. Otherwise, it returns null.
For example, a bridged C# type like this:
namespace ColorPalette;
public class ColorResource
{
public string Name { get; set; }
public int ColorId { get; set; }
}
produces a QML cast helper named TypeCast.as_ColorPalette_ColorResource(obj). In
QML, you call that method with an object reference. If the object actually represents a
ColorPalette.ColorResource instance, the return value can be used as that type.
Otherwise, the result is null.
function showColorDetails(obj) {
let color = TypeCast.as_ColorPalette_ColorResource(obj)
if (color == null)
return
console.log(color.name)
console.log(color.colorId)
}
Method names are derived from the C# namespace and type name, with namespace separators
replaced by _.
Constructors
TypeCast()
public TypeCast()