Created
December 4, 2019 11:11
-
-
Save tluyben/7d5de0dfcb0a0b0ff3959e58e157fab0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string PrintStructure(this VisualElement obj, string indent = "") | |
{ | |
if (obj == null) return ""; | |
var ot = obj.GetType().GetTypeInfo(); | |
var s = indent + ot.Name + " ["; | |
if (obj.StyleId != null && obj.StyleId.Length > 0) | |
{ | |
s += obj.StyleId + " "; | |
} | |
if (typeof(Label).GetTypeInfo().IsAssignableFrom(ot)) | |
{ | |
s += ((Label)obj).Text + " " + ((Label)obj).TextColor.ToHex() + " "; | |
} | |
else if (typeof(Button).GetTypeInfo().IsAssignableFrom(ot)) | |
{ | |
s += ((Button)obj).Text + " " + ((Button)obj).TextColor.ToHex() + " "; | |
} | |
else if (typeof(Image).GetTypeInfo().IsAssignableFrom(ot)) | |
{ | |
//s += ((Image)obj).Source.ToString() + " "; | |
} | |
s += obj.BackgroundColor.ToHex() + " "; | |
s += obj.Bounds.ToString() + " "; | |
s += "]\n"; | |
var t1 = typeof(ContentPage).GetTypeInfo(); | |
var t3 = typeof(Layout<View>).GetTypeInfo(); | |
var t4 = typeof(ContentView).GetTypeInfo(); | |
if (t1.IsAssignableFrom(ot)) // ContentPage | |
{ | |
s += ((ContentPage)obj).Content.PrintStructure(indent + " "); | |
} | |
else if (t4.IsAssignableFrom(ot)) // ContentView | |
{ | |
s += ((ContentView)obj).Content.PrintStructure(indent + " "); | |
} | |
else if (t3.IsAssignableFrom(ot)) // View | |
{ | |
int count = 0; | |
foreach (var c in ((Layout<View>)obj).Children) | |
{ | |
string _idx = count + ":"; | |
s += c.PrintStructure(indent + _idx.PadRight(3, ' ')); | |
count++; | |
} | |
} | |
return s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment