Skip to content

Commit c407371

Browse files
committed
Fix analyzer warnings
1 parent 4193f6b commit c407371

23 files changed

+134
-11
lines changed

Directory.Build.props

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Project>
22

33
<PropertyGroup>
4+
<EnableNETAnalyzers>true</EnableNETAnalyzers>
45
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
56
<UseArtifactsOutput>true</UseArtifactsOutput>
67
<DefineConstants Condition=" '$(ExtraDefine)' != '' ">$(DefineConstants);$(ExtraDefine)</DefineConstants>

LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ private HttpWebResponse GetResponseWithRedirects()
313313
}
314314

315315
// rethrow if it's not 401
316-
throw ex;
316+
throw;
317317
}
318318

319319
if (response.StatusCode == HttpStatusCode.Moved || response.StatusCode == HttpStatusCode.Redirect)

LibGit2Sharp/AmbiguousSpecificationException.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
using LibGit2Sharp.Core;
21
using System;
2+
#if NETFRAMEWORK
33
using System.Runtime.Serialization;
4+
#endif
5+
using LibGit2Sharp.Core;
46

57
namespace LibGit2Sharp
68
{
79
/// <summary>
810
/// The exception that is thrown when the provided specification cannot uniquely identify a reference, an object or a path.
911
/// </summary>
12+
#if NETFRAMEWORK
1013
[Serializable]
14+
#endif
1115
public class AmbiguousSpecificationException : NativeException
1216
{
1317
/// <summary>
@@ -30,7 +34,7 @@ public AmbiguousSpecificationException(string message)
3034
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
3135
/// <param name="args">An object array that contains zero or more objects to format.</param>
3236
public AmbiguousSpecificationException(string format, params object[] args)
33-
: base(String.Format(format, args))
37+
: base(string.Format(format, args))
3438
{
3539
}
3640

@@ -43,6 +47,7 @@ public AmbiguousSpecificationException(string message, Exception innerException)
4347
: base(message, innerException)
4448
{ }
4549

50+
#if NETFRAMEWORK
4651
/// <summary>
4752
/// Initializes a new instance of the <see cref="AmbiguousSpecificationException"/> class with a serialized data.
4853
/// </summary>
@@ -51,6 +56,7 @@ public AmbiguousSpecificationException(string message, Exception innerException)
5156
protected AmbiguousSpecificationException(SerializationInfo info, StreamingContext context)
5257
: base(info, context)
5358
{ }
59+
#endif
5460

5561
internal override GitErrorCode ErrorCode
5662
{

LibGit2Sharp/BareRepositoryException.cs

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
#if NETFRAMEWORK
23
using System.Runtime.Serialization;
4+
#endif
35
using LibGit2Sharp.Core;
46

57
namespace LibGit2Sharp
@@ -8,7 +10,9 @@ namespace LibGit2Sharp
810
/// The exception that is thrown when an operation which requires a
911
/// working directory is performed against a bare repository.
1012
/// </summary>
13+
#if NETFRAMEWORK
1114
[Serializable]
15+
#endif
1216
public class BareRepositoryException : NativeException
1317
{
1418
/// <summary>
@@ -43,6 +47,7 @@ public BareRepositoryException(string message, Exception innerException)
4347
: base(message, innerException)
4448
{ }
4549

50+
#if NETFRAMEWORK
4651
/// <summary>
4752
/// Initializes a new instance of the <see cref="LibGit2Sharp.BareRepositoryException"/> class with a serialized data.
4853
/// </summary>
@@ -51,6 +56,7 @@ public BareRepositoryException(string message, Exception innerException)
5156
protected BareRepositoryException(SerializationInfo info, StreamingContext context)
5257
: base(info, context)
5358
{ }
59+
#endif
5460

5561
internal BareRepositoryException(string message, GitErrorCategory category)
5662
: base(message, category)

LibGit2Sharp/CheckoutConflictException.cs

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
#if NETFRAMEWORK
23
using System.Runtime.Serialization;
4+
#endif
35
using LibGit2Sharp.Core;
46

57
namespace LibGit2Sharp
@@ -9,7 +11,9 @@ namespace LibGit2Sharp
911
/// because of a conflicting change staged in the index, or unstaged
1012
/// in the working directory.
1113
/// </summary>
14+
#if NETFRAMEWORK
1215
[Serializable]
16+
#endif
1317
public class CheckoutConflictException : NativeException
1418
{
1519
/// <summary>
@@ -44,6 +48,7 @@ public CheckoutConflictException(string message, Exception innerException)
4448
: base(message, innerException)
4549
{ }
4650

51+
#if NETFRAMEWORK
4752
/// <summary>
4853
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class with a serialized data.
4954
/// </summary>
@@ -52,6 +57,7 @@ public CheckoutConflictException(string message, Exception innerException)
5257
protected CheckoutConflictException(SerializationInfo info, StreamingContext context)
5358
: base(info, context)
5459
{ }
60+
#endif
5561

5662
internal CheckoutConflictException(string message, GitErrorCategory category)
5763
: base(message, category)

LibGit2Sharp/EmptyCommitException.cs

+6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
using System;
2+
#if NETFRAMEWORK
23
using System.Runtime.Serialization;
4+
#endif
35

46
namespace LibGit2Sharp
57
{
68
/// <summary>
79
/// The exception that is thrown when a commit would create an "empty"
810
/// commit that is treesame to its parent without an explicit override.
911
/// </summary>
12+
#if NETFRAMEWORK
1013
[Serializable]
14+
#endif
1115
public class EmptyCommitException : LibGit2SharpException
1216
{
1317
/// <summary>
@@ -42,6 +46,7 @@ public EmptyCommitException(string message, Exception innerException)
4246
: base(message, innerException)
4347
{ }
4448

49+
#if NETFRAMEWORK
4550
/// <summary>
4651
/// Initializes a new instance of the <see cref="EmptyCommitException"/> class with a serialized data.
4752
/// </summary>
@@ -50,5 +55,6 @@ public EmptyCommitException(string message, Exception innerException)
5055
protected EmptyCommitException(SerializationInfo info, StreamingContext context)
5156
: base(info, context)
5257
{ }
58+
#endif
5359
}
5460
}

LibGit2Sharp/EntryExistsException.cs

+7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
using System;
2+
#if NETFRAMEWORK
23
using System.Runtime.Serialization;
4+
#endif
5+
36
using LibGit2Sharp.Core;
47

58
namespace LibGit2Sharp
69
{
710
/// <summary>
811
/// The exception that is thrown attempting to create a resource that already exists.
912
/// </summary>
13+
#if NETFRAMEWORK
1014
[Serializable]
15+
#endif
1116
public class EntryExistsException : LibGit2SharpException
1217
{
1318
/// <summary>
@@ -42,6 +47,7 @@ public EntryExistsException(string message, Exception innerException)
4247
: base(message, innerException)
4348
{ }
4449

50+
#if NETFRAMEWORK
4551
/// <summary>
4652
/// Initializes a new instance of the <see cref="LibGit2Sharp.EntryExistsException"/> class with a serialized data.
4753
/// </summary>
@@ -50,6 +56,7 @@ public EntryExistsException(string message, Exception innerException)
5056
protected EntryExistsException(SerializationInfo info, StreamingContext context)
5157
: base(info, context)
5258
{ }
59+
#endif
5360

5461
internal EntryExistsException(string message, GitErrorCode code, GitErrorCategory category)
5562
: base(message, code, category)

LibGit2Sharp/InvalidSpecificationException.cs

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
#if NETFRAMEWORK
23
using System.Runtime.Serialization;
4+
#endif
35
using LibGit2Sharp.Core;
46

57
namespace LibGit2Sharp
@@ -10,7 +12,9 @@ namespace LibGit2Sharp
1012
/// if the spec refers to an object of an incorrect type (e.g. asking to
1113
/// create a branch from a blob, or peeling a blob to a commit).
1214
/// </summary>
15+
#if NETFRAMEWORK
1316
[Serializable]
17+
#endif
1418
public class InvalidSpecificationException : NativeException
1519
{
1620
/// <summary>
@@ -45,6 +49,7 @@ public InvalidSpecificationException(string message, Exception innerException)
4549
: base(message, innerException)
4650
{ }
4751

52+
#if NETFRAMEWORK
4853
/// <summary>
4954
/// Initializes a new instance of the <see cref="InvalidSpecificationException"/> class with a serialized data.
5055
/// </summary>
@@ -53,6 +58,7 @@ public InvalidSpecificationException(string message, Exception innerException)
5358
protected InvalidSpecificationException(SerializationInfo info, StreamingContext context)
5459
: base(info, context)
5560
{ }
61+
#endif
5662

5763
internal InvalidSpecificationException(string message, GitErrorCategory category)
5864
: base(message, category)

LibGit2Sharp/LibGit2SharpException.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
using System;
22
using System.Globalization;
3+
#if NETFRAMEWORK
34
using System.Runtime.Serialization;
4-
using LibGit2Sharp.Core;
5+
#endif
56

67
namespace LibGit2Sharp
78
{
89
/// <summary>
910
/// The exception that is thrown when an error occurs during application execution.
1011
/// </summary>
12+
#if NETFRAMEWORK
1113
[Serializable]
14+
#endif
1215
public class LibGit2SharpException : Exception
1316
{
1417
/// <summary>
@@ -40,10 +43,11 @@ public LibGit2SharpException(string message, Exception innerException)
4043
/// <param name="format">A composite format string for use in <see cref="String.Format(IFormatProvider, string, object[])"/>.</param>
4144
/// <param name="args">An object array that contains zero or more objects to format.</param>
4245
public LibGit2SharpException(string format, params object[] args)
43-
: base(String.Format(CultureInfo.InvariantCulture, format, args))
46+
: base(string.Format(CultureInfo.InvariantCulture, format, args))
4447
{
4548
}
4649

50+
#if NETFRAMEWORK
4751
/// <summary>
4852
/// Initializes a new instance of the <see cref="LibGit2SharpException"/> class with a serialized data.
4953
/// </summary>
@@ -52,5 +56,6 @@ public LibGit2SharpException(string format, params object[] args)
5256
protected LibGit2SharpException(SerializationInfo info, StreamingContext context)
5357
: base(info, context)
5458
{ }
59+
#endif
5560
}
5661
}

LibGit2Sharp/LockedFileException.cs

+6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
using System;
2+
#if NETFRAMEWORK
23
using System.Runtime.Serialization;
4+
#endif
35
using LibGit2Sharp.Core;
46

57
namespace LibGit2Sharp
68
{
79
/// <summary>
810
/// The exception that is thrown attempting to open a locked file.
911
/// </summary>
12+
#if NETFRAMEWORK
1013
[Serializable]
14+
#endif
1115
public class LockedFileException : NativeException
1216
{
1317
/// <summary>
@@ -42,6 +46,7 @@ public LockedFileException(string message, Exception innerException)
4246
: base(message, innerException)
4347
{ }
4448

49+
#if NETFRAMEWORK
4550
/// <summary>
4651
/// Initializes a new instance of the <see cref="LibGit2Sharp.LockedFileException"/> class with a serialized data.
4752
/// </summary>
@@ -50,6 +55,7 @@ public LockedFileException(string message, Exception innerException)
5055
protected LockedFileException(SerializationInfo info, StreamingContext context)
5156
: base(info, context)
5257
{ }
58+
#endif
5359

5460
internal LockedFileException(string message, GitErrorCategory category)
5561
: base(message, category)

LibGit2Sharp/MergeFetchHeadNotFoundException.cs

+6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
using System;
2+
#if NETFRAMEWORK
23
using System.Runtime.Serialization;
4+
#endif
35

46
namespace LibGit2Sharp
57
{
68
/// <summary>
79
/// The exception that is thrown when the ref to merge with was as part of a pull operation not fetched.
810
/// </summary>
11+
#if NETFRAMEWORK
912
[Serializable]
13+
#endif
1014
public class MergeFetchHeadNotFoundException : NotFoundException
1115
{
1216
/// <summary>
@@ -41,6 +45,7 @@ public MergeFetchHeadNotFoundException(string message, Exception innerException)
4145
: base(message, innerException)
4246
{ }
4347

48+
#if NETFRAMEWORK
4449
/// <summary>
4550
/// Initializes a new instance of the <see cref="MergeFetchHeadNotFoundException"/> class with a serialized data.
4651
/// </summary>
@@ -49,5 +54,6 @@ public MergeFetchHeadNotFoundException(string message, Exception innerException)
4954
protected MergeFetchHeadNotFoundException(SerializationInfo info, StreamingContext context)
5055
: base(info, context)
5156
{ }
57+
#endif
5258
}
5359
}

LibGit2Sharp/NameConflictException.cs

+6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
using System;
2+
#if NETFRAMEWORK
23
using System.Runtime.Serialization;
4+
#endif
35
using LibGit2Sharp.Core;
46

57
namespace LibGit2Sharp
68
{
79
/// <summary>
810
/// The exception that is thrown when a reference, a remote, a submodule... with the same name already exists in the repository
911
/// </summary>
12+
#if NETFRAMEWORK
1013
[Serializable]
14+
#endif
1115
public class NameConflictException : NativeException
1216
{
1317
/// <summary>
@@ -42,6 +46,7 @@ public NameConflictException(string message, Exception innerException)
4246
: base(message, innerException)
4347
{ }
4448

49+
#if NETFRAMEWORK
4550
/// <summary>
4651
/// Initializes a new instance of the <see cref="NameConflictException"/> class with a serialized data.
4752
/// </summary>
@@ -50,6 +55,7 @@ public NameConflictException(string message, Exception innerException)
5055
protected NameConflictException(SerializationInfo info, StreamingContext context)
5156
: base(info, context)
5257
{ }
58+
#endif
5359

5460
internal NameConflictException(string message, GitErrorCategory category)
5561
: base(message, category)

0 commit comments

Comments
 (0)