Skip to content

Commit 87de771

Browse files
committed
massive code style cleanup, c# 6 language level features
1 parent 5a7b616 commit 87de771

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1226
-1151
lines changed

dotnet/Razorvine.Pyrolite/DebugHelper/Program.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ namespace DebugHelper
1010
/// </summary>
1111
public static class Program
1212
{
13-
public static void Main(string[] args)
13+
public static void Main()
1414
{
1515
Unpickler u=new Unpickler();
16-
byte[] data;
17-
object result;
18-
16+
1917
Console.WriteLine("here we go; 1");
20-
data=PickleUtils.str2bytes("\u0080\u0002carray\narray\nq\u0000U\u0001iq\u0001]q\u0002\u0086q\u0003Rq\u0004.");
21-
result=u.loads(data);
18+
var data = PickleUtils.str2bytes("\u0080\u0002carray\narray\nq\u0000U\u0001iq\u0001]q\u0002\u0086q\u0003Rq\u0004.");
19+
var result = u.loads(data);
2220
PrettyPrint.print(result);
2321

2422
Console.WriteLine("here we go; 2");

dotnet/Razorvine.Pyrolite/EchoExample/Program.cs

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using Razorvine.Pyro;
55
// ReSharper disable CheckNamespace
6+
// ReSharper disable PossibleNullReferenceException
67

78
namespace Pyrolite.TestPyroEcho
89
{
@@ -11,7 +12,7 @@ namespace Pyrolite.TestPyroEcho
1112
/// </summary>
1213
public static class Program
1314
{
14-
public static void Main(String[] args) {
15+
public static void Main(string[] args) {
1516

1617
char test;
1718
if(args.Length==1)
@@ -21,21 +22,21 @@ public static void Main(String[] args) {
2122
test = Console.ReadLine().Trim().ToLowerInvariant()[0];
2223
}
2324

24-
setConfig();
25+
SetConfig();
2526
try {
2627
switch(test)
2728
{
2829
case 'e':
2930
Console.WriteLine("\r\nRunning ECHO test.\r\n");
30-
new TestEcho().Run();
31+
TestEcho.Run();
3132
break;
3233
case 'h':
3334
Console.WriteLine("\r\nRunning HANDSHAKE test.\r\n");
34-
new TestHandshake().Run();
35+
TestHandshake.Run();
3536
break;
3637
case 's':
3738
Console.WriteLine("\r\nRunning STREAMING test.\r\n");
38-
new TestStreaming().Run();
39+
TestStreaming.Run();
3940
break;
4041
default:
4142
Console.Error.WriteLine("invalid choice");
@@ -48,7 +49,7 @@ public static void Main(String[] args) {
4849
Console.WriteLine("\r\nEnter to exit:"); Console.ReadLine();
4950
}
5051

51-
static void setConfig()
52+
private static void SetConfig()
5253
{
5354
string tracedir=Environment.GetEnvironmentVariable("PYRO_TRACE_DIR");
5455
if(tracedir!=null) {

dotnet/Razorvine.Pyrolite/EchoExample/TestEcho.cs

+11-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace Pyrolite.TestPyroEcho
1414
/// <summary>
1515
/// This custom proxy adds custom annotations to the pyro messages
1616
/// </summary>
17+
// ReSharper disable once ArrangeTypeModifiers
18+
// ReSharper disable once UnusedMember.Global
1719
class CustomProxy : PyroProxy
1820
{
1921
public CustomProxy(PyroURI uri): base(uri)
@@ -30,11 +32,11 @@ public override IDictionary<string, byte[]> annotations()
3032
/// <summary>
3133
/// Test Pyro with the Pyro echo server.
3234
/// </summary>
33-
public class TestEcho {
34-
private static readonly byte[] hmacKey = null; // Encoding.UTF8.GetBytes("foo");
35+
public static class TestEcho {
36+
private static readonly byte[] HmacKey = null; // Encoding.UTF8.GetBytes("foo");
3537

3638

37-
public void Run() {
39+
public static void Run() {
3840

3941
Console.WriteLine("Testing Pyro echo server (make sure it's running, with nameserver enabled)...");
4042
Console.WriteLine("Pyrolite version: "+Config.PYROLITE_VERSION);
@@ -45,17 +47,17 @@ public void Run() {
4547
if(Config.SERIALIZER==Config.SerializerType.serpent)
4648
Console.WriteLine("note that for the serpent serializer, you need to have the Razorvine.Serpent assembly available.");
4749

48-
NameServerProxy ns = NameServerProxy.locateNS(null, hmacKey: hmacKey);
50+
NameServerProxy ns = NameServerProxy.locateNS(null, hmacKey: HmacKey);
4951
using(dynamic p = new PyroProxy(ns.lookup("test.echoserver")))
5052
{
51-
p.pyroHmacKey=hmacKey;
53+
p.pyroHmacKey=HmacKey;
5254
p.pyroHandshake = "banana";
5355

5456
// non-dynamic way of constructing a proxy is:
5557
// PyroProxy p=new PyroProxy("localhost",9999,"test.echoserver");
5658

5759
Console.WriteLine("echo(), param=42:");
58-
Object result=p.echo(42);
60+
object result=p.echo(42);
5961
Console.WriteLine("return value:");
6062
PrettyPrint.print(result);
6163

@@ -76,7 +78,7 @@ public void Run() {
7678

7779
// some more examples
7880

79-
String s="This string is way too long. This string is way too long. This string is way too long. This string is way too long. ";
81+
string s="This string is way too long. This string is way too long. This string is way too long. This string is way too long. ";
8082
s=s+s+s+s+s;
8183
Console.WriteLine("echo param:");
8284
PrettyPrint.print(s);
@@ -85,7 +87,7 @@ public void Run() {
8587
PrettyPrint.print(result);
8688

8789
Console.WriteLine("dict test.");
88-
IDictionary<string, object> map = new Dictionary<string, object>()
90+
IDictionary<string, object> map = new Dictionary<string, object>
8991
{
9092
{"value", 42},
9193
{"message", "hello"},
@@ -105,7 +107,7 @@ public void Run() {
105107
Debug.Assert(p2.pyroMethods.Contains("echo"));
106108
if(p2.pyroHmacKey!=null) {
107109
string hmac2 = Encoding.UTF8.GetString(p2.pyroHmacKey);
108-
Debug.Assert(hmac2==Encoding.UTF8.GetString(hmacKey));
110+
Debug.Assert(hmac2==Encoding.UTF8.GetString(HmacKey));
109111
}
110112

111113
Console.WriteLine("remote iterator test.");

dotnet/Razorvine.Pyrolite/EchoExample/TestHandshake.cs

+17-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using System.Collections.Generic;
66
using Razorvine.Pyro;
77
// ReSharper disable CheckNamespace
8+
// ReSharper disable PossibleNullReferenceException
9+
// ReSharper disable once InconsistentNaming
810

911
namespace Pyrolite.TestPyroEcho
1012
{
@@ -27,20 +29,25 @@ public override IDictionary<string, byte[]> annotations()
2729

2830
public override void validateHandshake(object handshake_response) {
2931
// the handshake example server returns a list.
30-
var response_list = (IList<object>) handshake_response;
31-
Console.WriteLine("Proxy received handshake response data: "+ string.Join(",", response_list));
32+
var responseList = (IList<object>) handshake_response;
33+
Console.WriteLine("Proxy received handshake response data: "+ string.Join(",", responseList));
3234
}
3335

3436
public override void responseAnnotations(IDictionary<string, byte[]> annotations, ushort msgtype) {
3537
Console.WriteLine(" Got response (type={0}). Annotations:", msgtype);
3638
foreach(var ann in annotations) {
3739
string value;
38-
if(ann.Key=="CORR") {
39-
value = new Guid(ann.Value).ToString();
40-
} else if (ann.Key=="HMAC") {
41-
value = "[...]";
42-
} else {
43-
value = ann.Value.ToString();
40+
switch (ann.Key)
41+
{
42+
case "CORR":
43+
value = new Guid(ann.Value).ToString();
44+
break;
45+
case "HMAC":
46+
value = "[...]";
47+
break;
48+
default:
49+
value = ann.Value.ToString();
50+
break;
4451
}
4552
Console.WriteLine(" {0} -> {1}", ann.Key, value);
4653
}
@@ -51,9 +58,9 @@ public override void responseAnnotations(IDictionary<string, byte[]> annotations
5158
/// Test Pyro with the Handshake example server to see
5259
/// how custom annotations and handshake handling is done.
5360
/// </summary>
54-
public class TestHandshake {
61+
public static class TestHandshake {
5562

56-
public void Run() {
63+
public static void Run() {
5764

5865
Console.WriteLine("Testing Pyro handshake and custom annotations. Make sure the server from the pyro handshake example is running.");
5966
Console.WriteLine("Pyrolite version: "+Config.PYROLITE_VERSION);

dotnet/Razorvine.Pyrolite/EchoExample/TestStreaming.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44
using System.Collections;
55
using Razorvine.Pyro;
66
// ReSharper disable CheckNamespace
7+
// ReSharper disable PossibleNullReferenceException
78

89
namespace Pyrolite.TestPyroEcho
910
{
1011

1112
/// <summary>
1213
/// Test Pyro with streaming.
1314
/// </summary>
14-
public class TestStreaming {
15+
public static class TestStreaming {
1516

16-
public void Run() {
17+
public static void Run() {
1718

18-
setConfig();
19+
SetConfig();
1920
// Config.SERIALIZER = Config.SerializerType.pickle;
2021

2122
Console.WriteLine("Pyrolite version: "+Config.PYROLITE_VERSION);
@@ -71,8 +72,8 @@ public void Run() {
7172
}
7273
}
7374
}
74-
75-
static void setConfig()
75+
76+
private static void SetConfig()
7677
{
7778
string tracedir=Environment.GetEnvironmentVariable("PYRO_TRACE_DIR");
7879
if(tracedir!=null) {

dotnet/Razorvine.Pyrolite/FlameExample/TestFlame.cs

+13-14
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,40 @@ namespace Pyrolite.TestPyroFlame
1111
/// Test Pyro with a Flame server
1212
/// </summary>
1313
public static class TestFlame {
14+
private static readonly byte[] HmacKey = null;
1415

15-
static byte[] hmacKey = null;
16-
17-
public static void Main(String[] args) {
16+
public static void Main() {
1817
try {
1918
Test();
2019
} catch (Exception x) {
2120
Console.WriteLine("unhandled exception: {0}",x);
2221
}
2322
}
24-
25-
public static void Test() {
23+
24+
private static void Test() {
2625

2726
Console.WriteLine("Testing Pyro flame server (make sure it's running on localhost 9999)...");
2827
Console.WriteLine("Pyrolite version: "+Config.PYROLITE_VERSION);
2928

30-
setConfig();
29+
SetConfig();
3130
using(dynamic flame=new PyroProxy("localhost",9999,"Pyro.Flame"))
3231
{
33-
if(hmacKey!=null) flame.pyroHmacKey = hmacKey;
32+
if(HmacKey!=null) flame.pyroHmacKey = HmacKey;
3433

3534
Console.WriteLine("builtin:");
36-
using(dynamic r_max=(FlameBuiltin)flame.builtin("max"))
35+
using(dynamic rMax=(FlameBuiltin)flame.builtin("max"))
3736
{
38-
if(hmacKey!=null) r_max.pyroHmacKey = hmacKey;
37+
if(HmacKey!=null) rMax.pyroHmacKey = HmacKey;
3938

40-
int maximum=(int)r_max(new []{22,99,1}); // invoke remote max() builtin function
39+
int maximum=(int)rMax(new []{22,99,1}); // invoke remote max() builtin function
4140
Console.WriteLine("maximum="+maximum);
4241
}
4342

44-
using(dynamic r_module=(FlameModule)flame.module("socket"))
43+
using(dynamic rModule=(FlameModule)flame.module("socket"))
4544
{
46-
if(hmacKey!=null) r_module.pyroHmacKey = hmacKey;
45+
if(HmacKey!=null) rModule.pyroHmacKey = HmacKey;
4746

48-
String hostname=(String)r_module.gethostname(); // get remote hostname
47+
string hostname=(string)rModule.gethostname(); // get remote hostname
4948
Console.WriteLine("hostname="+hostname);
5049
}
5150

@@ -63,7 +62,7 @@ public static void Test() {
6362
}
6463
}
6564

66-
static void setConfig()
65+
private static void SetConfig()
6766
{
6867
string tracedir=Environment.GetEnvironmentVariable("PYRO_TRACE_DIR");
6968
if(tracedir!=null) {

dotnet/Razorvine.Pyrolite/NamingExample/TestNaming.cs

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* part of Pyrolite, by Irmen de Jong ([email protected]) */
22

33
using System;
4-
using System.Collections.Generic;
54
using Razorvine.Pyro;
65
// ReSharper disable CheckNamespace
76

@@ -12,31 +11,30 @@ namespace Pyrolite.TestPyroNaming
1211
/// Test Pyro with the Pyro name server.
1312
/// </summary>
1413
public static class TestNaming {
14+
private static readonly byte[] HmacKey = null;
1515

16-
static byte[] hmacKey = null;
17-
18-
public static void Main(String[] args) {
16+
public static void Main() {
1917
try {
2018
Test();
2119
} catch (Exception x) {
2220
Console.WriteLine("unhandled exception: {0}",x);
2321
}
2422
Console.WriteLine("\r\nEnter to exit:"); Console.ReadLine();
2523
}
26-
27-
public static void Test() {
24+
25+
private static void Test() {
2826

2927
Console.WriteLine("Testing Pyro nameserver connection (make sure it's running with a broadcast server)...");
3028
Console.WriteLine("Pyrolite version: "+Config.PYROLITE_VERSION);
3129

32-
setConfig();
30+
SetConfig();
3331
// Config.SERIALIZER = Config.SerializerType.pickle;
3432

3533
Console.WriteLine("serializer used: {0}", Config.SERIALIZER);
3634
if(Config.SERIALIZER==Config.SerializerType.serpent)
3735
Console.WriteLine("note that for the serpent serializer, you need to have the Razorvine.Serpent assembly available.");
3836

39-
using(NameServerProxy ns=NameServerProxy.locateNS(null, hmacKey: hmacKey))
37+
using(NameServerProxy ns=NameServerProxy.locateNS(null, hmacKey: HmacKey))
4038
{
4139
Console.WriteLine("discovered ns at "+ns.hostname+":"+ns.port);
4240
ns.ping();
@@ -54,13 +52,13 @@ public static void Test() {
5452

5553

5654
Console.WriteLine("\nobjects registered in the name server:");
57-
IDictionary<string,string> objects = ns.list(null, null);
55+
var objects = ns.list(null, null);
5856
foreach(string key in objects.Keys) {
5957
Console.WriteLine(key + " --> " + objects[key]);
6058
}
6159

6260
Console.WriteLine("\nobjects registered in the name server, with metadata:");
63-
IDictionary<string, Tuple<string, ISet<string>>> objectsm = ns.list_with_meta(null, null);
61+
var objectsm = ns.list_with_meta(null, null);
6462
foreach(string key in objectsm.Keys) {
6563
var registration = objectsm[key];
6664
Console.WriteLine(key + " --> " + registration.Item1);
@@ -94,12 +92,12 @@ public static void Test() {
9492

9593
using(PyroProxy p=new PyroProxy(ns.lookup("Pyro.NameServer")))
9694
{
97-
p.pyroHmacKey = hmacKey;
95+
p.pyroHmacKey = HmacKey;
9896
p.call("ping");
9997
}
10098

101-
int num_removed=ns.remove(null, "dotnet.", null);
102-
Console.WriteLine("number of removed entries: {0}",num_removed);
99+
int numRemoved=ns.remove(null, "dotnet.", null);
100+
Console.WriteLine("number of removed entries: {0}",numRemoved);
103101

104102
try {
105103
Console.WriteLine("uri=" + ns.lookup("dotnet.test")); // should fail....
@@ -110,8 +108,8 @@ public static void Test() {
110108
}
111109

112110
}
113-
114-
static void setConfig()
111+
112+
private static void SetConfig()
115113
{
116114
string tracedir=Environment.GetEnvironmentVariable("PYRO_TRACE_DIR");
117115
if(tracedir!=null) {

0 commit comments

Comments
 (0)