Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove RunClassConstructor proxy from SecurityHelper for code quality #9893

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using MS.Internal;
using System.Globalization;
using XamlReaderHelper = System.Windows.Markup.XamlReaderHelper;
using System.Runtime.CompilerServices;

namespace System.Windows.Baml2006
{
Expand Down Expand Up @@ -1377,7 +1378,7 @@ private void Process_Property()
// Force load the Statics by walking up the hierarchy and running class constructors
while (null != currentType)
{
MS.Internal.WindowsBase.SecurityHelper.RunClassConstructor(currentType);
RuntimeHelpers.RunClassConstructor(currentType.TypeHandle);
currentType = currentType.BaseType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.


using System.Xaml;
using System.ComponentModel;
using System.Globalization;

using System.Windows;
using System.Collections.Generic;
using System.Xaml;
using System.Runtime.CompilerServices;

namespace System.Windows.Markup
{
Expand Down Expand Up @@ -114,7 +112,7 @@ public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext,
// Force load the Statics by walking up the hierarchy and running class constructors
while (null != currentType)
{
MS.Internal.WindowsBase.SecurityHelper.RunClassConstructor(currentType);
RuntimeHelpers.RunClassConstructor(currentType.TypeHandle);
currentType = currentType.BaseType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
// Contents: Value serializer for the RoutedEvent class
//

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.CompilerServices;

namespace System.Windows.Markup
{
Expand Down Expand Up @@ -45,7 +44,7 @@ static void ForceTypeConstructors(Type currentType)
// Force load the Statics by walking up the hierarchy and running class constructors
while (currentType != null && !initializedTypes.ContainsKey(currentType))
{
MS.Internal.WindowsBase.SecurityHelper.RunClassConstructor(currentType);
RuntimeHelpers.RunClassConstructor(currentType.TypeHandle);
initializedTypes[currentType] = currentType;
currentType = currentType.BaseType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
using System.Reflection;

using MS.Utility;
using System.Security;
using System.Text;
using System.ComponentModel.Design.Serialization;
using System.Globalization;
Expand All @@ -34,6 +33,7 @@
using System.Xaml.Permissions;
using System.Windows.Navigation;
using MS.Internal.Xaml.Context;
using System.Runtime.CompilerServices;

namespace System.Windows.Markup
{
Expand Down Expand Up @@ -943,7 +943,7 @@ internal static object Load(

// In some cases, the application constructor is not run prior to loading,
// causing the loader not to recognize URIs beginning with "pack:" or "application:".
MS.Internal.WindowsBase.SecurityHelper.RunClassConstructor(typeof(System.Windows.Application));
RuntimeHelpers.RunClassConstructor(typeof(Application).TypeHandle);

EventTrace.EasyTraceEvent(EventTrace.Keyword.KeywordXamlBaml | EventTrace.Keyword.KeywordPerf, EventTrace.Event.WClientParseXamlBegin, parserContext.BaseUri);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,21 @@
using System;
using System.Xml;
using System.IO;
using MS.Utility;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.ComponentModel;
using System.Collections.Specialized;
using System.Runtime.CompilerServices;
using System.Diagnostics;
using System.Reflection;
using MS.Utility;

#if !PBTCOMPILER

using System.Windows;
using System.Windows.Markup;
using System.Windows.Resources;
using System.Windows.Threading;
using SecurityHelper=MS.Internal.PresentationFramework.SecurityHelper;
using MS.Internal; // CriticalExceptions

#else

using System.Runtime.CompilerServices;

#endif

// Disabling 1634 and 1691:
Expand Down Expand Up @@ -2010,7 +2002,7 @@ internal RoutedEvent RoutedEventFromName(
// Force load the Statics by walking up the hierarchy and running class constructors
while (null != currentType)
{
MS.Internal.WindowsBase.SecurityHelper.RunClassConstructor(currentType);
RuntimeHelpers.RunClassConstructor(currentType.TypeHandle);
currentType = GetCachedBaseType(currentType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
using MS.Internal.PresentationFramework; // SafeSecurityHelper
using System.Windows.Baml2006;
using System.Xaml.Permissions;
using System.Runtime.CompilerServices;

// Disable pragma warnings to enable PREsharp pragmas
#pragma warning disable 1634, 1691
Expand Down Expand Up @@ -819,7 +820,7 @@ private void LoadExternalAssembly(bool classic, bool generic, out Assembly assem
Type knownTypeHelper = assembly.GetType("Microsoft.Windows.Themes.KnownTypeHelper");
if (knownTypeHelper != null)
{
MS.Internal.WindowsBase.SecurityHelper.RunClassConstructor(knownTypeHelper);
RuntimeHelpers.RunClassConstructor(knownTypeHelper.TypeHandle);
}
}
#pragma warning restore 6502
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,6 @@ internal static int MapUrlToZoneWrapper(Uri uri)
}
#endif


#if WINDOWS_BASE
internal static void RunClassConstructor(Type t)
{
System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(t.TypeHandle);
}

#endif // WINDOWS_BASE

#if DRT
/// <remarks> The LinkDemand on Marshal.SizeOf() was removed in v4. </remarks>
internal static int SizeOf(Type t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using MS.Utility;
using MS.Internal;
using System.Threading;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Globalization;
using System.ComponentModel;
using System.Windows.Markup;// For ValueSerializerAttribute
using System.Windows.Threading; // For DispatcherObject
using MS.Utility;
using System.Windows.Markup; // For ValueSerializerAttribute
using MS.Internal.WindowsBase;
using System.Reflection; // for IsInstanceOfType
using MS.Internal;
using System.Windows.Threading; // For DispatcherObject
using System.Collections.Generic;
using System.Runtime.CompilerServices;

#pragma warning disable 1634, 1691 // suppressing PreSharp warnings

Expand Down Expand Up @@ -980,7 +978,7 @@ internal static DependencyProperty FromName(string name, Type ownerType)
while (ownerType != null)
{
// Ensure static constructor of type has run
SecurityHelper.RunClassConstructor(ownerType);
RuntimeHelpers.RunClassConstructor(ownerType.TypeHandle);

// Locate property
FromNameKey key = new(name, ownerType);
Expand Down