-
Notifications
You must be signed in to change notification settings - Fork 700
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Move all public nested classes out into own files * Move more nested classes out * Tidy up and treat CA1034 as an error. Fix remaining nested classes. * Remove partial keyword from ThemeManager as it is no longer needed * Rename Bar to BarSeriesBar to more clearly indicate it is part of GraphView subsystem * Fix xmldoc references * Revert nesting changes to ConsoleDrivers * Change to file scoped namespaces and revert renames - LineCanvasCell back to just Cell - ApplicationRunState back to just RunState * Switch to file scoped namespaces
- Loading branch information
Showing
66 changed files
with
1,859 additions
and
1,809 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using System; | ||
using System.Reflection; | ||
using System.Text.Json.Serialization; | ||
|
||
#nullable enable | ||
|
||
namespace Terminal.Gui; | ||
|
||
/// <summary> | ||
/// Holds a property's value and the <see cref="PropertyInfo"/> that allows <see cref="ConfigurationManager"/> | ||
/// to get and set the property's value. | ||
/// </summary> | ||
/// <remarks> | ||
/// Configuration properties must be <see langword="public"/> and <see langword="static"/> | ||
/// and have the <see cref="SerializableConfigurationProperty"/> | ||
/// attribute. If the type of the property requires specialized JSON serialization, | ||
/// a <see cref="JsonConverter"/> must be provided using | ||
/// the <see cref="JsonConverterAttribute"/> attribute. | ||
/// </remarks> | ||
public class ConfigProperty { | ||
private object? propertyValue; | ||
|
||
/// <summary> | ||
/// Describes the property. | ||
/// </summary> | ||
public PropertyInfo? PropertyInfo { get; set; } | ||
|
||
/// <summary> | ||
/// Helper to get either the Json property named (specified by [JsonPropertyName(name)] | ||
/// or the actual property name. | ||
/// </summary> | ||
/// <param name="pi"></param> | ||
/// <returns></returns> | ||
public static string GetJsonPropertyName (PropertyInfo pi) | ||
{ | ||
var jpna = pi.GetCustomAttribute (typeof (JsonPropertyNameAttribute)) as JsonPropertyNameAttribute; | ||
return jpna?.Name ?? pi.Name; | ||
} | ||
|
||
/// <summary> | ||
/// Holds the property's value as it was either read from the class's implementation or from a config file. | ||
/// If the property has not been set (e.g. because no configuration file specified a value), | ||
/// this will be <see langword="null"/>. | ||
/// </summary> | ||
/// <remarks> | ||
/// On <see langword="set"/>, performs a sparse-copy of the new value to the existing value (only copies elements of | ||
/// the object that are non-null). | ||
/// </remarks> | ||
public object? PropertyValue { | ||
get => propertyValue; | ||
set { | ||
propertyValue = value; | ||
} | ||
} | ||
|
||
internal object? UpdateValueFrom (object source) | ||
{ | ||
if (source == null) { | ||
return PropertyValue; | ||
} | ||
|
||
var ut = Nullable.GetUnderlyingType (PropertyInfo!.PropertyType); | ||
if (source.GetType () != PropertyInfo!.PropertyType && (ut != null && source.GetType () != ut)) { | ||
throw new ArgumentException ($"The source object ({PropertyInfo!.DeclaringType}.{PropertyInfo!.Name}) is not of type {PropertyInfo!.PropertyType}."); | ||
} | ||
if (PropertyValue != null && source != null) { | ||
PropertyValue = ConfigurationManager.DeepMemberwiseCopy (source, PropertyValue); | ||
} else { | ||
PropertyValue = source; | ||
} | ||
|
||
return PropertyValue; | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves (using reflection) the value of the static property described in <see cref="PropertyInfo"/> | ||
/// into <see cref="PropertyValue"/>. | ||
/// </summary> | ||
/// <returns></returns> | ||
public object? RetrieveValue () | ||
{ | ||
return PropertyValue = PropertyInfo!.GetValue (null); | ||
} | ||
|
||
/// <summary> | ||
/// Applies the <see cref="PropertyValue"/> to the property described by <see cref="PropertyInfo"/>. | ||
/// </summary> | ||
/// <returns></returns> | ||
public bool Apply () | ||
{ | ||
if (PropertyValue != null) { | ||
PropertyInfo?.SetValue (null, ConfigurationManager.DeepMemberwiseCopy (PropertyValue, PropertyInfo?.GetValue (null))); | ||
} | ||
return PropertyValue != null; | ||
} | ||
|
||
} |
This file contains 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
This file contains 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
Oops, something went wrong.