Shared
Reflection helpers that the Hypernova Windows Forms controls share between their assemblies.
public static class Shared
Remarks
The class is a support library for the controls rather than something an application is expected to call. It is public so that each control assembly can use it without carrying its own copy.
See also
Members at a glance
| Methods | |
|---|---|
BuildDataFromStaticType | Reads every static property declared on a type and returns the current values, keyed by property name. |
Methods
BuildDataFromStaticType static
Reads every static property declared on a type and returns the current values, keyed by property name.
Parameters
type- The type to read – typically a static class of colours or metrics. Must not be
null.
Returns
A new dictionary with one entry for each static property of type, public and
non-public, mapping the property name to the value it returned at the moment of the call. A type with
no static properties gives an empty dictionary. Instance properties are not read.
Exceptions
ArgumentNullExceptiontypeisnull.
Remarks
Each property getter is called once, in the order reflection reports the properties. The values are a snapshot: later changes to the properties are not reflected in the dictionary.
Non-public properties are included on purpose – the controls use this to take a snapshot of
internal palette and metric classes. An exception thrown by a getter is not caught; it reaches the
caller wrapped in a TargetInvocationException.
Example
using System;
using System.Drawing;
using Binarymission.WinForms.Controls.CommonUtils;
// List every system colour by name - for a diagnostics page, say.
foreach (var entry in Shared.BuildDataFromStaticType(typeof(SystemColors)))
{
Console.WriteLine($"{entry.Key,-28} {((Color)entry.Value).Name}");
}