From 1b780b2d46bfad3084df5e454d5b5ca81601595a Mon Sep 17 00:00:00 2001 From: Milo Gilad Date: Sat, 26 Aug 2017 10:46:54 -0400 Subject: Getting type info dynamically --- vala.html.markdown | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'vala.html.markdown') diff --git a/vala.html.markdown b/vala.html.markdown index c329447d..51cb8dc0 100755 --- a/vala.html.markdown +++ b/vala.html.markdown @@ -359,7 +359,7 @@ public abstract class OperatingSystem : GLib.Object { public abstract void use_computer(); } -public class Ubuntu : OperatingSystem { +public class Linux : OperatingSystem { public override void use_computer() { // Abstract methods must be overridden stdout.printf("Beep boop\n"); } @@ -400,6 +400,15 @@ interface Laptop { // May only contain abstracts or virtuals public interface CellPhone : Collection, GLib.Object {} +// You can get the type info of a class at runtime dynamically. + +bool type_info = object is TypeName; // uses "is" to get a bool + +Type type_info2 = object.get_type(); +var type_name = type_info2.name(); + +Type type_info3 = typeof(Linux); +Linux type_demo = (Linux) Object.new(type_info3); ``` * More Vala documentation can be found [here](https://valadoc.org/). -- cgit v1.2.3