Skip to content

Commit de224d0

Browse files
authored
Remove CAS attributes (#8008)
1 parent 685490e commit de224d0

File tree

48 files changed

+370
-1552
lines changed

Some content is hidden

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

48 files changed

+370
-1552
lines changed

snippets/csharp/System.Windows.Forms.Design.Behavior/Adorner/Enabled/DesignerDemoControl.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ private void InitializeComponent()
128128
//
129129
// This designer also offers a designer action for changing the
130130
// Anchor property.
131-
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
132131
public class DemoControlDesigner : ControlDesigner
133132
{
134133
// This adorner holds the glyphs that represent the Anchor property.
@@ -802,4 +801,4 @@ public override bool OnMouseDoubleClick(
802801
}
803802
#endregion
804803
}
805-
// </snippet1>
804+
// </snippet1>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6-windows</TargetFramework>
6+
<UseWindowsForms>true</UseWindowsForms>
7+
</PropertyGroup>
8+
9+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net6-windows</TargetFramework>
6+
<UseWindowsForms>true</UseWindowsForms>
7+
</PropertyGroup>
8+
9+
</Project>

snippets/csharp/System.Windows.Forms.Design/EventsTab/Overview/class1.cs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22
using System;
33
using System.ComponentModel;
44
using System.ComponentModel.Design;
5-
using System.Collections;
65
using System.Drawing;
76
using System.IO;
8-
using System.Reflection;
97
using System.Runtime.Serialization;
108
using System.Runtime.Serialization.Formatters.Binary;
11-
using System.Windows.Forms;
12-
using System.Windows.Forms.Design;
139

1410
namespace EventsTabExample
15-
{
11+
{
1612
// This component adds a TypeEventsTab to the Properties Window.
1713
[PropertyTabAttribute(typeof(TypeEventsTab), PropertyTabScope.Document)]
1814
public class TypeEventsTabComponent : Component
@@ -23,8 +19,6 @@ public TypeEventsTabComponent()
2319
}
2420

2521
// This example events tab lists events by their delegate type.
26-
[System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.InheritanceDemand, Name="FullTrust")]
27-
[System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
2822
public class TypeEventsTab : System.Windows.Forms.Design.EventsTab
2923
{
3024
[BrowsableAttribute(true)]
@@ -35,38 +29,38 @@ public class TypeEventsTab : System.Windows.Forms.Design.EventsTab
3529

3630
public TypeEventsTab(IServiceProvider sp) : base(sp)
3731
{
38-
this.sp = sp;
32+
this.sp = sp;
3933
}
40-
34+
4135
// Returns the properties of the specified component extended with a
4236
// CategoryAttribute reflecting the name of the type of the property.
43-
public override System.ComponentModel.PropertyDescriptorCollection
44-
GetProperties(ITypeDescriptorContext context, object component,
37+
public override System.ComponentModel.PropertyDescriptorCollection
38+
GetProperties(ITypeDescriptorContext context, object component,
4539
System.Attribute[] attributes)
46-
{
40+
{
4741
// Obtain an instance of the IEventBindingService.
4842
IEventBindingService eventPropertySvc = (IEventBindingService)
4943
sp.GetService(typeof(IEventBindingService));
5044

5145
// Return if an IEventBindingService could not be obtained.
52-
if (eventPropertySvc == null)
46+
if (eventPropertySvc == null)
5347
return new PropertyDescriptorCollection(null);
54-
48+
5549
// Obtain the events on the component.
56-
EventDescriptorCollection events =
57-
TypeDescriptor.GetEvents(component, attributes);
58-
50+
EventDescriptorCollection events =
51+
TypeDescriptor.GetEvents(component, attributes);
52+
5953
// Create an array of the events, where each event is assigned
6054
// a category matching its type.
6155
EventDescriptor[] newEvents = new EventDescriptor[events.Count];
62-
for(int i=0;i < events.Count;i++)
63-
newEvents[i] = TypeDescriptor.CreateEvent(events[i].ComponentType, events[i],
64-
new CategoryAttribute(events[i].EventType.FullName));
56+
for (int i = 0; i < events.Count; i++)
57+
newEvents[i] = TypeDescriptor.CreateEvent(events[i].ComponentType, events[i],
58+
new CategoryAttribute(events[i].EventType.FullName));
6559
events = new EventDescriptorCollection(newEvents);
6660

6761
// Return event properties for the event descriptors.
6862
return eventPropertySvc.GetEventProperties(events);
69-
}
63+
}
7064

7165
// Provides the name for the event property tab.
7266
public override string TabName
@@ -101,4 +95,4 @@ private Image DeserializeFromBase64Text(string text)
10195
}
10296
}
10397
}
104-
//</Snippet1>
98+
//</Snippet1>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net6-windows</TargetFramework>
6+
<UseWindowsForms>true</UseWindowsForms>
7+
</PropertyGroup>
8+
9+
</Project>

snippets/csharp/System.Windows.Forms.Design/IWindowsFormsEditorService/Overview/winformsedserviceeditordialogexample.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
//<Snippet1>
22
using System;
33
using System.ComponentModel;
4-
using System.ComponentModel.Design;
54
using System.Drawing;
65
using System.Drawing.Design;
76
using System.Windows.Forms;
87
using System.Windows.Forms.Design;
98

109
namespace IWindowsFormsEditorServiceExample
11-
{
10+
{
1211
// Example UITypeEditor that uses the IWindowsFormsEditorService
1312
// to display a Form.
14-
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
1513
public class TestDialogEditor : UITypeEditor
1614
{
1715
public TestDialogEditor()
@@ -25,18 +23,18 @@ public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext contex
2523
}
2624

2725
public override object EditValue(
28-
ITypeDescriptorContext context,
29-
IServiceProvider provider,
26+
ITypeDescriptorContext context,
27+
IServiceProvider provider,
3028
object value)
3129
{
3230
// Attempts to obtain an IWindowsFormsEditorService.
33-
IWindowsFormsEditorService edSvc =
31+
IWindowsFormsEditorService edSvc =
3432
(IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
3533
if (edSvc == null)
3634
{
3735
return null;
3836
}
39-
37+
4038
// Displays a StringInputDialog Form to get a user-adjustable
4139
// string value.
4240
using (StringInputDialog form = new StringInputDialog((string)value))
@@ -49,7 +47,7 @@ public override object EditValue(
4947

5048
// If OK was not pressed, return the original value
5149
return value;
52-
}
50+
}
5351
}
5452

5553
// Example Form for entering a string.
@@ -75,20 +73,20 @@ private void InitializeComponent()
7573
this.ok_button.Location = new System.Drawing.Point(180, 43);
7674
this.ok_button.Name = "ok_button";
7775
this.ok_button.TabIndex = 1;
78-
this.ok_button.Text = "OK";
79-
this.ok_button.DialogResult = System.Windows.Forms.DialogResult.OK;
76+
this.ok_button.Text = "OK";
77+
this.ok_button.DialogResult = System.Windows.Forms.DialogResult.OK;
8078
this.cancel_button.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
8179
this.cancel_button.Location = new System.Drawing.Point(260, 43);
8280
this.cancel_button.Name = "cancel_button";
8381
this.cancel_button.TabIndex = 2;
84-
this.cancel_button.Text = "Cancel";
82+
this.cancel_button.Text = "Cancel";
8583
this.cancel_button.DialogResult = System.Windows.Forms.DialogResult.Cancel;
8684
this.inputTextBox.Location = new System.Drawing.Point(6, 9);
8785
this.inputTextBox.Name = "inputTextBox";
8886
this.inputTextBox.Size = new System.Drawing.Size(327, 20);
8987
this.inputTextBox.TabIndex = 0;
90-
this.inputTextBox.Text = "";
91-
this.inputTextBox.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
88+
this.inputTextBox.Text = "";
89+
this.inputTextBox.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
9290
| System.Windows.Forms.AnchorStyles.Right);
9391
this.ClientSize = new System.Drawing.Size(342, 73);
9492
this.Controls.AddRange(new System.Windows.Forms.Control[] {
@@ -119,17 +117,17 @@ public string TestDialogString
119117
}
120118
}
121119
private string localDialogTestString;
122-
120+
123121
public WinFormsEdServiceDialogExampleControl()
124122
{
125-
localDialogTestString = "Test String";
123+
localDialogTestString = "Test String";
126124
this.Size = new Size(210, 74);
127125
this.BackColor = Color.Beige;
128126
}
129127

130128
protected override void OnPaint(PaintEventArgs e)
131129
{
132-
if( this.DesignMode )
130+
if (this.DesignMode)
133131
{
134132
e.Graphics.DrawString("Use the Properties window to show", new Font("Arial", 8), new SolidBrush(Color.Black), 5, 5);
135133
e.Graphics.DrawString("a Form dialog box, using the", new Font("Arial", 8), new SolidBrush(Color.Black), 5, 17);
@@ -144,4 +142,4 @@ protected override void OnPaint(PaintEventArgs e)
144142
}
145143
}
146144
}
147-
//</Snippet1>
145+
//</Snippet1>

snippets/csharp/System.Windows.Forms.Design/IWindowsFormsEditorService/Overview/winformsedserviceeditordropdownexample.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
11
//<Snippet1>
22
using System;
33
using System.ComponentModel;
4-
using System.ComponentModel.Design;
54
using System.Drawing;
65
using System.Drawing.Design;
76
using System.Windows.Forms;
87
using System.Windows.Forms.Design;
98

109
namespace IWindowsFormsEditorServiceExample
11-
{
10+
{
1211
// Example UITypeEditor that uses the IWindowsFormsEditorService to
1312
// display a drop-down control.
14-
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
1513
public class TestDropDownEditor : System.Drawing.Design.UITypeEditor
1614
{
1715
public TestDropDownEditor()
1816
{
1917
}
20-
18+
2119
public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
2220
{
2321
// Indicates that this editor can display a control-based
2422
// drop-down interface.
2523
return UITypeEditorEditStyle.DropDown;
2624
}
27-
25+
2826
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
2927
{
3028
// Attempts to obtain an IWindowsFormsEditorService.
3129
IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
32-
if( edSvc == null )
33-
return value;
34-
30+
if (edSvc == null)
31+
return value;
32+
3533
// Displays a drop-down control.
3634
StringInputControl inputControl = new StringInputControl((string)value, edSvc);
3735
edSvc.DropDownControl(inputControl);
@@ -62,7 +60,7 @@ private void InitializeComponent()
6260
this.ok_button = new System.Windows.Forms.Button();
6361
this.cancel_button = new System.Windows.Forms.Button();
6462
this.SuspendLayout();
65-
this.inputTextBox.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
63+
this.inputTextBox.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
6664
| System.Windows.Forms.AnchorStyles.Right);
6765
this.inputTextBox.Location = new System.Drawing.Point(6, 7);
6866
this.inputTextBox.Name = "inputTextBox";
@@ -77,7 +75,7 @@ private void InitializeComponent()
7775
this.ok_button.Text = "OK";
7876
this.ok_button.Click += new EventHandler(this.CloseControl);
7977
this.cancel_button.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
80-
this.cancel_button.DialogResult = System.Windows.Forms.DialogResult.Cancel;
78+
this.cancel_button.DialogResult = System.Windows.Forms.DialogResult.Cancel;
8179
this.cancel_button.Location = new System.Drawing.Point(267, 38);
8280
this.cancel_button.Name = "cancel_button";
8381
this.cancel_button.TabIndex = 2;
@@ -97,7 +95,7 @@ private void CloseControl(object sender, EventArgs e)
9795
edSvc.CloseDropDown();
9896
}
9997
}
100-
98+
10199
// Provides an example control that displays instructions in design mode,
102100
// with which the example UITypeEditor is associated.
103101
public class WinFormsEdServiceDropDownExampleControl : UserControl
@@ -110,11 +108,11 @@ public string TestDropDownString
110108
return localDropDownTestString;
111109
}
112110
set
113-
{
111+
{
114112
localDropDownTestString = value;
115113
}
116114
}
117-
115+
118116
private string localDropDownTestString;
119117

120118
public WinFormsEdServiceDropDownExampleControl()
@@ -126,7 +124,7 @@ public WinFormsEdServiceDropDownExampleControl()
126124

127125
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
128126
{
129-
if( this.DesignMode )
127+
if (this.DesignMode)
130128
{
131129
e.Graphics.DrawString("Use the Properties window to show", new Font("Arial", 8), new SolidBrush(Color.Black), 5, 5);
132130
e.Graphics.DrawString("a drop-down control, using the", new Font("Arial", 8), new SolidBrush(Color.Black), 5, 17);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6-windows</TargetFramework>
6+
<UseWindowsForms>true</UseWindowsForms>
7+
</PropertyGroup>
8+
9+
</Project>

snippets/csharp/System.Windows.Forms/Application/AddMessageFilter/source.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Windows.Forms;
3-
using System.Security.Permissions;
43

54
public class Form1 : Form
65
{
@@ -14,7 +13,6 @@ public static void Main(string[] args)
1413

1514
// <Snippet1>
1615
// Creates a message filter.
17-
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
1816
public class TestMessageFilter : IMessageFilter
1917
{
2018
public bool PreFilterMessage(ref Message m)
@@ -29,4 +27,4 @@ public bool PreFilterMessage(ref Message m)
2927
}
3028
}
3129

32-
// </Snippet1>
30+
// </Snippet1>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6-windows</TargetFramework>
6+
<UseWindowsForms>true</UseWindowsForms>
7+
</PropertyGroup>
8+
9+
</Project>

0 commit comments

Comments
 (0)