Skip to content
This repository was archived by the owner on Nov 22, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Neo.VM/ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,13 @@ public ExecutionContext Clone(int initialPosition)
/// Gets custom data of the specified type. If the data does not exist, create a new one.
/// </summary>
/// <typeparam name="T">The type of data to be obtained.</typeparam>
/// <param name="factory">A delegate used to create the entry. If factory is null, new() will be used.</param>
/// <returns>The custom data of the specified type.</returns>
public T GetState<T>() where T : class, new()
public T GetState<T>(Func<T>? factory) where T : class, new()
{
if (!shared_states.States.TryGetValue(typeof(T), out object? value))
{
value = new T();
value = factory is null ? new T() : factory();
shared_states.States[typeof(T)] = value;
}
return (T)value;
Expand Down