|
|
|
|
@ -150,20 +150,32 @@ public partial class MultiFormatDataViewModel : ObservableObject |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// Returns the selected Data as string in the <paramref name="format"/> given. |
|
|
|
|
/// If nothing is selected, returns the whole content of Data. |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="format">format to return data in</param> |
|
|
|
|
/// <returns>the data in the given format</returns> |
|
|
|
|
public string GetSelectedDataAsString(FormatType format) |
|
|
|
|
{ |
|
|
|
|
// nothing selected => return empty string |
|
|
|
|
if(this.Selected == null || this.Selected.Count == 0) { return string.Empty; } |
|
|
|
|
List<ByteDataViewModel>? dataCopy = new(); |
|
|
|
|
|
|
|
|
|
// shallow copy of the selected items |
|
|
|
|
var selectedCopy = this.Selected.Select(item => (ByteDataViewModel)item.Clone()).ToList(); |
|
|
|
|
// nothing selected => return whole data |
|
|
|
|
if(this.Selected == null || this.Selected.Count == 0) |
|
|
|
|
{ |
|
|
|
|
dataCopy = this.Data.Select(item => (ByteDataViewModel)item.Clone()).ToList(); |
|
|
|
|
} |
|
|
|
|
else // something is selected: shallow copy of the selected items |
|
|
|
|
{ |
|
|
|
|
dataCopy = this.Selected.Select(item => (ByteDataViewModel)item.Clone()).ToList(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
string dataAsString = string.Empty; |
|
|
|
|
dataAsString = format switch |
|
|
|
|
{ |
|
|
|
|
FormatType.Character => ByteDataViewModelHelpers.GetCharacterStringOfBytesDataViewModels(selectedCopy), |
|
|
|
|
FormatType.Hexadecimal => ByteDataViewModelHelpers.GetHexadecimalStringOfBytesDataViewModels(selectedCopy), |
|
|
|
|
FormatType.Binary => ByteDataViewModelHelpers.GetBinaryStringOfEBytesDataViewModels(selectedCopy), |
|
|
|
|
FormatType.Character => ByteDataViewModelHelpers.GetCharacterStringOfBytesDataViewModels(dataCopy), |
|
|
|
|
FormatType.Hexadecimal => ByteDataViewModelHelpers.GetHexadecimalStringOfBytesDataViewModels(dataCopy), |
|
|
|
|
FormatType.Binary => ByteDataViewModelHelpers.GetBinaryStringOfEBytesDataViewModels(dataCopy), |
|
|
|
|
_ => throw new ArgumentException($"'{GetSelectedDataAsString}()' does not have handling implemented for {nameof(FormatType)} {format}") |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|