This library aims to bring indexable properties to C#.
[TODO]
Use one of the follwing methods to install and use this library:
-
Package Manager:
PM> Install-Package Unknown6656.IndexableProperties -
.NET CLI:
> dotnet add package Unknown6656.IndexableProperties -
Package reference (e.g. in a
.csproj/.vbproj/.fsprojproject file):<PackageReference Include="Unknown6656.IndexableProperties" Version="*" />
-
Paket CLI:
> paket add Unknown6656.IndexableProperties -
F# Interactive:
#r "nuget: Unknown6656.IndexableProperties, *"
To use the indexable properties, simply include the namespace Unknown6656:
using Unknown6656;The library defines the following indexer types:
- Readable/Writable indexers (
Unknown6656.Indexer<...>) - Read-only indexers (
Unknown6656.ReadOnlyIndexer<...>) - Write-only indexers (
Unknown6656.WriteOnlyIndexer<...>) - By-reference indexers (
Unknown6656.RedIndexer<...>)
Each indexer defines a set of index types (Index1 through IndexN) and a input/return value type (Value).
An Indexer may be declared as follows:
public class MyClass
{
public Indexer<int, string> MyIndex { get; } = new(...);
}The code sample above declares a 1-dimensional indexer which takes an int as its only index and accepts/returns a string-value.
[TODO]
public class MyClass
{
public Indexer<int, double> Items { get; }
public Indexer<int, double> SquaredItems { get; }
public MyClass(double[] array)
{
Items = new(
index => array[index],
(index, value) => array[index] = value
);
SquaredItems = new(
index => array[index] * array[index],
(index, value) => array[index] = Math.Sqrt(value)
);
}
}
MyClass c = new(new double [] { 1, 2, 3, 4, 5 });
double original = c.Items[3];
double squared = c.SquaredItems[3];
c.SquaredItems[3] = 42;
double newvalue = c.Items[3];
Console.WriteLine("original item at index 3: " + original);
Console.WriteLine("original squared at index 3: " + squared);
Console.WriteLine("new item at index 3: " + newvalue);[TODO]