1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
// ReSharper disable UnusedMember.Global -- used dynamically through proxies
using System;
using System.Collections.Generic;
using System.Reflection;
using StardewModdingAPI.Utilities;
namespace SMAPI.Tests.ModApiProvider.Framework
{
/// <summary>A mod-provided API which provides basic events, properties, and methods.</summary>
public class SimpleApi : BaseApi
{
/*********
** Test interface
*********/
/****
** Events
****/
/// <summary>A simple event field.</summary>
public event EventHandler<int>? OnEventRaised;
/// <summary>A simple event property with custom add/remove logic.</summary>
public event EventHandler<int> OnEventRaisedProperty
{
add => this.OnEventRaised += value;
remove => this.OnEventRaised -= value;
}
/****
** Properties
****/
/// <summary>A simple numeric property.</summary>
public int NumberProperty { get; set; }
/// <summary>A simple object property.</summary>
public object? ObjectProperty { get; set; }
/// <summary>A simple list property.</summary>
public List<string>? ListProperty { get; set; }
/// <summary>A simple list property with an interface.</summary>
public IList<string>? ListPropertyWithInterface { get; set; }
/// <summary>A property with nested generics.</summary>
public IDictionary<string, IList<string>>? GenericsProperty { get; set; }
/// <summary>A property using an enum available to both mods.</summary>
public BindingFlags EnumProperty { get; set; }
/// <summary>A read-only property.</summary>
public int GetterProperty => 42;
/****
** Methods
****/
/// <summary>A simple method with no return value.</summary>
public void GetNothing() { }
/// <summary>A simple method which returns a number.</summary>
public int GetInt(int value)
{
return value;
}
/// <summary>A simple method which returns an object.</summary>
public object GetObject(object value)
{
return value;
}
/// <summary>A simple method which returns a list.</summary>
public List<string> GetList(string value)
{
return new() { value };
}
/// <summary>A simple method which returns a list with an interface.</summary>
public IList<string> GetListWithInterface(string value)
{
return new List<string> { value };
}
/// <summary>A simple method which returns nested generics.</summary>
public IDictionary<string, IList<string>> GetGenerics(string key, string value)
{
return new Dictionary<string, IList<string>>
{
[key] = new List<string> { value }
};
}
/// <summary>A simple method which returns a lambda.</summary>
public Func<string, string> GetLambda(Func<string, string> value)
{
return value;
}
/// <summary>A simple method which returns out parameters.</summary>
public bool TryGetOutParameter(int inputNumber, out int outNumber, out string outString, out PerScreen<int> outReference, out IDictionary<int, PerScreen<int>> outComplexType)
{
outNumber = inputNumber;
outString = inputNumber.ToString();
outReference = new PerScreen<int>(() => inputNumber);
outComplexType = new Dictionary<int, PerScreen<int>>
{
[inputNumber] = new PerScreen<int>(() => inputNumber)
};
return true;
}
/*********
** Helper methods
*********/
/// <summary>Raise the <see cref="OnEventRaised"/> event.</summary>
/// <param name="value">The value to pass to the event.</param>
public void RaiseEventField(int value)
{
this.OnEventRaised?.Invoke(null, value);
}
}
}
|