Skip to content

Commit d7ec803

Browse files
authored
Optimize: use Property intead of Method (#4197)
1 parent d38f847 commit d7ec803

File tree

14 files changed

+29
-29
lines changed

14 files changed

+29
-29
lines changed

src/Neo.ConsoleService/ConsoleHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static string ReadUserInput(string prompt, bool password = false)
103103
do
104104
{
105105
key = Console.ReadKey(true);
106-
if (PrintableASCIIChars.IndexOf(key.KeyChar) != -1)
106+
if (PrintableASCIIChars.Contains(key.KeyChar))
107107
{
108108
sb.Append(key.KeyChar);
109109
Console.Write(password ? '*' : key.KeyChar);
@@ -138,7 +138,7 @@ public static SecureString ReadSecureString(string prompt)
138138
do
139139
{
140140
key = Console.ReadKey(true);
141-
if (PrintableASCIIChars.IndexOf(key.KeyChar) != -1)
141+
if (PrintableASCIIChars.Contains(key.KeyChar))
142142
{
143143
securePwd.AppendChar(key.KeyChar);
144144
Console.Write('*');

src/Neo/Ledger/MemoryPool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ private void RemoveConflictsOfVerified(PoolItem item)
447447
if (_conflicts.TryGetValue(h, out var conflicts))
448448
{
449449
conflicts.Remove(item.Tx.Hash);
450-
if (conflicts.Count() == 0)
450+
if (conflicts.Count == 0)
451451
{
452452
_conflicts.Remove(h);
453453
}

src/Plugins/OracleService/OracleSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private OracleSettings(IConfigurationSection section)
6363
AllowPrivateHost = section.GetValue("AllowPrivateHost", false);
6464
AllowedContentTypes = section.GetSection("AllowedContentTypes").GetChildren().Select(p => p.Get<string>()).ToArray();
6565
ExceptionPolicy = section.GetValue("UnhandledExceptionPolicy", UnhandledExceptionPolicy.Ignore);
66-
if (AllowedContentTypes.Count() == 0)
66+
if (AllowedContentTypes.Length == 0)
6767
AllowedContentTypes = AllowedContentTypes.Concat("application/json").ToArray();
6868
Https = new HttpsSettings(section.GetSection("Https"));
6969
NeoFS = new NeoFSSettings(section.GetSection("NeoFS"));

src/Plugins/RestServer/RestWebServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public void Start()
166166
options.OnRejected = async (context, token) =>
167167
{
168168
context.HttpContext.Response.StatusCode = StatusCodes.Status429TooManyRequests;
169-
context.HttpContext.Response.Headers["Retry-After"] = _settings.RateLimitWindowSeconds.ToString();
169+
context.HttpContext.Response.Headers.RetryAfter = _settings.RateLimitWindowSeconds.ToString();
170170
context.HttpContext.Response.ContentType = "text/plain";
171171

172172
if (context.Lease.TryGetMetadata(MetadataName.RetryAfter, out var retryAfter))

src/Plugins/RpcServer/RpcServer.Wallet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,8 @@ private JObject GetVerificationResult(UInt160 scriptHash, ContractParameter[] ar
710710
var contract = NativeContract.ContractManagement.GetContract(snapshot, scriptHash)
711711
.NotNull_Or(RpcError.UnknownContract);
712712

713-
var md = contract.Manifest.Abi.GetMethod(ContractBasicMethod.Verify, args.Count())
714-
.NotNull_Or(RpcErrorFactory.InvalidContractVerification(contract.Hash, args.Count()));
713+
var md = contract.Manifest.Abi.GetMethod(ContractBasicMethod.Verify, args.Length)
714+
.NotNull_Or(RpcErrorFactory.InvalidContractVerification(contract.Hash, args.Length));
715715

716716
(md.ReturnType == ContractParameterType.Boolean)
717717
.True_Or(RpcErrorFactory.InvalidContractVerification("The verify method doesn't return boolean value."));

src/Plugins/RpcServer/RpcServer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ internal bool CheckAuth(HttpContext context)
8181
{
8282
if (string.IsNullOrEmpty(settings.RpcUser)) return true;
8383

84-
string? reqauth = context.Request.Headers["Authorization"];
84+
string? reqauth = context.Request.Headers.Authorization;
8585
if (string.IsNullOrEmpty(reqauth))
8686
{
87-
context.Response.Headers["WWW-Authenticate"] = "Basic realm=\"Restricted\"";
87+
context.Response.Headers.WWWAuthenticate = "Basic realm=\"Restricted\"";
8888
context.Response.StatusCode = 401;
8989
return false;
9090
}

tests/Neo.Json.UnitTests/UT_JArray.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ public void TestInsert()
168168
};
169169

170170
jArray.Insert(1, bob);
171-
Assert.AreEqual(5, jArray.Count());
171+
Assert.AreEqual(5, jArray.Count);
172172
Assert.AreEqual(alice, jArray[0]);
173173
Assert.AreEqual(bob, jArray[1]);
174174
Assert.AreEqual(alice, jArray[2]);
175175

176176
jArray.Insert(5, bob);
177-
Assert.AreEqual(6, jArray.Count());
177+
Assert.AreEqual(6, jArray.Count);
178178
Assert.AreEqual(bob, jArray[5]);
179179
}
180180

@@ -208,15 +208,15 @@ public void TestRemove()
208208
{
209209
alice
210210
};
211-
Assert.AreEqual(1, jArray.Count());
211+
Assert.AreEqual(1, jArray.Count);
212212
jArray.Remove(alice);
213-
Assert.AreEqual(0, jArray.Count());
213+
Assert.AreEqual(0, jArray.Count);
214214

215215
jArray.Add(alice);
216216
jArray.Add(alice);
217-
Assert.AreEqual(2, jArray.Count());
217+
Assert.AreEqual(2, jArray.Count);
218218
jArray.Remove(alice);
219-
Assert.AreEqual(1, jArray.Count());
219+
Assert.AreEqual(1, jArray.Count);
220220
}
221221

222222
[TestMethod]
@@ -229,7 +229,7 @@ public void TestRemoveAt()
229229
alice
230230
};
231231
jArray.RemoveAt(1);
232-
Assert.AreEqual(2, jArray.Count());
232+
Assert.AreEqual(2, jArray.Count);
233233
Assert.DoesNotContain(bob, jArray);
234234
}
235235

tests/Neo.Plugins.ApplicationLogs.Tests/UT_LogReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public async Task Test_Commands()
196196
{
197197
Assert.AreEqual(VMState.HALT, log.VmState);
198198
Assert.IsTrue(log.Stack[0].GetBoolean());
199-
Assert.AreEqual(2, log.Notifications.Count());
199+
Assert.AreEqual(2, log.Notifications.Length);
200200
Assert.AreEqual("Transfer", log.Notifications[0].EventName);
201201
Assert.AreEqual(log.Notifications[0].ScriptHash, NativeContract.NEO.Hash);
202202
Assert.AreEqual(1, log.Notifications[0].State[2]);

tests/Neo.Plugins.RestServer.Tests/ControllerRateLimitingTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void Initialize()
5353
options.OnRejected = async (context, token) =>
5454
{
5555
context.HttpContext.Response.StatusCode = StatusCodes.Status429TooManyRequests;
56-
context.HttpContext.Response.Headers["Retry-After"] = "10";
56+
context.HttpContext.Response.Headers.RetryAfter = "10";
5757
await context.HttpContext.Response.WriteAsync("Too many requests. Please try again later.", token);
5858
};
5959
});

tests/Neo.Plugins.RestServer.Tests/RateLimitingIntegrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private void SetupTestServer(int permitLimit, int windowSeconds, int queueLimit,
114114
options.OnRejected = async (context, token) =>
115115
{
116116
context.HttpContext.Response.StatusCode = StatusCodes.Status429TooManyRequests;
117-
context.HttpContext.Response.Headers["Retry-After"] = windowSeconds.ToString();
117+
context.HttpContext.Response.Headers.RetryAfter = windowSeconds.ToString();
118118

119119
if (context.Lease.TryGetMetadata(MetadataName.RetryAfter, out var retryAfter))
120120
{

0 commit comments

Comments
 (0)