Skip to content

Commit

Permalink
Changed to Use collection expression for array (#3217)
Browse files Browse the repository at this point in the history
Co-authored-by: Shargon <[email protected]>
  • Loading branch information
cschuchardt88 and shargon authored May 7, 2024
1 parent eacf16d commit 6f40f00
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 25 deletions.
7 changes: 5 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion

# Suggest more modern language features when available
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_object_initializer = true:warning
dotnet_style_collection_initializer = true:warning
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
Expand Down Expand Up @@ -256,6 +256,9 @@ dotnet_diagnostic.IDE0060.severity = none

[src/{Analyzers,CodeStyle,Features,Workspaces,EditorFeatures,VisualStudio}/**/*.{cs,vb}]

# Use collection expression for array
dotnet_diagnostic.IDE0300.severity = warning

# Avoid "this." and "Me." if not necessary
dotnet_diagnostic.IDE0003.severity = warning
dotnet_diagnostic.IDE0009.severity = warning
Expand Down
12 changes: 8 additions & 4 deletions src/Neo/Cryptography/BloomFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ public BloomFilter(int m, int k, uint nTweak)
{
if (k < 0 || m < 0) throw new ArgumentOutOfRangeException();
seeds = Enumerable.Range(0, k).Select(p => (uint)p * 0xFBA4C795 + nTweak).ToArray();
bits = new BitArray(m);
bits.Length = m;
bits = new BitArray(m)
{
Length = m
};
Tweak = nTweak;
}

Expand All @@ -64,8 +66,10 @@ public BloomFilter(int m, int k, uint nTweak, ReadOnlyMemory<byte> elements)
{
if (k < 0 || m < 0) throw new ArgumentOutOfRangeException();
seeds = Enumerable.Range(0, k).Select(p => (uint)p * 0xFBA4C795 + nTweak).ToArray();
bits = new BitArray(elements.ToArray());
bits.Length = m;
bits = new BitArray(elements.ToArray())
{
Length = m
};
Tweak = nTweak;
}

Expand Down
8 changes: 5 additions & 3 deletions src/Neo/Network/P2P/Payloads/Signer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,11 @@ public void Serialize(BinaryWriter writer)
/// <returns>The converted signer.</returns>
public static Signer FromJson(JObject json)
{
Signer signer = new();
signer.Account = UInt160.Parse(json["account"].GetString());
signer.Scopes = Enum.Parse<WitnessScope>(json["scopes"].GetString());
Signer signer = new()
{
Account = UInt160.Parse(json["account"].GetString()),
Scopes = Enum.Parse<WitnessScope>(json["scopes"].GetString())
};
if (signer.Scopes.HasFlag(WitnessScope.CustomContracts))
signer.AllowedContracts = ((JArray)json["allowedcontracts"]).Select(p => UInt160.Parse(p.GetString())).ToArray();
if (signer.Scopes.HasFlag(WitnessScope.CustomGroups))
Expand Down
10 changes: 6 additions & 4 deletions tests/Neo.Json.UnitTests/UT_OrderedDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ public class UT_OrderedDictionary
[TestInitialize]
public void SetUp()
{
od = new OrderedDictionary<string, uint>();
od.Add("a", 1);
od.Add("b", 2);
od.Add("c", 3);
od = new OrderedDictionary<string, uint>
{
{ "a", 1 },
{ "b", 2 },
{ "c", 3 }
};
}

[TestMethod]
Expand Down
6 changes: 4 additions & 2 deletions tests/Neo.UnitTests/Network/P2P/Payloads/UT_NotValidBefore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ public void Size_Get()
[TestMethod]
public void ToJson()
{
var test = new NotValidBefore();
test.Height = 42;
var test = new NotValidBefore
{
Height = 42
};
var json = test.ToJson().ToString();
Assert.AreEqual(@"{""type"":""NotValidBefore"",""height"":42}", json);
}
Expand Down
6 changes: 4 additions & 2 deletions tests/Neo.UnitTests/SmartContract/UT_ContractParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ public void TestToString()
ContractParameter contractParameter1 = new();
Assert.AreEqual("(null)", contractParameter1.ToString());

ContractParameter contractParameter2 = new(ContractParameterType.ByteArray);
contractParameter2.Value = new byte[1];
ContractParameter contractParameter2 = new(ContractParameterType.ByteArray)
{
Value = new byte[1]
};
Assert.AreEqual("00", contractParameter2.ToString());

ContractParameter contractParameter3 = new(ContractParameterType.Array);
Expand Down
20 changes: 12 additions & 8 deletions tests/Neo.UnitTests/VM/UT_Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ public void TestEmit()
[TestMethod]
public void TestToJson()
{
var item = new VM.Types.Array();
item.Add(5);
item.Add("hello world");
item.Add(new byte[] { 1, 2, 3 });
item.Add(true);
var item = new VM.Types.Array
{
5,
"hello world",
new byte[] { 1, 2, 3 },
true
};

Assert.AreEqual("{\"type\":\"Integer\",\"value\":\"5\"}", item[0].ToJson().ToString());
Assert.AreEqual("{\"type\":\"ByteString\",\"value\":\"aGVsbG8gd29ybGQ=\"}", item[1].ToJson().ToString());
Expand Down Expand Up @@ -274,9 +276,11 @@ private void TestEmitPush2Array()
{
ScriptBuilder sb = new ScriptBuilder();
ContractParameter parameter = new ContractParameter(ContractParameterType.Array);
IList<ContractParameter> values = new List<ContractParameter>();
values.Add(new ContractParameter(ContractParameterType.Integer));
values.Add(new ContractParameter(ContractParameterType.Integer));
IList<ContractParameter> values = new List<ContractParameter>
{
new ContractParameter(ContractParameterType.Integer),
new ContractParameter(ContractParameterType.Integer)
};
parameter.Value = values;
sb.EmitPush(parameter);
byte[] tempArray = new byte[4];
Expand Down

0 comments on commit 6f40f00

Please sign in to comment.