Skip to content

Commit 5a91736

Browse files
committed
C#: Change public fields to properties
1 parent 92ccb79 commit 5a91736

Some content is hidden

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

45 files changed

+95
-100
lines changed

csharp/autobuilder/Semmle.Autobuild.CSharp.Tests/BuildScripts.cs

+17-17
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ internal class TestActions : IBuildActions
2020
/// <summary>
2121
/// List of strings passed to FileDelete.
2222
/// </summary>
23-
public readonly IList<string> FileDeleteIn = new List<string>();
23+
public IList<string> FileDeleteIn { get; } = new List<string>();
2424

2525
void IBuildActions.FileDelete(string file)
2626
{
2727
FileDeleteIn.Add(file);
2828
}
2929

30-
public readonly IList<string> FileExistsIn = new List<string>();
31-
public readonly IDictionary<string, bool> FileExists = new Dictionary<string, bool>();
30+
public IList<string> FileExistsIn { get; } = new List<string>();
31+
public IDictionary<string, bool> FileExists { get; } = new Dictionary<string, bool>();
3232

3333
bool IBuildActions.FileExists(string file)
3434
{
@@ -42,12 +42,12 @@ bool IBuildActions.FileExists(string file)
4242
throw new ArgumentException("Missing FileExists " + file);
4343
}
4444

45-
public readonly IList<string> RunProcessIn = new List<string>();
46-
public readonly IDictionary<string, int> RunProcess = new Dictionary<string, int>();
47-
public readonly IDictionary<string, string> RunProcessOut = new Dictionary<string, string>();
48-
public readonly IDictionary<string, string> RunProcessWorkingDirectory = new Dictionary<string, string>();
49-
public readonly HashSet<string> CreateDirectories = new HashSet<string>();
50-
public readonly HashSet<(string, string)> DownloadFiles = new HashSet<(string, string)>();
45+
public IList<string> RunProcessIn { get; } = new List<string>();
46+
public IDictionary<string, int> RunProcess { get; } = new Dictionary<string, int>();
47+
public IDictionary<string, string> RunProcessOut { get; } = new Dictionary<string, string>();
48+
public IDictionary<string, string> RunProcessWorkingDirectory { get; } = new Dictionary<string, string>();
49+
public HashSet<string> CreateDirectories { get; } = new HashSet<string>();
50+
public HashSet<(string, string)> DownloadFiles { get; } = new HashSet<(string, string)>();
5151

