Skip to content

Commit 23c6b65

Browse files
Sync MilCodeGen to generated code (#10430)
* Sync MilCodeGen to generated code Contributes to #10429 * PR feedback
1 parent de23c2f commit 23c6b65

27 files changed

+112
-674
lines changed

src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/AnimatableTemplate.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,8 @@ public override void Go(ResourceModel resourceModel)
6565
csFile.WriteBlock(
6666
[[inline]]
6767
[[Helpers.ManagedStyle.WriteFileHeader(filename, @"wpf\src\Graphics\codegen\mcg\generators\AnimatableTemplate.cs")]]
68-
69-
using MS.Internal;
70-
using MS.Utility;
71-
using System;
72-
using System.Collections;
73-
using System.Collections.Generic;
74-
using System.Diagnostics;
75-
using System.Security;
76-
using System.Security.Permissions;
77-
using System.Windows.Threading;
78-
using System.Windows.Media.Animation;
79-
using System.Windows.Media.Composition;
8068

81-
using SR = MS.Internal.PresentationCore.SR;
69+
using System.Windows.Media.Animation;
8270

8371
namespace [[instance.Namespace]]
8472
{

src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/AnimationBaseTemplate.cs

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -69,53 +69,16 @@ public override void Go(ResourceModel resourceModel)
6969

7070
string fullPath = Path.Combine(resourceModel.OutputDirectory, path);
7171

72-
string moduleReference;
73-
string sridReference =
74-
[[inline]]
75-
using SR=System.Windows.SR;
76-
[[/inline]];
77-
78-
// Duplicate AnimatedTypeHelpers class across Core/Framework causes name conflicts,
79-
// requiring that they be split across two namespaces.
80-
switch (instance.ModuleName)
81-
{
82-
case @"PresentationCore":
83-
moduleReference = "using MS.Internal.PresentationCore;";
84-
sridReference =
85-
[[inline]]
86-
using SR=MS.Internal.PresentationCore.SR;
87-
[[/inline]];
88-
break;
89-
case "PresentationFramework":
90-
moduleReference = "using MS.Internal.PresentationFramework;";
91-
break;
92-
default:
93-
moduleReference = "";
94-
break;
95-
}
96-
97-
9872
using (FileCodeSink csFile = new FileCodeSink(fullPath, fileName, true /* Create dir if necessary */))
9973
{
10074
csFile.WriteBlock(
10175
[[inline]]
10276
[[Helpers.ManagedStyle.WriteFileHeader(fileName)]]
10377

104-
using MS.Internal;
105-
106-
using System;
107-
using System.Collections;
108-
using System.ComponentModel;
109-
using System.Diagnostics;
110-
using System.Windows.Media.Animation;
11178
using System.Windows.Media.Media3D;
112-
113-
[[moduleReference]]
114-
115-
[[sridReference]]
11679

11780
namespace System.Windows.Media.Animation
118-
{
81+
{
11982
/// <summary>
12083
///
12184
/// </summary>
@@ -293,14 +256,8 @@ private string WriteIAnimationGetCurrentValueBody(AnimationBaseTemplateInstance
293256
nullCheck =
294257
[[inline]]
295258
// Verify that object arguments are non-null since we are a value type
296-
if (defaultOriginValue == null)
297-
{
298-
throw new ArgumentNullException("defaultOriginValue");
299-
}
300-
if (defaultDestinationValue == null)
301-
{
302-
throw new ArgumentNullException("defaultDestinationValue");
303-
}
259+
ArgumentNullException.ThrowIfNull(defaultOriginValue);
260+
ArgumentNullException.ThrowIfNull(defaultDestinationValue);
304261
[[/inline]];
305262
}
306263

@@ -321,10 +278,7 @@ private string WriteTypedGetCurrentValueBody(AnimationBaseTemplateInstance insta
321278
[[inline]]
322279
ReadPreamble();
323280

324-
if (animationClock == null)
325-
{
326-
throw new ArgumentNullException("animationClock");
327-
}
281+
ArgumentNullException.ThrowIfNull(animationClock);
328282

329283
if (animationClock.CurrentState == ClockState.Stopped)
330284
{

src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/AnimationClockResource.cs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,7 @@ public override void Go()
7171
[[inline]]
7272
[[Helpers.ManagedStyle.WriteFileHeader(fileName)]]
7373

74-
using System;
75-
using System.Windows;
76-
using System.Windows.Media;
7774
using System.Windows.Media.Composition;
78-
using System.Diagnostics;
79-
using System.Runtime.InteropServices;
80-
using System.Security;
8175

8276
namespace System.Windows.Media.Animation
8377
{
@@ -173,21 +167,16 @@ protected override DUCE.ResourceType ResourceType
173167
/// </summary>
174168
/// <param name="handle"> The DUCE.ResourceHandle for this resource on this channel. </param>
175169
/// <param name="channel"> The channel on which to update the render-thread resource. </param>
176-
/// <SecurityNote>
177-
/// Critical: This code calls into an unsafe code block
178-
/// TreatAsSafe: This code does not return any critical data.It is ok to expose
179-
/// Channels can handle bad pointers and will not affect other appdomains or processes
180-
/// </SecurityNote>
181-
[SecurityCritical,SecurityTreatAsSafe]
182170
protected override void UpdateResource(
183171
DUCE.ResourceHandle handle,
184172
DUCE.Channel channel)
185173
{
186-
DUCE.MILCMD_[[nameAsUpper]]RESOURCE cmd = new DUCE.MILCMD_[[nameAsUpper]]RESOURCE();
187-
188-
cmd.Type = MILCMD.MilCmd[[resource.Name]]Resource;
189-
cmd.Handle = handle;
190-
cmd.Value = CurrentValue;
174+
DUCE.MILCMD_[[nameAsUpper]]RESOURCE cmd = new DUCE.MILCMD_[[nameAsUpper]]RESOURCE
175+
{
176+
Type = MILCMD.MilCmd[[resource.Name]]Resource,
177+
Handle = handle,
178+
Value = CurrentValue
179+
};
191180

192181
unsafe
193182
{

src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/AnimationResourceTemplate.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,8 @@ public override void Go(ResourceModel resourceModel)
6262
[[inline]]
6363
[[Helpers.ManagedStyle.WriteFileHeader(fileName, @"wpf\src\Graphics\codegen\mcg\generators\AnimationResourceTemplate.cs")]]
6464

65-
using System;
66-
using MS.Internal;
67-
using System.Diagnostics;
68-
using System.Runtime.InteropServices;
69-
using System.Threading;
70-
71-
using System.Windows.Media;
7265
using System.Windows.Media.Composition;
7366
using System.Windows.Media.Media3D;
74-
using System.Security;
75-
using System.Security.Permissions;
7667

7768
namespace System.Windows.Media.Animation
7869
{
@@ -91,11 +82,6 @@ protected override DUCE.ResourceType ResourceType
9182
}
9283
}
9384

94-
/// <SecurityNote>
95-
/// Critical: This code is critical because it has unsafe code blocks
96-
/// TreatAsSafe: This call is ok to expose. Channels can handle bad pointers
97-
/// </SecurityNote>
98-
[SecurityCritical,SecurityTreatAsSafe]
9985
protected override void UpdateResourceCore(DUCE.Channel channel)
10086
{
10187
Debug.Assert(_duceResource.IsOnChannel(channel));

src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/AnimationTemplate.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,25 +117,14 @@ public override void Go(ResourceModel resourceModel)
117117
[[inline]]
118118
[[Helpers.ManagedStyle.WriteFileHeader(fileName)]]
119119

120-
using MS.Internal;
121120
using MS.Internal.KnownBoxes;
122-
using MS.Utility;
123-
124-
using System;
125-
using System.Collections;
126-
using System.ComponentModel;
127-
using System.Diagnostics;
128121
using System.Globalization;
129-
using System.Runtime.InteropServices;
130-
using System.Windows.Media;
131122
using System.Windows.Media.Media3D;
132-
using System.Windows.Media.Animation;
133123

134124
[[moduleReference]]
135125

136126
namespace System.Windows.Media.Animation
137-
{
138-
127+
{
139128
/// <summary>
140129
/// Animates the value of a [[instance.TypeName]] property using linear interpolation
141130
/// between two values. The values are determined by the combination of

src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/AnimationUsingKeyFramesTemplate.cs

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,13 @@ public override void Go(ResourceModel resourceModel)
6868
string fullPath = Path.Combine(resourceModel.OutputDirectory, path);
6969

7070
string moduleReference = "";
71-
string sridReference =
72-
[[inline]]
73-
using SR=System.Windows.SR;
74-
[[/inline]];
7571

7672
// Duplicate AnimatedTypeHelpers class across Core/Framework causes name conflicts,
7773
// requiring that they be split across two namespaces.
7874
switch (instance.ModuleName)
7975
{
8076
case @"PresentationCore":
8177
moduleReference = "using MS.Internal.PresentationCore;";
82-
sridReference =
83-
[[inline]]
84-
using SR=MS.Internal.PresentationCore.SR;
85-
[[/inline]];
8678
break;
8779
case "PresentationFramework":
8880
moduleReference = "using MS.Internal.PresentationFramework;";
@@ -95,21 +87,11 @@ public override void Go(ResourceModel resourceModel)
9587
[[inline]]
9688
[[Helpers.ManagedStyle.WriteFileHeader(fileName)]]
9789

98-
using MS.Internal;
9990
using MS.Internal.KnownBoxes;
100-
101-
using System;
10291
using System.Collections;
103-
using System.Collections.Generic;
10492
using System.ComponentModel;
105-
using System.Diagnostics;
106-
using System.Windows;
10793
using System.Windows.Markup;
108-
using System.Windows.Media.Animation;
109-
using System.Windows.Media.Media3D;
110-
111-
[[sridReference]]
112-
94+
using System.Windows.Media.Media3D;
11395
[[moduleReference]]
11496

11597
namespace System.Windows.Media.Animation
@@ -299,10 +281,7 @@ void IAddChild.AddChild(object child)
299281
{
300282
WritePreamble();
301283

302-
if (child == null)
303-
{
304-
throw new ArgumentNullException("child");
305-
}
284+
ArgumentNullException.ThrowIfNull(child);
306285

307286
AddChild(child);
308287

@@ -324,7 +303,7 @@ protected virtual void AddChild(object child)
324303
}
325304
else
326305
{
327-
throw new ArgumentException(SR.Animation_ChildMustBeKeyFrame, "child");
306+
throw new ArgumentException(SR.Animation_ChildMustBeKeyFrame, nameof(child));
328307
}
329308
}
330309

@@ -343,10 +322,7 @@ protected virtual void AddChild(object child)
343322
/// null.</exception>
344323
void IAddChild.AddText(string childText)
345324
{
346-
if (childText == null)
347-
{
348-
throw new ArgumentNullException("childText");
349-
}
325+
ArgumentNullException.ThrowIfNull(childText);
350326

351327
AddText(childText);
352328
}
@@ -612,10 +588,7 @@ public [[instance.TypeName]]KeyFrameCollection KeyFrames
612588
}
613589
set
614590
{
615-
if (value == null)
616-
{
617-
throw new ArgumentNullException("value");
618-
}
591+
ArgumentNullException.ThrowIfNull(value);
619592

620593
WritePreamble();
621594

@@ -819,7 +792,7 @@ private void ResolveKeyTimes()
819792
}
820793

821794
int maxKeyFrameIndex = keyFrameCount - 1;
822-
ArrayList unspecifiedBlocks = new ArrayList();
795+
List<KeyTimeBlock> unspecifiedBlocks = new List<KeyTimeBlock>();
823796
bool hasPacedKeyTimes = false;
824797

825798
//
@@ -886,8 +859,10 @@ private void ResolveKeyTimes()
886859
hasPacedKeyTimes = true;
887860
}
888861

889-
KeyTimeBlock block = new KeyTimeBlock();
890-
block.BeginIndex = index;
862+
KeyTimeBlock block = new KeyTimeBlock
863+
{
864+
BeginIndex = index
865+
};
891866

892867
// NOTE: We don't want to go all the way up to the
893868
// last frame because if it is Uniform or Paced its
@@ -931,7 +906,7 @@ private void ResolveKeyTimes()
931906

932907
for (int j = 0; j < unspecifiedBlocks.Count; j++)
933908
{
934-
KeyTimeBlock block = (KeyTimeBlock)unspecifiedBlocks[j];
909+
KeyTimeBlock block = unspecifiedBlocks[j];
935910

936911
TimeSpan blockBeginTime = TimeSpan.Zero;
937912

src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/CommandStructure.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,9 @@ public override void Go()
156156
[[inline]]
157157
// This code is generated from mcg\generators\CommandStructure.cs
158158

159-
using System;
160159
using System.Windows.Media.Composition;
161160
using System.Runtime.InteropServices;
162161
using System.Windows.Media.Effects;
163-
using System.Security;
164162

165163
using BOOL = System.UInt32;
166164

src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/DiscreteKeyFrameTemplate.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ private void ProcessNewModule(ResourceModel resourceModel, string moduleName, re
174174
string fileName = "DiscreteKeyFrames.cs";
175175
string path = null;
176176
string fullPath = null;
177-
string moduleReference = null;
178177

179178
//
180179
// Create a new file
@@ -183,18 +182,6 @@ private void ProcessNewModule(ResourceModel resourceModel, string moduleName, re
183182
path = "src\\" + moduleName + "\\System\\Windows\\Media\\Animation\\Generated";
184183
fullPath = Path.Combine(resourceModel.OutputDirectory, path);
185184

186-
// Duplicate AnimatedTypeHelpers class across Core/Framework causes name conflicts,
187-
// requiring that they be split across two namespaces.
188-
switch (moduleName)
189-
{
190-
case @"PresentationCore":
191-
moduleReference = "using MS.Internal.PresentationCore;";
192-
break;
193-
case "PresentationFramework":
194-
moduleReference = "using MS.Internal.PresentationFramework;";
195-
break;
196-
}
197-
198185
csFile = new FileCodeSink(fullPath, fileName, true /* Create dir if necessary */);
199186

200187
//
@@ -205,17 +192,8 @@ private void ProcessNewModule(ResourceModel resourceModel, string moduleName, re
205192
[[inline]]
206193
[[Helpers.ManagedStyle.WriteFileHeader(fileName)]]
207194

208-
using MS.Internal;
209-
210-
using System;
211-
using System.Collections;
212-
using System.ComponentModel;
213-
using System.Diagnostics;
214-
using System.Windows.Media;
215195
using System.Windows.Media.Media3D;
216196

217-
[[moduleReference]]
218-
219197
namespace System.Windows.Media.Animation
220198
{
221199
[[/inline]]

src/Microsoft.DotNet.Wpf/src/WpfGfx/codegen/mcg/generators/DuceResource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ McgResource dataType
567567

568568
codeSink.WriteBlock(
569569
[[inline]]
570-
HRESULT [[dataType.DuceClass]]::RegisterNotifiers(CMilSlaveHandleTable *pHandleTable)
570+
HRESULT [[dataType.DuceClass]]::RegisterNotifiers(__in_ecount(1) CMilSlaveHandleTable *pHandleTable)
571571
{
572572
HRESULT hr = S_OK;
573573

0 commit comments

Comments
 (0)