Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Platform.cs
Go to the documentation of this file.
1using System;
6
7namespace ReLogic.OS;
8
9public abstract class Platform : IDisposable
10{
11 public static readonly Platform Current = (OperatingSystem.IsWindows() ? new WindowsPlatform() : (OperatingSystem.IsMacOS() ? ((Platform)new OsxPlatform()) : ((Platform)new LinuxPlatform())));
12
13 public readonly PlatformType Type;
14
16
17 private bool _disposedValue;
18
19 public static bool IsWindows => Current.Type == PlatformType.Windows;
20
21 public static bool IsOSX => Current.Type == PlatformType.OSX;
22
23 public static bool IsLinux => Current.Type == PlatformType.Linux;
24
26 {
27 Type = type;
28 }
29
30 protected void RegisterService<T>(T service) where T : class
31 {
32 if (_services.Has<T>())
33 {
34 _services.Remove<T>();
35 }
36 _services.Register(service);
37 }
38
39 public abstract void InitializeClientServices(IntPtr windowHandle);
40
41 public static T Get<T>() where T : class
42 {
43 return Current._services.Get<T>();
44 }
45
46 public static bool Has<T>() where T : class
47 {
48 return Current._services.Has<T>();
49 }
50
51 public static void IfHas<T>(Action<T> callback) where T : class
52 {
53 Current._services.IfHas(callback);
54 }
55
56 public static U IfHas<T, U>(Func<T, U> callback) where T : class
57 {
58 return Current._services.IfHas(callback);
59 }
60
61 protected virtual void Dispose(bool disposing)
62 {
63 if (!_disposedValue)
64 {
65 if (disposing && _services != null)
66 {
68 _services = null;
69 }
70 _disposedValue = true;
71 }
72 }
73
74 public void Dispose()
75 {
76 Dispose(disposing: true);
77 }
78}
static T Get< T >()
Definition Platform.cs:41
virtual void Dispose(bool disposing)
Definition Platform.cs:61
TypeInstanceCollection< object > _services
Definition Platform.cs:15
static bool Has< T >()
Definition Platform.cs:46
readonly PlatformType Type
Definition Platform.cs:13
Platform(PlatformType type)
Definition Platform.cs:25
static U IfHas< T, U >(Func< T, U > callback)
Definition Platform.cs:56
static void IfHas< T >(Action< T > callback)
Definition Platform.cs:51
void RegisterService< T >(T service)
Definition Platform.cs:30
static bool IsOSX
Definition Platform.cs:21
static bool IsWindows
Definition Platform.cs:19
static bool IsLinux
Definition Platform.cs:23
static readonly Platform Current
Definition Platform.cs:11
void InitializeClientServices(IntPtr windowHandle)