5252
int IBuildActions.RunProcess(string cmd, string args, string? workingDirectory, IDictionary<string, string>? env, out IList<string> stdOut)
5353
{
@@ -85,14 +85,14 @@ int IBuildActions.RunProcess(string cmd, string args, string? workingDirectory,
8585
return ret;
8686
}
8787

88-
public readonly IList<string> DirectoryDeleteIn = new List<string>();
88+
public IList<string> DirectoryDeleteIn { get; } = new List<string>();
8989

9090
void IBuildActions.DirectoryDelete(string dir, bool recursive)
9191
{
9292
DirectoryDeleteIn.Add(dir);
9393
}
9494

95-
public readonly IDictionary<string, bool> DirectoryExists = new Dictionary<string, bool>();
95+
public IDictionary<string, bool> DirectoryExists { get; } = new Dictionary<string, bool>();
9696

9797
bool IBuildActions.DirectoryExists(string dir)
9898
{
@@ -102,7 +102,7 @@ bool IBuildActions.DirectoryExists(string dir)
102102
return ret;
103103
}
104104

105-
public readonly IDictionary<string, string?> GetEnvironmentVariable = new Dictionary<string, string?>();
105+
public IDictionary<string, string?> GetEnvironmentVariable { get; } = new Dictionary<string, string?>();
106106

107107
string? IBuildActions.GetEnvironmentVariable(string name)
108108
{
@@ -112,14 +112,14 @@ bool IBuildActions.DirectoryExists(string dir)
112112
return ret;
113113
}
114114

115-
public string GetCurrentDirectory = "";
115+
public string GetCurrentDirectory { get; set; } = "";
116116

117117
string IBuildActions.GetCurrentDirectory()
118118
{
119119
return GetCurrentDirectory;
120120
}
121121

122-
public readonly IDictionary<string, string> EnumerateFiles = new Dictionary<string, string>();
122+
public IDictionary<string, string> EnumerateFiles { get; } = new Dictionary<string, string>();
123123

124124
IEnumerable<string> IBuildActions.EnumerateFiles(string dir)
125125
{
@@ -129,7 +129,7 @@ IEnumerable<string> IBuildActions.EnumerateFiles(string dir)
129129
return str.Split("\n").Select(p => PathCombine(dir, p));
130130
}
131131

132-
public readonly IDictionary<string, string> EnumerateDirectories = new Dictionary<string, string>();
132+
public IDictionary<string, string> EnumerateDirectories { get; } = new Dictionary<string, string>();
133133

134134
IEnumerable<string> IBuildActions.EnumerateDirectories(string dir)
135135
{
@@ -141,7 +141,7 @@ IEnumerable<string> IBuildActions.EnumerateDirectories(string dir)
141141
: str.Split("\n").Select(p => PathCombine(dir, p));
142142
}
143143

144-
public bool IsWindows;
144+
public bool IsWindows { get; set; }
145145

146146
bool IBuildActions.IsWindows() => IsWindows;
147147

@@ -164,7 +164,7 @@ void IBuildActions.WriteAllText(string filename, string contents)
164164
{
165165
}
166166

167-
public readonly IDictionary<string, XmlDocument> LoadXml = new Dictionary<string, XmlDocument>();
167+
public IDictionary<string, XmlDocument> LoadXml { get; } = new Dictionary<string, XmlDocument>();
168168

169169
XmlDocument IBuildActions.LoadXml(string filename)
170170
{

csharp/autobuilder/Semmle.Autobuild.Shared/BuildActions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,6 @@ private static async Task DownloadFileAsync(string address, string filename)
227227
public void DownloadFile(string address, string fileName) =>
228228
DownloadFileAsync(address, fileName).Wait();
229229

230-
public static readonly IBuildActions Instance = new SystemBuildActions();
230+
public static IBuildActions Instance { get; } = new SystemBuildActions();
231231
}
232232
}

