True Shape object Type in release mode

BitSmithy 1,791 Reputation points
2024-01-08T13:19:08.2966667+00:00

I have such XAML:

<Canvas Name="c">
<Rectangle/>
<Rectangle/>
<Image/>
</Canvas>

now when I iterate such XAML in c#

string s = "";
foreach (object o in c.Children)             
{          
	s += o.GetType().Name;
}

Next I try to run such code in Debug and Release modes.

In debug mode it gives right class names but in release mode it it gives "Shape" as Rectangle class name.

How to solve this problem, I needs right name in Debug and Release Run modes.

Universal Windows Platform (UWP)
{count} votes

Accepted answer
  1. Junjie Zhu - MSFT 15,446 Reputation points Microsoft Vendor
    2024-01-11T06:18:01.4833333+00:00

    Hi @BitSmithy ,

    Special treatment of specific controls directly, it seems that it can be used as a workaround, you can try this.

    string s = "";
    foreach (object o in c.Children)
    {
        if (o.GetType() == typeof(Rectangle))
        {
            s += "Rectangle";
        }
        else
        {
            s += o.GetType().Name;
        }
    
    }
    

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful