Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit df58256

Browse files
committed
Some more code analysis fixes
1 parent da286ca commit df58256

File tree

7 files changed

+33
-10
lines changed

7 files changed

+33
-10
lines changed

common/codeanalysis-debug.ruleset

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@
106106

107107
<!-- we're returning arrays from properties -->
108108
<Rule Id="CA1819" Action="None" />
109+
110+
<!-- Unity does its own serialization and doesn't need special serializable type constructors -->
111+
<Rule Id="CA2229" Action="None" />
112+
<Rule Id="CA2240" Action="None" />
113+
109114
</Rules>
110115
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp.Features" RuleNamespace="Microsoft.CodeAnalysis.CSharp.Features">
111116
<Rule Id="IDE0001" Action="None" />

common/codeanalysis-release.ruleset

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@
9595

9696
<!-- we're returning arrays from properties -->
9797
<Rule Id="CA1819" Action="None" />
98+
99+
<!-- Unity does its own serialization and doesn't need special serializable type constructors -->
100+
<Rule Id="CA2229" Action="None" />
101+
<Rule Id="CA2240" Action="None" />
98102
</Rules>
99103
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp.Features" RuleNamespace="Microsoft.CodeAnalysis.CSharp.Features">
100104
<Rule Id="IDE0001" Action="None" />

src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationCache.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,26 @@
22
using System.Collections.Generic;
33
using System.Globalization;
44
using System.Linq;
5+
using System.Runtime.Serialization;
56
using UnityEditor;
67
using UnityEngine;
78
using Application = UnityEngine.Application;
89

910
namespace GitHub.Unity
1011
{
12+
[Serializable]
13+
public class SerializationException : Exception
14+
{
15+
public SerializationException() : base()
16+
{ }
17+
public SerializationException(string message) : base(message)
18+
{ }
19+
public SerializationException(string message, Exception innerException) : base(message, innerException)
20+
{ }
21+
protected SerializationException(SerializationInfo info, StreamingContext context) : base(info, context)
22+
{ }
23+
}
24+
1125
sealed class ApplicationCache : ScriptObjectSingleton<ApplicationCache>
1226
{
1327
[SerializeField] private bool firstRun = true;
@@ -373,7 +387,7 @@ public void OnAfterDeserialize()
373387

374388
if (keys.Length != subKeys.Length || subKeys.Length != subKeyValues.Length)
375389
{
376-
throw new Exception("Deserialization length mismatch");
390+
throw new SerializationException("Deserialization length mismatch");
377391
}
378392

379393
for (var remoteIndex = 0; remoteIndex < keys.Length; remoteIndex++)
@@ -385,7 +399,7 @@ public void OnAfterDeserialize()
385399

386400
if (subKeyContainer.Values.Length != subKeyValueContainer.Values.Length)
387401
{
388-
throw new Exception("Deserialization length mismatch");
402+
throw new SerializationException("Deserialization length mismatch");
389403
}
390404

391405
var branchesDictionary = new Dictionary<string, ConfigBranch>();

src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ protected override void Dispose(bool disposing)
8686
{
8787
if (disposing)
8888
{
89-
base.Dispose(disposing);
9089
if (!disposed)
9190
{
9291
disposed = true;
9392
}
9493
}
94+
base.Dispose(disposing);
9595
}
9696

9797
public override IProcessEnvironment GitEnvironment { get { return Platform.GitEnvironment; } }

src/UnityExtension/Assets/Editor/GitHub.Unity/ScriptObjectSingleton.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace GitHub.Unity
77
{
88
[AttributeUsage(AttributeTargets.Class)]
9-
class LocationAttribute : Attribute
9+
sealed class LocationAttribute : Attribute
1010
{
1111
public enum Location { PreferencesFolder, ProjectFolder, LibraryFolder, UserFolder }
1212
public string filepath { get; set; }
@@ -102,11 +102,11 @@ protected virtual void Save(bool saveAsText)
102102
return;
103103
}
104104

105-
NPath filePath = GetFilePath();
106-
if (filePath != null)
105+
NPath locationFilePath = GetFilePath();
106+
if (locationFilePath != null)
107107
{
108-
filePath.Parent.EnsureDirectoryExists();
109-
InternalEditorUtility.SaveToSerializedFileAndForget(new[] { instance }, filePath, saveAsText);
108+
locationFilePath.Parent.EnsureDirectoryExists();
109+
InternalEditorUtility.SaveToSerializedFileAndForget(new[] { instance }, locationFilePath, saveAsText);
110110
}
111111
}
112112

src/UnityExtension/Assets/Editor/GitHub.Unity/SerializableDictionary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void OnAfterDeserialize()
3131

3232
if (keys.Count != values.Count)
3333
{
34-
throw new Exception(
34+
throw new SerializationException(
3535
string.Format("there are {0} keys and {1} values after deserialization. Make sure that both key and value types are serializable.",
3636
keys.Count, values.Count));
3737
}

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ private Subview ToView(SubTab tab)
453453
case SubTab.Settings:
454454
return settingsView;
455455
default:
456-
throw new ArgumentOutOfRangeException();
456+
throw new ArgumentOutOfRangeException("tab");
457457
}
458458
}
459459

0 commit comments

Comments
 (0)