csharp/autobuilder/Semmle.Autobuild.Shared/BuildScript.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,13 @@ public static BuildScript Bind(BuildScript s1, Func<IList<string>, int, BuildScr
232232
/// <summary>
233233
/// The empty build script that always returns exit code 0.
234234
/// </summary>
235-
public static readonly BuildScript Success = Create(actions => successCode);
235+
public static BuildScript Success { get; } = Create(actions => successCode);
236236

237237
private const int failureCode = 1;
238238
/// <summary>
239239
/// The empty build script that always returns exit code 1.
240240
/// </summary>
241-
public static readonly BuildScript Failure = Create(actions => failureCode);
241+
public static BuildScript Failure { get; } = Create(actions => failureCode);
242242

243243
private static bool Succeeded(int i) => i == successCode;
244244

csharp/extractor/Semmle.Extraction.CIL.Driver/ExtractorOptions.cs

+19-19
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Semmle.Extraction.CIL.Driver
1616
/// </summary>
1717
internal class AssemblyInfo
1818
{
19-
public override string ToString() => filename;
19+
public override string ToString() => Filename;
2020

2121
private static AssemblyName CreateAssemblyName(MetadataReader mdReader, StringHandle name, System.Version version, StringHandle culture)
2222
{
@@ -59,7 +59,7 @@ private static AssemblyName CreateAssemblyName(MetadataReader mdReader, Assembly
5959
/// </exception>
6060
public AssemblyInfo(string path)
6161
{
62-
filename = path;
62+
Filename = path;
6363

6464
// Attempt to open the file and see if it's a valid assembly.
6565
using var stream = File.OpenRead(path);
@@ -75,9 +75,9 @@ public AssemblyInfo(string path)
7575
throw new InvalidAssemblyException();
7676

7777
// Get our own assembly name
78-
name = CreateAssemblyName(mdReader, mdReader.GetAssemblyDefinition());
78+
Name = CreateAssemblyName(mdReader, mdReader.GetAssemblyDefinition());
7979

80-
references = mdReader.AssemblyReferences
80+
References = mdReader.AssemblyReferences
8181
.Select(r => mdReader.GetAssemblyReference(r))
8282
.Select(ar => CreateAssemblyName(mdReader, ar))
8383
.ToArray();
@@ -91,10 +91,10 @@ public AssemblyInfo(string path)
9191
}
9292
}
9393

94-
public readonly AssemblyName name;
95-
public readonly string filename;
96-
public bool extract;
97-
public readonly AssemblyName[] references;
94+
public AssemblyName Name { get; }
95+
public string Filename { get; }
96+
public bool Extract { get; set; }
97+
public AssemblyName[] References { get; }
9898
}
9999

100100
/// <summary>
@@ -125,19 +125,19 @@ public void AddFile(string assemblyPath, bool extractAll)
125125
{
126126
var info = new AssemblyInfo(assemblyPath)
127127
{
128-
extract = extractAll
128+
Extract = extractAll
129129
};
130-
if (!assembliesRead.ContainsKey(info.name))
131-
assembliesRead.Add(info.name, info);
130+
if (!assembliesRead.ContainsKey(info.Name))
131+
assembliesRead.Add(info.Name, info);
132132
}
133133
catch (InvalidAssemblyException)
134134
{ }
135135
}
136136
}
137137

138-
public IEnumerable<AssemblyInfo> AssembliesToExtract => assembliesRead.Values.Where(info => info.extract);
138+
public IEnumerable<AssemblyInfo> AssembliesToExtract => assembliesRead.Values.Where(info => info.Extract);
139139

140-
private IEnumerable<AssemblyName> AssembliesToReference => AssembliesToExtract.SelectMany(info => info.references);
140+
private IEnumerable<AssemblyName> AssembliesToReference => AssembliesToExtract.SelectMany(info => info.References);
141141

142142
public void ResolveReferences()
143143
{
@@ -148,22 +148,22 @@ public void ResolveReferences()
148148
var item = assembliesToReference.Pop();
149149
if (assembliesRead.TryGetValue(item, out var info))
150150
{
151-
if (!info.extract)
151+
if (!info.Extract)
152152
{
153-
info.extract = true;
154-
foreach (var reference in info.references)
153+
info.Extract = true;
154+
foreach (var reference in info.References)
155155
assembliesToReference.Push(reference);
156156
}
157157
}
158158
else
159159
{
160-
missingReferences.Add(item);
160+
MissingReferences.Add(item);
161161
}
162162
}
163163
}
164164

165165
private readonly HashSet<string> filesAnalyzed = new HashSet<string>();
166-
public readonly HashSet<AssemblyName> missingReferences = new HashSet<AssemblyName>();
166+
public HashSet<AssemblyName> MissingReferences {get;} = new HashSet<AssemblyName>();
167167
}
168168

169169
/// <summary>
@@ -235,7 +235,7 @@ private void AddFileOrDirectory(string path)
235235
/// extracted. This is not an error, it just means that the database is not
236236
/// as complete as it could be.
237237
/// </summary>
238-
public IEnumerable<AssemblyName> MissingReferences => assemblyList.missingReferences;
238+
public IEnumerable<AssemblyName> MissingReferences => assemblyList.MissingReferences;
239239

240240
private void ParseArgs(string[] args)
241241
{

csharp/extractor/Semmle.Extraction.CIL.Driver/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static void Main(string[] args)
4242
using var logger = new ConsoleLogger(options.Verbosity);
4343

4444
var actions = options.AssembliesToExtract
45-
.Select(asm => asm.filename)
45+
.Select(asm => asm.Filename)
4646
.Select<string, Action>(filename =>
4747
() => ExtractAssembly(layout, filename, logger, options.NoCache, options.PDB, options.TrapCompression))
4848
.ToArray();

csharp/extractor/Semmle.Extraction.CIL/Entities/Instruction.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ public enum Payload
3838
/// <summary>
3939
/// For each Payload, how many additional bytes in the bytestream need to be read.
4040
/// </summary>
41-
internal static readonly int[] payloadSizes = {
41+
private static readonly int[] payloadSizes = {
4242
0, 4, 4, 1, 4,
4343
4, 1, 1, 4, 1,
4444
2, 4, 8, 4, 8,
4545
4, -1, 4, 4, 4,
4646
4, 2, 1, 4, 2, 4 };
4747

4848
// Maps opcodes to payloads for each instruction.
49-
public static readonly Dictionary<ILOpCode, Payload> opPayload = new Dictionary<ILOpCode, Payload>()
49+
private static readonly Dictionary<ILOpCode, Payload> opPayload = new Dictionary<ILOpCode, Payload>()
5050
{
5151
{ ILOpCode.Nop, Payload.None },
5252
{ ILOpCode.Break, Payload.None },
@@ -268,10 +268,10 @@ public enum Payload
268268
{ ILOpCode.Readonly, Payload.None }
269269
};
270270

271-
public readonly DefinitionMethod Method;
272-
public readonly ILOpCode OpCode;
273-
public readonly int Offset;
274-
public readonly int Index;
271+
public DefinitionMethod Method { get; }
272+
public ILOpCode OpCode { get; }
273+
public int Offset { get; }
274+
public int Index { get; }
275275
private readonly int payloadValue;
276276
private readonly uint unsignedPayloadValue;
277277

csharp/extractor/Semmle.Extraction.CSharp.Standalone/Program.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ internal class Extraction
1212
{
1313
public Extraction(string directory)
1414
{
15-
this.directory = directory;
15+
Directory = directory;
1616
}
1717

18-
public readonly string directory;
19-
public readonly List<string> Sources = new List<string>();
18+
public string Directory { get; }
19+
public List<string> Sources { get; } = new List<string>();
2020
};
2121

2222
/// <summary>

csharp/extractor/Semmle.Extraction.CSharp/Entities/Accessor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public override void Populate(TextWriter trapFile)
8383

8484
private class AccessorFactory : ICachedEntityFactory<IMethodSymbol, Accessor>
8585
{
86-
public static readonly AccessorFactory Instance = new AccessorFactory();
86+
public static AccessorFactory Instance { get; } = new AccessorFactory();
8787

8888
public Accessor Create(Context cx, IMethodSymbol init) => new Accessor(cx, init);
8989
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/CommentBlock.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void BindTo(Label entity, CommentBinding binding)
3939

4040
private class CommentBlockFactory : ICachedEntityFactory<ICommentBlock, CommentBlock>
4141
{
42-
public static readonly CommentBlockFactory Instance = new CommentBlockFactory();
42+
public static CommentBlockFactory Instance { get; } = new CommentBlockFactory();
4343

4444
public CommentBlock Create(Context cx, ICommentBlock init) => new CommentBlock(cx, init);
4545
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/CommentLine.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private static CommentLine Create(Context cx, Microsoft.CodeAnalysis.Location lo
139139

140140
private class CommentLineFactory : ICachedEntityFactory<(Microsoft.CodeAnalysis.Location, CommentLineType, string, string), CommentLine>
141141
{
142-
public static readonly CommentLineFactory Instance = new CommentLineFactory();
142+
public static CommentLineFactory Instance { get; } = new CommentLineFactory();
143143

144144
public CommentLine Create(Context cx, (Microsoft.CodeAnalysis.Location, CommentLineType, string, string) init) =>
145145
new CommentLine(cx, init.Item1, init.Item2, init.Item3, init.Item4);

csharp/extractor/Semmle.Extraction.CSharp/Entities/Constructor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public override Microsoft.CodeAnalysis.Location ReportingLocation
147147

148148
private class ConstructorFactory : ICachedEntityFactory<IMethodSymbol, Constructor>
149149
{
150-
public static readonly ConstructorFactory Instance = new ConstructorFactory();
150+
public static ConstructorFactory Instance { get; } = new ConstructorFactory();
151151

152152
public Constructor Create(Context cx, IMethodSymbol init) => new Constructor(cx, init);
153153
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/Conversion.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public override Microsoft.CodeAnalysis.Location ReportingLocation
2828

2929
private class ConversionFactory : ICachedEntityFactory<IMethodSymbol, Conversion>
3030
{
31-
public static readonly ConversionFactory Instance = new ConversionFactory();
31+
public static ConversionFactory Instance { get; } = new ConversionFactory();
3232

3333
public Conversion Create(Context cx, IMethodSymbol init) => new Conversion(cx, init);
3434
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/Destructor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public override void Populate(TextWriter trapFile)
2828

2929
private class DestructorFactory : ICachedEntityFactory<IMethodSymbol, Destructor>
3030
{
31-
public static readonly DestructorFactory Instance = new DestructorFactory();
31+
public static DestructorFactory Instance { get; } = new DestructorFactory();
3232

3333
public Destructor Create(Context cx, IMethodSymbol init) => new Destructor(cx, init);
3434
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/Event.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public override void Populate(TextWriter trapFile)
6767

6868
private class EventFactory : ICachedEntityFactory<IEventSymbol, Event>
6969
{
70-
public static readonly EventFactory Instance = new EventFactory();
70+
public static EventFactory Instance { get; } = new EventFactory();
7171

7272
public Event Create(Context cx, IEventSymbol init) => new Event(cx, init);
7373
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/EventAccessor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public override void Populate(TextWriter trapFile)
5757

5858
private class EventAccessorFactory : ICachedEntityFactory<IMethodSymbol, EventAccessor>
5959
{
60-
public static readonly EventAccessorFactory Instance = new EventAccessorFactory();
60+
public static EventAccessorFactory Instance { get; } = new EventAccessorFactory();
6161

6262
public EventAccessor Create(Context cx, IMethodSymbol init) => new EventAccessor(cx, init);
6363
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expression.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public interface IExpressionParentEntity : IEntity
2020
internal class Expression : FreshEntity, IExpressionParentEntity
2121
{
2222
private readonly IExpressionInfo info;
23-
public readonly AnnotatedType Type;
24-
public readonly Extraction.Entities.Location Location;
25-
public readonly ExprKind Kind;
23+
public AnnotatedType Type { get; }
24+
public Extraction.Entities.Location Location { get; }
25+
public ExprKind Kind { get; }
2626

2727
internal Expression(IExpressionInfo info)
2828
: base(info.Context)
@@ -294,7 +294,7 @@ public static ExprKind AdjustKind(this Expression.CallType ct, ExprKind k)
294294
internal abstract class Expression<TExpressionSyntax> : Expression
295295
where TExpressionSyntax : ExpressionSyntax
296296
{
297-
public readonly TExpressionSyntax Syntax;
297+
public TExpressionSyntax Syntax { get; }
298298

299299
protected Expression(ExpressionNodeInfo info)
300300
: base(info)

csharp/extractor/Semmle.Extraction.CSharp/Entities/Field.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public override void WriteId(TextWriter trapFile)
131131

132132
private class FieldFactory : ICachedEntityFactory<IFieldSymbol, Field>
133133
{
134-
public static readonly FieldFactory Instance = new FieldFactory();
134+
public static FieldFactory Instance { get; } = new FieldFactory();
135135

136136
public Field Create(Context cx, IFieldSymbol init) => new Field(cx, init);
137137
}

0 commit comments

Comments
 (0)