#SharedStatic.GetOrCreate key question

1 messages · Page 1 of 1 (latest)

signal dust
signal dust
#

@simple prawn You might be able to answer this

simple prawn
#

Unfortunately I'm not sure about that answer, but I have asked some people who will know to chime in - likely on Monday or Tuesday though.

alpine crater
#

The context is used to define the specific instance of the type, if you didn't have a Key you could only have 1 of each type of shared static

private static readonly SharedStatic<int> Test1 = SharedStatic<int>.GetOrCreate<Key1>();
private static readonly SharedStatic<int> Test2 = SharedStatic<int>.GetOrCreate<Key2>();```
As for the subcontext, totally not needed in that sample you posted but I've found it to be pretty useful as a pattern for generics, for example this is how K is implemented in my library https://gitlab.com/tertle/com.bovinelabs.core/-/blob/master/Documentation~/K.md

```cs
public static class K<T>
{
    private static readonly SharedStatic<KMap> Map = SharedStatic<KMap>.GetOrCreate<KMap, T>();```