From a2aef7cf7f2c5d09e2831a806a6074e2f4ab67c9 Mon Sep 17 00:00:00 2001
From: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
Date: Thu, 8 Jul 2021 16:56:29 -0700
Subject: [PATCH 1/4] fix build warnings
---
.../code-analysis/quality-rules/ca1060.md | 4 ++--
.../snippets/csharp/all-rules/.editorconfig | 18 ++++++++++++++++++
.../snippets/csharp/all-rules/all-rules.csproj | 8 ++++++++
.../snippets/csharp/all-rules/ca1060.cs | 6 ------
.../snippets/csharp/all-rules/ca1802.cs | 9 ++++++++-
.../snippets/csharp/all-rules/ca1810.cs | 13 ++++++++++++-
.../snippets/csharp/all-rules/ca2109.cs | 2 ++
.../snippets/csharp/all-rules/ca2229.cs | 2 --
.../snippets/csharp/all-rules/ca2237.cs | 2 --
.../snippets/csharp/all-rules/ca2242.cs | 2 +-
10 files changed, 51 insertions(+), 15 deletions(-)
create mode 100644 docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/.editorconfig
diff --git a/docs/fundamentals/code-analysis/quality-rules/ca1060.md b/docs/fundamentals/code-analysis/quality-rules/ca1060.md
index c45bfa68ddce8..8ea00981d3e64 100644
--- a/docs/fundamentals/code-analysis/quality-rules/ca1060.md
+++ b/docs/fundamentals/code-analysis/quality-rules/ca1060.md
@@ -73,7 +73,7 @@ The following example shows an **Interaction.Beep** method that wraps the **Mess
## SafeNativeMethods example
-P/Invoke methods that can be safely exposed to any application and that do not have any side effects should be put in a class that is named **SafeNativeMethods**. You do not have to demand permissions and you do not have to pay much attention to where they are called from.
+P/Invoke methods that can be safely exposed to any application and that do not have any side effects should be put in a class that is named **SafeNativeMethods**. You do not have to pay much attention to where they are called from.
The following example shows an **Environment.TickCount** property that wraps the **GetTickCount** function from kernel32.dll.
@@ -83,7 +83,7 @@ The following example shows an **Environment.TickCount** property that wraps the
## UnsafeNativeMethods example
-P/Invoke methods that cannot be safely called and that could cause side effects should be put in a class that is named **UnsafeNativeMethods**. These methods should be rigorously checked to make sure that they are not exposed to the user unintentionally. Alternatively, the methods should have another permission that is demanded instead of **UnmanagedCode** when they use them.
+P/Invoke methods that cannot be safely called and that could cause side effects should be put in a class that is named **UnsafeNativeMethods**. These methods should be rigorously checked to make sure that they are not exposed to the user unintentionally.
The following example shows a **Cursor.Hide** method that wraps the **ShowCursor** function from user32.dll.
diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/.editorconfig b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/.editorconfig
new file mode 100644
index 0000000000000..fdc0f4e49bb00
--- /dev/null
+++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/.editorconfig
@@ -0,0 +1,18 @@
+# To learn more about .editorconfig see https://aka.ms/editorconfigdocs
+root = true
+
+# All files
+[*]
+indent_style = space
+
+# CS0659: Type overrides Object.Equals(object o) but does not override Object.GetHashCode()
+dotnet_diagnostic.CS0659.severity = suggestion
+
+# CAXXXX analyzers
+dotnet_diagnostic.CA1822.severity = none
+
+# CS0108: Member hides inherited member; missing new keyword
+dotnet_diagnostic.CS0108.severity = suggestion
+
+[*.xml]
+indent_size = 2
diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/all-rules.csproj b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/all-rules.csproj
index e0e3dce6a5497..c020a98d57b07 100644
--- a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/all-rules.csproj
+++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/all-rules.csproj
@@ -11,4 +11,12 @@
+
+
+
+
+
+
+
+
diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1060.cs b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1060.cs
index bb0e340b29b58..d4018a7e60e34 100644
--- a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1060.cs
+++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1060.cs
@@ -62,14 +62,8 @@ internal static class SafeNativeMethods
//
public static class Cursor
{
- // Callers do not require UnmanagedCode permission, however,
- // they do require UIPermissionWindow.AllWindows.
public static void Hide()
{
- // Need to demand an appropriate permission
- // in place of UnmanagedCode permission as
- // ShowCursor is not considered a safe method.
- new UIPermission(UIPermissionWindow.AllWindows).Demand();
UnsafeNativeMethods.ShowCursor(false);
}
}
diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1802.cs b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1802.cs
index ca6ee7f279f6c..ec498926ac995 100644
--- a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1802.cs
+++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1802.cs
@@ -1,4 +1,6 @@
-namespace ca1802
+using System;
+
+namespace ca1802
{
//
// This class violates the rule.
@@ -7,6 +9,11 @@ public class UseReadOnly
static readonly int x = 3;
static readonly double y = x + 2.1;
static readonly string s = "readonly";
+
+ public void Print()
+ {
+ Console.WriteLine(s);
+ }
}
// This class satisfies the rule.
diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1810.cs b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1810.cs
index d61e6935daf47..13b7b0c9abd94 100644
--- a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1810.cs
+++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1810.cs
@@ -1,4 +1,5 @@
-using System.Reflection;
+using System;
+using System.Reflection;
using System.Resources;
namespace ca1810
@@ -16,6 +17,11 @@ static StaticConstructor()
new ResourceManager("strings", Assembly.GetExecutingAssembly());
resourceString = stringManager.GetString("string");
}
+
+ public void Print()
+ {
+ Console.WriteLine(someInteger);
+ }
}
public class NoStaticConstructor
@@ -29,6 +35,11 @@ static string InitializeResourceString()
new ResourceManager("strings", Assembly.GetExecutingAssembly());
return stringManager.GetString("string");
}
+
+ public void Print()
+ {
+ Console.WriteLine(someInteger);
+ }
}
//
}
diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2109.cs b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2109.cs
index dee2689166e87..8d174b21a76f4 100644
--- a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2109.cs
+++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2109.cs
@@ -3,6 +3,7 @@
namespace ca2109
{
+#pragma warning disable SYSLIB0003
//
public class HandleEvents
{
@@ -21,4 +22,5 @@ public static void SomeActionHappened(Object sender, EventArgs e)
}
}
//
+#pragma warning restore SYSLIB0003
}
diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2229.cs b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2229.cs
index 5a6fe593f20f5..e954566dfba7c 100644
--- a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2229.cs
+++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2229.cs
@@ -26,8 +26,6 @@ protected SerializationConstructorsRequired(
}
// The following method serializes the instance.
- [SecurityPermission(SecurityAction.LinkDemand,
- Flags = SecurityPermissionFlag.SerializationFormatter)]
void ISerializable.GetObjectData(SerializationInfo info,
StreamingContext context)
{
diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2237.cs b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2237.cs
index c8c1db5854b18..4d22fa85f34f0 100644
--- a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2237.cs
+++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2237.cs
@@ -20,8 +20,6 @@ protected BaseType(
baseValue = info.GetInt32("baseValue");
}
- [SecurityPermissionAttribute(SecurityAction.Demand,
- SerializationFormatter = true)]
public virtual void GetObjectData(
SerializationInfo info, StreamingContext context)
{
diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2242.cs b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2242.cs
index 20d549ac6295f..70480e0727350 100644
--- a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2242.cs
+++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2242.cs
@@ -5,7 +5,7 @@ namespace ca2242
//
class NaNTests
{
- static double zero;
+ static double zero = 0;
static void Main()
{
From f68f629131900851c03ad4727ec42e6bb5a62cc3 Mon Sep 17 00:00:00 2001
From: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
Date: Thu, 8 Jul 2021 17:01:33 -0700
Subject: [PATCH 2/4] fix project file
---
.../snippets/csharp/all-rules/all-rules.csproj | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/all-rules.csproj b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/all-rules.csproj
index c020a98d57b07..981d7b32c5b18 100644
--- a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/all-rules.csproj
+++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/all-rules.csproj
@@ -12,11 +12,7 @@
-
-
-
-
-
+
From d61f6e8553dbc131353e0a8fdfa0444a4be7ca6d Mon Sep 17 00:00:00 2001
From: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
Date: Fri, 9 Jul 2021 07:57:46 -0700
Subject: [PATCH 3/4] Remove root=true in editorconfig
---
.../snippets/csharp/all-rules/.editorconfig | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/.editorconfig b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/.editorconfig
index fdc0f4e49bb00..d434f146418db 100644
--- a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/.editorconfig
+++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/.editorconfig
@@ -1,18 +1,8 @@
-# To learn more about .editorconfig see https://aka.ms/editorconfigdocs
-root = true
-
-# All files
-[*]
-indent_style = space
-
# CS0659: Type overrides Object.Equals(object o) but does not override Object.GetHashCode()
dotnet_diagnostic.CS0659.severity = suggestion
-# CAXXXX analyzers
-dotnet_diagnostic.CA1822.severity = none
-
# CS0108: Member hides inherited member; missing new keyword
dotnet_diagnostic.CS0108.severity = suggestion
-[*.xml]
-indent_size = 2
+# CA1822: Mark members as static
+dotnet_diagnostic.CA1822.severity = none
From fa534f9cc75ac26be4f88816748d72c0ac41fa17 Mon Sep 17 00:00:00 2001
From: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
Date: Fri, 9 Jul 2021 16:21:32 -0700
Subject: [PATCH 4/4] Add all files glob
---
.../quality-rules/snippets/csharp/all-rules/.editorconfig | 3 +++
1 file changed, 3 insertions(+)
diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/.editorconfig b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/.editorconfig
index d434f146418db..8b9bc7fe4a78a 100644
--- a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/.editorconfig
+++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/.editorconfig
@@ -1,3 +1,6 @@
+# All files
+[*]
+
# CS0659: Type overrides Object.Equals(object o) but does not override Object.GetHashCode()
dotnet_diagnostic.CS0659.severity = suggestion