Код: Выделить всё
public sealed class KeyValue(object value, [CallerArgumentExpression(nameof(value))] string keyName = null)
{
public string Key { get; set; } = keyName;
public object Value { get; set; } = value;
public static implicit operator KeyValue(string value) => new KeyValue(value);
}
Код: Выделить всё
string ThisIsMyName = "Test";
KeyValue pair = ThisIsMyName;
Console.WriteLine(pair.Key) //should print ThisIsMyName
Console.WriteLine(pair.Value) // should print Test
Код: Выделить всё
string ThisIsMyName = "Test";
KeyValue pair = new(ThisIsMyName);
Console.WriteLine(pair.Key) //prints ThisIsMyName
Console.WriteLine(pair.Value) //prints Test
Код: Выделить всё
Task HandleFailureAsync(params KeyValue[] parameters)
----------
string test1 = "t1";
string test2 = "t2";
KeyValue testKey1 = test1;
KeyValue testKey2 = test2;
HandleFailureAsync(testKey1, testKey2);
//instead of
HandleFailureAsync(new(test1), new(test2));
Подробнее здесь: https://stackoverflow.com/questions/783 ... it-casting