RefTuple
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- csharp
- Ambito
- backend-api-design
Direzione di ricerca
Nell’issue non sono indicati file di implementazione o test. Inizia individuando l’API pubblica del toolkit e i progetti di test destinati a .NET 9 e C# 13, quindi confronta la firma richiesta di RefTuple<T1,T2> con le convenzioni esistenti per tuple e ref-struct. Il lavoro è completato quando l’API supporta la costruzione, la decostruzione e gli argomenti di tipo ref-struct mostrati senza una breaking change, con test che coprono questo utilizzo.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Overview
Adding RefTuple<...> types would allow ref structs to be used in tuples.
API breakdown
public ref struct RefTuple<T1,T2>
where T1 : allows ref struct
where T2 : allows ref struct
{
public RefTuple(T1 t1, T2 t2);
public T1 Item1 { get; set; }
public T2 Item2 { get; set; }
public readonly void Deconstruct(out T1 item1, out T2 item2);
}
Usage example
This is an example using pattern matching to select a reference to a field, and a paired value. The ref is wrapped in a Ref<T>, which as a ref struct cannot be stored in a normal tuple or ValueTuple.
// Get reference to selected register argument
RefTuple<Ref<GPRegister>, RegisterSet> pair = target switch
{
// General Purpose Registers
Argument.RS => new(new(ref _rs), RegisterSet.GeneralPurpose),
Argument.RT => new(new(ref _rt), RegisterSet.GeneralPurpose),
Argument.RD => new(new(ref _rd), RegisterSet.GeneralPurpose),
// Float Registers
Argument.FS => new(new(ref _rs), RegisterSet.FloatingPoints),
Argument.FT => new(new(ref _rt), RegisterSet.FloatingPoints),
Argument.FD => new(new(ref _rd), RegisterSet.FloatingPoints),
// RT Register for coprocessors
Argument.RT_Numbered => new(new(ref _rt), RegisterSet.Numbered),
// Invalid target type
_ => throw new ArgumentOutOfRangeException($"Argument of type '{target}' attempted to parse as a register.")
};
(Ref<GPRegister> regRef, RegisterSet set) = pair;
ref GPRegister reg = ref regRef.Value;
Breaking change?
No
Alternatives
For the code above, here's what it looks like using a switch statement instead of a switch expression.
// Get reference to selected register argument
ref GPRegister reg = ref _rs;
RegisterSet set = RegisterSet.GeneralPurpose;
switch (target)
{
// General Purpose Registers
case Argument.RS:
reg = ref _rs;
break;
case Argument.RT:
reg = ref _rt;
break;
case Argument.RD:
reg = ref _rd;
break;
// Float Registers
case Argument.FS:
reg = ref _rs;
set = RegisterSet.FloatingPoints;
break;
case Argument.FT:
reg = ref _rt;
set = RegisterSet.FloatingPoints;
break;
case Argument.FD:
reg = ref _rd;
set = RegisterSet.FloatingPoints;
break;
// RT Register for coprocessors
case Argument.RT_Numbered:
reg = ref _rt;
set = RegisterSet.Numbered;
break;
// Invalid target type
default:
return ThrowHelper.ThrowArgumentOutOfRangeException<bool>($"Argument of type '{target}' attempted to parse as a register.");
}
Perfectly legitimate code, but the pattern matching is much more convenient to read.
Additional context
This requires .NET 9 and C# version 13
Help us help you
Yes, I'd like to be assigned to work on this item
- Lingua principale
- C#
- Stelle
- 3.8k
- Fork
- 402
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di CommunityToolkit/dotnet
-
RelayCommand<T>.CanExecute(null) returns false for value types without a predicateForse già presa @apachezy l’ha presa 121 giorni fa. Apertabug :bug:
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
CommunityToolkit/dotnet#1206 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
CommunityToolkit/dotnet#1186 ·
-
bug :bug:
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 68/100
CommunityToolkit/dotnet#648 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
CommunityToolkit/dotnet#1218 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
CommunityToolkit/dotnet#1217 ·
Tutte le issue di CommunityToolkit/dotnet
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 2 giorni
-
area: core bug help wanted ready
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
ZaidX88/sluice#265 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
rate limit at lrclib.netAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
-
area: remote bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Install a C# EnvironmentAperta📅 Sprint 4 Module-Tools Setup Submit:None 🦔 Size Tiny
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
CodeYourFuture/Module-Tools#712 ·