using System; using System.Linq; using System.Runtime.InteropServices; using NvAPIWrapper.Native.Attributes; using NvAPIWrapper.Native.General.Structures; using NvAPIWrapper.Native.Interfaces; namespace NvAPIWrapper.Native.DRS.Structures { /// /// Contains a list of all possible values for a setting as well as its default value /// [StructLayout(LayoutKind.Sequential, Pack = 8)] [StructureVersion(1)] public struct DRSSettingValues : IInitializable { internal const int MaximumNumberOfValues = 100; internal StructureVersion _Version; internal uint _NumberOfValues; internal DRSSettingType _SettingType; internal DRSSettingValue _DefaultValue; [MarshalAs(UnmanagedType.ByValArray, SizeConst = MaximumNumberOfValues)] internal DRSSettingValue[] _Values; /// /// Gets the setting's value type /// public DRSSettingType SettingType { get => _SettingType; } /// /// Gets a list of possible values for the setting /// public object[] Values { get { switch (_SettingType) { case DRSSettingType.Integer: return ValuesAsInteger().Cast().ToArray(); case DRSSettingType.Binary: return ValuesAsBinary().Cast().ToArray(); case DRSSettingType.String: case DRSSettingType.UnicodeString: return ValuesAsUnicodeString().Cast().ToArray(); default: throw new ArgumentOutOfRangeException(nameof(SettingType)); } } } /// /// Gets the default value of the setting /// public object DefaultValue { get { switch (_SettingType) { case DRSSettingType.Integer: return DefaultValueAsInteger(); case DRSSettingType.Binary: return DefaultValueAsBinary(); case DRSSettingType.String: case DRSSettingType.UnicodeString: return DefaultValueAsUnicodeString(); default: throw new ArgumentOutOfRangeException(nameof(SettingType)); } } } /// /// Returns the default value as an integer /// /// An integer representing the default value public uint DefaultValueAsInteger() { return _DefaultValue.AsInteger(); } /// /// Returns the default value as a byte array /// /// An array of bytes representing the default value public byte[] DefaultValueAsBinary() { return _DefaultValue.AsBinary(); } /// /// Returns the default value as an unicode string /// /// A string representing the default value public string DefaultValueAsUnicodeString() { return _DefaultValue.AsUnicodeString(); } /// /// Returns the setting's possible values as an array of integers /// /// An array of integers representing the possible values public uint[] ValuesAsInteger() { return _Values.Take((int) _NumberOfValues).Select(value => value.AsInteger()).ToArray(); } /// /// Returns the setting's possible values as an array of byte arrays /// /// An array of byte arrays representing the possible values public byte[][] ValuesAsBinary() { return _Values.Take((int) _NumberOfValues).Select(value => value.AsBinary()).ToArray(); } /// /// Returns the setting's possible values as an array of unicode strings /// /// An array of unicode strings representing the possible values public string[] ValuesAsUnicodeString() { return _Values.Take((int) _NumberOfValues).Select(value => value.AsUnicodeString()).ToArray(); } } }