BrawlCrate v0.41
Wii File Editor
Loading...
Searching...
No Matches
Public Member Functions | List of all members
BrawlLib.Internal.UserInputByteEnumDropdown< T > Class Template Reference
Inheritance diagram for BrawlLib.Internal.UserInputByteEnumDropdown< T >:
BrawlLib.Internal.UserInputHexByteEnumDropdown< T >

Public Member Functions

override bool GetStandardValuesSupported (ITypeDescriptorContext context)
 
virtual string FormattedNumericalValue (T val)
 
virtual string FormattedNumericalValue (byte b)
 
override StandardValuesCollection GetStandardValues (ITypeDescriptorContext context)
 
override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
 
override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
 
override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
 

Member Function Documentation

◆ CanConvertFrom()

override bool BrawlLib.Internal.UserInputByteEnumDropdown< T >.CanConvertFrom ( ITypeDescriptorContext  context,
Type  sourceType 
)
inline
1074 {
1075 return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
1076 }

◆ ConvertFrom()

override object BrawlLib.Internal.UserInputByteEnumDropdown< T >.ConvertFrom ( ITypeDescriptorContext  context,
CultureInfo  culture,
object  value 
)
inline
1079 {
1080 if (value.GetType() == typeof(string))
1081 {
1082 string field0 = (value.ToString() ?? "").Split(' ')[0];
1083 int fromBase = field0.StartsWith("0x", StringComparison.OrdinalIgnoreCase)
1084 ? 16
1085 : 10;
1086 return Convert.ToByte(field0, fromBase);
1087 }
1088
1089 return base.ConvertFrom(context, culture, value);
1090 }

◆ ConvertTo()

override object BrawlLib.Internal.UserInputByteEnumDropdown< T >.ConvertTo ( ITypeDescriptorContext  context,
CultureInfo  culture,
object  value,
Type  destinationType 
)
inline
1094 {
1095 if (destinationType == typeof(string) && value != null)
1096 {
1097 if (value is T enumObj)
1098 {
1099 return FormattedNumericalValue(enumObj) + " - " + enumObj.GetDescription();
1100 }
1101 if (value is byte b)
1102 {
1103 var enumVals = Enum.GetValues(typeof(T)).Cast<T>();
1104 if (enumVals.Any(o => Convert.ToByte(o) == b))
1105 return $"{FormattedNumericalValue(b)} - {Enum.GetValues(typeof(T)).Cast<T>().First(o => Convert.ToByte(o) == b).GetDescription()}";
1106 return FormattedNumericalValue(b);
1107 }
1108
1109 if (value is string s)
1110 return s;
1111 }
1112
1113 return base.ConvertTo(context, culture, value, destinationType);
1114 }
virtual string FormattedNumericalValue(T val)
Definition: DropDownLists.cs:1054

◆ FormattedNumericalValue() [1/2]

virtual string BrawlLib.Internal.UserInputByteEnumDropdown< T >.FormattedNumericalValue ( byte  b)
inlinevirtual

Reimplemented in BrawlLib.Internal.UserInputHexByteEnumDropdown< T >.

1059 {
1060 return $"{b}";
1061 }

◆ FormattedNumericalValue() [2/2]

virtual string BrawlLib.Internal.UserInputByteEnumDropdown< T >.FormattedNumericalValue ( val)
inlinevirtual

Reimplemented in BrawlLib.Internal.UserInputHexByteEnumDropdown< T >.

1055 {
1056 return $"{Convert.ToByte(val)}";
1057 }

◆ GetStandardValues()

override StandardValuesCollection BrawlLib.Internal.UserInputByteEnumDropdown< T >.GetStandardValues ( ITypeDescriptorContext  context)
inline
1064 {
1065 var enumList = new List<string>();
1066 foreach (var enumVal in Enum.GetValues(typeof(T)).Cast<T>())
1067 {
1068 enumList.Add($"{FormattedNumericalValue(enumVal)} - {enumVal.GetDescription()}");
1069 }
1070 return new StandardValuesCollection(enumList);
1071 }

◆ GetStandardValuesSupported()

override bool BrawlLib.Internal.UserInputByteEnumDropdown< T >.GetStandardValuesSupported ( ITypeDescriptorContext  context)
inline
1050 {
1051 return true;
1052 }

The documentation for this class was generated from the following file: