From b157c452a24cae8cd08bedaff79cc64c54647a64 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Tue, 15 Mar 2016 17:10:08 +0700 Subject: [PATCH] Class ApiOptionsSingleton was implemented in order to support proper unit tests. Now ApiOptionsSingleton.Instance is used as ApiOptions.None static member instead of creation of new ApiOptions class each time when ApiOptions.None is invoked. Singleton pattern will allow write proper tests for methods that use ApiOptions.None as their parameter For instance, now "Arg.Is(options => options == ApiOptions.None)" construction can be used. Also, usage of sigleton has some posititve performance impact. --- Octokit/Models/Request/ApiOptions.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Octokit/Models/Request/ApiOptions.cs b/Octokit/Models/Request/ApiOptions.cs index ef149633..764dd45f 100644 --- a/Octokit/Models/Request/ApiOptions.cs +++ b/Octokit/Models/Request/ApiOptions.cs @@ -7,9 +7,32 @@ namespace Octokit [DebuggerDisplay("{DebuggerDisplay,nq}")] public class ApiOptions { + private class ApiOptionsSingleton + { + private static readonly ApiOptions _instance = new ApiOptions(); + + // Explicit static constructor to tell C# compiler + // not to mark type as beforefieldinit + static ApiOptionsSingleton() + { + } + + private ApiOptionsSingleton() + { + } + + public static ApiOptions Instance + { + get + { + return _instance; + } + } + } + public static ApiOptions None { - get { return new ApiOptions(); } + get { return ApiOptionsSingleton.Instance; } } ///