diff --git a/.github/workflows/Build.yml b/.github/workflows/Build.yml index 7bafb20973d..646918f4cd5 100644 --- a/.github/workflows/Build.yml +++ b/.github/workflows/Build.yml @@ -37,4 +37,4 @@ jobs: uses: actions/upload-artifact@v1 with: name: WPF_Release - path: ./artifacts/packages/Release/NonShipping \ No newline at end of file + path: ./artifacts/packages/Release/NonShipping diff --git a/.github/workflows/NuGet-Tag-Publish.yml b/.github/workflows/NuGet-Tag-Publish.yml new file mode 100644 index 00000000000..7de16267ed3 --- /dev/null +++ b/.github/workflows/NuGet-Tag-Publish.yml @@ -0,0 +1,65 @@ +name: Publish Custom WPF + +on: + push: + tags: + - '*' + +jobs: + # BuildDebug: + + # runs-on: windows-latest + + # steps: + # - uses: actions/checkout@v1 + # # - name: Install Nuget + # # uses: nuget/setup-nuget@v1 + # # with: + # # nuget-version: '5.x' + # - name: Build + # run: .\build.cmd -pack -ci -configuration Debug -prepareMachine /p:Platform=x86 + # - name: Push + # uses: actions/upload-artifact@v1 + # with: + # name: WPF_Debug + # path: ./artifacts/packages/Debug/NonShipping + + Build: + + runs-on: windows-latest + + steps: + - uses: actions/checkout@v1 + - name: Setup .NET + uses: actions/setup-dotnet@v1 + with: + dotnet-version: | + 3.1.x + 5.0.x + 6.0.101 + - name: Install Tools + run: dotnet tool install -g dotnetCampus.TagToVersion --add-source https://api.nuget.org/v3/index.json + - name: Set Package TagToVersion + run: dotnet tagtoversion -t ${{ github.ref }} -f CustomWpf\build\Version.props + - name: Build WPF + run: .\build.cmd -pack -ci -configuration Release -prepareMachine /p:Platform=x86 + - name: Pack NuGet + run: dotnet pack CustomWpf -c release + + - name: Install Nuget + uses: nuget/setup-nuget@v1 + with: + nuget-version: '5.x' + - name: Add private GitHub registry to NuGet + run: | + nuget sources add -name github -Source https://nuget.pkg.github.com/dotnet-campus/index.json -Username dotnet-campus -Password ${{ secrets.GITHUB_TOKEN }} + - name: Push NuGet Package + run: | + nuget push .\CustomWpf\bin\Release\*.nupkg -Source github -SkipDuplicate + nuget push .\CustomWpf\bin\Release\*.nupkg -Source https://api.nuget.org/v3/index.json -SkipDuplicate -ApiKey ${{ secrets.NugetKey }} + + # - name: Push + # uses: actions/upload-artifact@v1 + # with: + # name: WPF_Release + # path: ./artifacts/packages/Release/NonShipping \ No newline at end of file diff --git a/CustomWpf/CustomWpf.sln b/CustomWpf/CustomWpf.sln new file mode 100644 index 00000000000..500cb3ff708 --- /dev/null +++ b/CustomWpf/CustomWpf.sln @@ -0,0 +1,81 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.32014.148 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnetCampus.WPF", "Lib\dotnetCampus.CustomWpf.Lib\dotnetCampus.WPF.csproj", "{39764FE3-C2F9-4772-9BF6-B66923ABEC4C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lib", "Lib", "{FE032A91-A790-4274-A194-02E161D1F14B}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Packaging", "Packaging", "{27886E90-E328-4AE9-86DA-1F596554D26B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnetCampus.WPF.NuGet", "Packaging\dotnetCampus.WPF.NuGet\dotnetCampus.WPF.NuGet.csproj", "{FDC9151F-3544-4C68-9D05-D8E4935F1A9F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnetCampus.WPF.Resource", "Lib\dotnetCampus.CustomWpf.Resource\dotnetCampus.WPF.Resource.csproj", "{D73CB485-6290-4E37-B441-8068E60CBF7E}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{315B416C-6CDA-4CD5-9666-69C8272CD80E}" + ProjectSection(SolutionItems) = preProject + build\Version.props = build\Version.props + EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnetCampus.WPF.Dependencies", "Lib\dotnetCampus.CustomWpf.Dependencies\dotnetCampus.WPF.Dependencies.csproj", "{39E01A9E-C352-4B7E-96CA-612A07937470}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Demo", "Demo", "{1FCB5593-B06F-4DC3-B63F-315CF6DCF2BA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemoApp", "Demo\DemoApp\DemoApp.csproj", "{3C3A4FD6-333B-480B-8354-3BB209FA89DB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemoLib1", "Demo\DemoLib1\DemoLib1.csproj", "{B892B53C-752A-4700-8845-CD095F3AC08B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemoLib2", "Demo\DemoLib2\DemoLib2.csproj", "{17CCDE40-5335-479A-8B67-E7B0A1332EA9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {39764FE3-C2F9-4772-9BF6-B66923ABEC4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {39764FE3-C2F9-4772-9BF6-B66923ABEC4C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {39764FE3-C2F9-4772-9BF6-B66923ABEC4C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {39764FE3-C2F9-4772-9BF6-B66923ABEC4C}.Release|Any CPU.Build.0 = Release|Any CPU + {FDC9151F-3544-4C68-9D05-D8E4935F1A9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FDC9151F-3544-4C68-9D05-D8E4935F1A9F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FDC9151F-3544-4C68-9D05-D8E4935F1A9F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FDC9151F-3544-4C68-9D05-D8E4935F1A9F}.Release|Any CPU.Build.0 = Release|Any CPU + {D73CB485-6290-4E37-B441-8068E60CBF7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D73CB485-6290-4E37-B441-8068E60CBF7E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D73CB485-6290-4E37-B441-8068E60CBF7E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D73CB485-6290-4E37-B441-8068E60CBF7E}.Release|Any CPU.Build.0 = Release|Any CPU + {39E01A9E-C352-4B7E-96CA-612A07937470}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {39E01A9E-C352-4B7E-96CA-612A07937470}.Debug|Any CPU.Build.0 = Debug|Any CPU + {39E01A9E-C352-4B7E-96CA-612A07937470}.Release|Any CPU.ActiveCfg = Release|Any CPU + {39E01A9E-C352-4B7E-96CA-612A07937470}.Release|Any CPU.Build.0 = Release|Any CPU + {3C3A4FD6-333B-480B-8354-3BB209FA89DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3C3A4FD6-333B-480B-8354-3BB209FA89DB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3C3A4FD6-333B-480B-8354-3BB209FA89DB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3C3A4FD6-333B-480B-8354-3BB209FA89DB}.Release|Any CPU.Build.0 = Release|Any CPU + {B892B53C-752A-4700-8845-CD095F3AC08B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B892B53C-752A-4700-8845-CD095F3AC08B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B892B53C-752A-4700-8845-CD095F3AC08B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B892B53C-752A-4700-8845-CD095F3AC08B}.Release|Any CPU.Build.0 = Release|Any CPU + {17CCDE40-5335-479A-8B67-E7B0A1332EA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {17CCDE40-5335-479A-8B67-E7B0A1332EA9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {17CCDE40-5335-479A-8B67-E7B0A1332EA9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {17CCDE40-5335-479A-8B67-E7B0A1332EA9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {39764FE3-C2F9-4772-9BF6-B66923ABEC4C} = {FE032A91-A790-4274-A194-02E161D1F14B} + {FDC9151F-3544-4C68-9D05-D8E4935F1A9F} = {27886E90-E328-4AE9-86DA-1F596554D26B} + {D73CB485-6290-4E37-B441-8068E60CBF7E} = {FE032A91-A790-4274-A194-02E161D1F14B} + {39E01A9E-C352-4B7E-96CA-612A07937470} = {FE032A91-A790-4274-A194-02E161D1F14B} + {3C3A4FD6-333B-480B-8354-3BB209FA89DB} = {1FCB5593-B06F-4DC3-B63F-315CF6DCF2BA} + {B892B53C-752A-4700-8845-CD095F3AC08B} = {1FCB5593-B06F-4DC3-B63F-315CF6DCF2BA} + {17CCDE40-5335-479A-8B67-E7B0A1332EA9} = {1FCB5593-B06F-4DC3-B63F-315CF6DCF2BA} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C25E6016-F278-457B-87D6-39EC0E0A6849} + EndGlobalSection +EndGlobal diff --git a/CustomWpf/Demo/DemoApp/App.xaml b/CustomWpf/Demo/DemoApp/App.xaml new file mode 100644 index 00000000000..d2734c10dbf --- /dev/null +++ b/CustomWpf/Demo/DemoApp/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/CustomWpf/Demo/DemoApp/App.xaml.cs b/CustomWpf/Demo/DemoApp/App.xaml.cs new file mode 100644 index 00000000000..5a67a03ff54 --- /dev/null +++ b/CustomWpf/Demo/DemoApp/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace DemoApp +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/CustomWpf/Demo/DemoApp/AssemblyInfo.cs b/CustomWpf/Demo/DemoApp/AssemblyInfo.cs new file mode 100644 index 00000000000..8b5504ecfbb --- /dev/null +++ b/CustomWpf/Demo/DemoApp/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/CustomWpf/Demo/DemoApp/DemoApp.csproj b/CustomWpf/Demo/DemoApp/DemoApp.csproj new file mode 100644 index 00000000000..1a3bf6c44c4 --- /dev/null +++ b/CustomWpf/Demo/DemoApp/DemoApp.csproj @@ -0,0 +1,21 @@ + + + + WinExe + net6.0-windows + enable + true + false + + + + + + + + + + + + + diff --git a/CustomWpf/Demo/DemoApp/MainWindow.xaml b/CustomWpf/Demo/DemoApp/MainWindow.xaml new file mode 100644 index 00000000000..b52095773ab --- /dev/null +++ b/CustomWpf/Demo/DemoApp/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/CustomWpf/Demo/DemoApp/MainWindow.xaml.cs b/CustomWpf/Demo/DemoApp/MainWindow.xaml.cs new file mode 100644 index 00000000000..d2dfd425734 --- /dev/null +++ b/CustomWpf/Demo/DemoApp/MainWindow.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace DemoApp +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/CustomWpf/Demo/DemoLib1/AssemblyInfo.cs b/CustomWpf/Demo/DemoLib1/AssemblyInfo.cs new file mode 100644 index 00000000000..8b5504ecfbb --- /dev/null +++ b/CustomWpf/Demo/DemoLib1/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/CustomWpf/Demo/DemoLib1/DemoLib1.csproj b/CustomWpf/Demo/DemoLib1/DemoLib1.csproj new file mode 100644 index 00000000000..efadcca11bb --- /dev/null +++ b/CustomWpf/Demo/DemoLib1/DemoLib1.csproj @@ -0,0 +1,18 @@ + + + + net6.0-windows + enable + true + false + + + + + + + + + + + diff --git a/CustomWpf/Demo/DemoLib1/UserControl1.xaml b/CustomWpf/Demo/DemoLib1/UserControl1.xaml new file mode 100644 index 00000000000..c1a99ddd476 --- /dev/null +++ b/CustomWpf/Demo/DemoLib1/UserControl1.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/CustomWpf/Demo/DemoLib1/UserControl1.xaml.cs b/CustomWpf/Demo/DemoLib1/UserControl1.xaml.cs new file mode 100644 index 00000000000..255d31e44fa --- /dev/null +++ b/CustomWpf/Demo/DemoLib1/UserControl1.xaml.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using DemoLib2; + +namespace DemoLib1 +{ + /// + /// Interaction logic for UserControl1.xaml + /// + public partial class UserControl1 : UserControl + { + public UserControl1() + { + InitializeComponent(); + } + + public Foo Foo { get; } = new Foo(); + } +} diff --git a/CustomWpf/Demo/DemoLib2/DemoLib2.csproj b/CustomWpf/Demo/DemoLib2/DemoLib2.csproj new file mode 100644 index 00000000000..268cbace460 --- /dev/null +++ b/CustomWpf/Demo/DemoLib2/DemoLib2.csproj @@ -0,0 +1,10 @@ + + + + net6.0 + enable + enable + false + + + diff --git a/CustomWpf/Demo/DemoLib2/Foo.cs b/CustomWpf/Demo/DemoLib2/Foo.cs new file mode 100644 index 00000000000..a5438636cd7 --- /dev/null +++ b/CustomWpf/Demo/DemoLib2/Foo.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DemoLib2 +{ + public class Foo + { + } +} diff --git a/CustomWpf/Directory.Build.props b/CustomWpf/Directory.Build.props new file mode 100644 index 00000000000..2478d617d14 --- /dev/null +++ b/CustomWpf/Directory.Build.props @@ -0,0 +1,18 @@ + + + + latest + $(MSBuildThisFileDirectory)bin\$(Configuration) + dotnet campus(.NET 职业技术学院) + + dotnet-campus + https://github.com/dotnet-campus/dotnetCampus.CustomWpf + https://github.com/dotnet-campus/dotnetCampus.CustomWpf + 包含定制的 WPF 版本 + + git + Copyright © 2020-2022 dotnet campus, All Rights Reserved. + + + + diff --git a/CustomWpf/Directory.Build.targets b/CustomWpf/Directory.Build.targets new file mode 100644 index 00000000000..faf2349bae2 --- /dev/null +++ b/CustomWpf/Directory.Build.targets @@ -0,0 +1,3 @@ + + + diff --git a/CustomWpf/Lib/dotnetCampus.CustomWpf.Dependencies/Build/Package.targets b/CustomWpf/Lib/dotnetCampus.CustomWpf.Dependencies/Build/Package.targets new file mode 100644 index 00000000000..c99690af8b8 --- /dev/null +++ b/CustomWpf/Lib/dotnetCampus.CustomWpf.Dependencies/Build/Package.targets @@ -0,0 +1,13 @@ + + + + $(RuntimeIdentifier) + win-x86 + + + + + + + diff --git a/CustomWpf/Lib/dotnetCampus.CustomWpf.Dependencies/dotnetCampus.WPF.Dependencies.csproj b/CustomWpf/Lib/dotnetCampus.CustomWpf.Dependencies/dotnetCampus.WPF.Dependencies.csproj new file mode 100644 index 00000000000..63906a8bab0 --- /dev/null +++ b/CustomWpf/Lib/dotnetCampus.CustomWpf.Dependencies/dotnetCampus.WPF.Dependencies.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + + false + true + + + + + + + + + + diff --git a/CustomWpf/Lib/dotnetCampus.CustomWpf.Lib/Program.cs b/CustomWpf/Lib/dotnetCampus.CustomWpf.Lib/Program.cs new file mode 100644 index 00000000000..edfa89a0b31 --- /dev/null +++ b/CustomWpf/Lib/dotnetCampus.CustomWpf.Lib/Program.cs @@ -0,0 +1,18 @@ +using System; +using System.Runtime.CompilerServices; +using System.Windows; +using System.Windows.Media; +using System.Windows.Media.Composition; +using System.Windows.Navigation; + +namespace dotnetCampus.WPF +{ + class Program + { + static void Main(string[] args) + { + Application application = new Application(); + //NavigationService applicationNavService = application.NavService; + } + } +} diff --git a/CustomWpf/Lib/dotnetCampus.CustomWpf.Lib/dotnet-campus.PublicKey.snk b/CustomWpf/Lib/dotnetCampus.CustomWpf.Lib/dotnet-campus.PublicKey.snk new file mode 100644 index 00000000000..a21f243aa1b Binary files /dev/null and b/CustomWpf/Lib/dotnetCampus.CustomWpf.Lib/dotnet-campus.PublicKey.snk differ diff --git a/CustomWpf/Lib/dotnetCampus.CustomWpf.Lib/dotnet-campus.snk b/CustomWpf/Lib/dotnetCampus.CustomWpf.Lib/dotnet-campus.snk new file mode 100644 index 00000000000..8251708e309 Binary files /dev/null and b/CustomWpf/Lib/dotnetCampus.CustomWpf.Lib/dotnet-campus.snk differ diff --git a/CustomWpf/Lib/dotnetCampus.CustomWpf.Lib/dotnetCampus.WPF.csproj b/CustomWpf/Lib/dotnetCampus.CustomWpf.Lib/dotnetCampus.WPF.csproj new file mode 100644 index 00000000000..5f667bfc3ed --- /dev/null +++ b/CustomWpf/Lib/dotnetCampus.CustomWpf.Lib/dotnetCampus.WPF.csproj @@ -0,0 +1,28 @@ + + + + net6.0-windows + true + True + dotnet-campus.snk + + ..\..\..\ + + + $(Configuration) + + Microsoft.DotNet.Wpf.GitHub.Debug + Microsoft.DotNet.Wpf.GitHub + + + + true + + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + + + + + + + diff --git a/CustomWpf/Lib/dotnetCampus.CustomWpf.Resource/Build/Package.props b/CustomWpf/Lib/dotnetCampus.CustomWpf.Resource/Build/Package.props new file mode 100644 index 00000000000..ca9ef88448a --- /dev/null +++ b/CustomWpf/Lib/dotnetCampus.CustomWpf.Resource/Build/Package.props @@ -0,0 +1,5 @@ + + + $(MSBuildThisFileDirectory)..\Assets\ + + diff --git a/CustomWpf/Lib/dotnetCampus.CustomWpf.Resource/dotnetCampus.WPF.Resource.csproj b/CustomWpf/Lib/dotnetCampus.CustomWpf.Resource/dotnetCampus.WPF.Resource.csproj new file mode 100644 index 00000000000..092ccde4276 --- /dev/null +++ b/CustomWpf/Lib/dotnetCampus.CustomWpf.Resource/dotnetCampus.WPF.Resource.csproj @@ -0,0 +1,23 @@ + + + + net6.0 + false + true + + ..\..\..\ + + + $(Configuration) + + Microsoft.DotNet.Wpf.GitHub.Debug + Microsoft.DotNet.Wpf.GitHub + + $(WpfRepoRoot)\artifacts\packaging\$(WpfConfig)\$(WpfOuputFolder) + + + + + + + diff --git a/CustomWpf/NuGet.config b/CustomWpf/NuGet.config new file mode 100644 index 00000000000..f578cf96933 --- /dev/null +++ b/CustomWpf/NuGet.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/CustomWpf/Packaging/dotnetCampus.WPF.NuGet/MainTask.cs b/CustomWpf/Packaging/dotnetCampus.WPF.NuGet/MainTask.cs new file mode 100644 index 00000000000..a528545072c --- /dev/null +++ b/CustomWpf/Packaging/dotnetCampus.WPF.NuGet/MainTask.cs @@ -0,0 +1,64 @@ +using System.Reflection; + +using dotnetCampus.Configurations; +using dotnetCampus.DotNETBuild.Context; +using dotnetCampus.DotNETBuild.Utils; +using dotnetCampus.GitCommand; + +namespace dotnetCampus.WPF.NuGet; + +class MainTask +{ + public void Run() + { + var appConfigurator = AppConfigurator.GetAppConfigurator(); + + var commandLineArgs = Environment.GetCommandLineArgs(); + appConfigurator.AddCommandLine(commandLineArgs, new Dictionary() + { + {"t","Tag" } + }); + + var tagVersion = appConfigurator.Default["Tag"]; + + FileSniff fileSniff = new FileSniff(appConfigurator); + fileSniff.Sniff(); + + // 重新寻找 CustomWpf.sln 所在文件夹 + var slnFolder = FindDirectoryByFile(new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!), "CustomWpf.sln")!; + + var compileConfiguration = appConfigurator.Of(); + + Git git = new Git(new DirectoryInfo(compileConfiguration.CodeDirectory)); + var currentCommit = git.GetCurrentCommit(); + + // 找到 Version 版本号文件 + var versionFile = Path.Combine(slnFolder.FullName, @"build\Version.props"); + + } + + /// + /// 向上寻找到存在某个文件名的文件夹 + /// + /// + /// + /// + private static DirectoryInfo FindDirectoryByFile(DirectoryInfo currentDirectory, string fileName) + { + var directory = currentDirectory; + while (directory != null) + { + var file = Path.Combine(directory.FullName, fileName); + if (File.Exists(file)) + { + return directory; + } + else + { + directory = directory.Parent; + } + } + + throw new ArgumentException($"Can not find any Directory. CurrentDirectory =\"{currentDirectory}\";FileName=\"{fileName}\""); + } +} diff --git a/CustomWpf/Packaging/dotnetCampus.WPF.NuGet/Program.cs b/CustomWpf/Packaging/dotnetCampus.WPF.NuGet/Program.cs new file mode 100644 index 00000000000..d59d2ba2a93 --- /dev/null +++ b/CustomWpf/Packaging/dotnetCampus.WPF.NuGet/Program.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using dotnetCampus.Configurations; +using dotnetCampus.DotNETBuild.Utils; + +namespace dotnetCampus.WPF.NuGet; + +// 这个项目现在完全没有被用上 +// 不删除,后续需要再发布 x64 版本 +internal class Program +{ + public static void Main(string[] args) + { + MainTask mainTask = new MainTask(); + mainTask.Run(); + } +} diff --git a/CustomWpf/Packaging/dotnetCampus.WPF.NuGet/dotnetCampus.WPF.NuGet.csproj b/CustomWpf/Packaging/dotnetCampus.WPF.NuGet/dotnetCampus.WPF.NuGet.csproj new file mode 100644 index 00000000000..8b5a0a04d35 --- /dev/null +++ b/CustomWpf/Packaging/dotnetCampus.WPF.NuGet/dotnetCampus.WPF.NuGet.csproj @@ -0,0 +1,15 @@ + + + + Exe + net6.0 + enable + enable + false + + + + + + + diff --git a/CustomWpf/README.md b/CustomWpf/README.md new file mode 100644 index 00000000000..9864e635efd --- /dev/null +++ b/CustomWpf/README.md @@ -0,0 +1,7 @@ +# 私有发布的 WPF 仓库 + +这个仓库包含了官方没有合入的功能 + +## 给开发者 + +本仓库当前固定 dotnet 版本号,用来解决引用依赖问题。如有升级 dotnet runtime 版本,请同步更改 global.json 的 sdk 版本号,以及 `.github\workflows\` 里面的构建代码的安装版本号 \ No newline at end of file diff --git a/CustomWpf/build/Version.props b/CustomWpf/build/Version.props new file mode 100644 index 00000000000..0fd74ea58ea --- /dev/null +++ b/CustomWpf/build/Version.props @@ -0,0 +1,5 @@ + + + 6.0.4-alpha01-202205a6c7dca6 + + diff --git a/README.md b/README.md index abfa3e03b2a..cd2eb0a4310 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,37 @@ +# The Custom Windows Presentation Foundation (WPF) + +This repository fork from [WPF](https://github.com/dotnet/wpf), but contains code that is not officially merged. + +The reason for creating this repo is that we can't wait for some fascinating features. + +![](https://github.com/dotnet-campus/dotnetCampus.CustomWpf/workflows/Build%20WPF/badge.svg) + +| NuGet | Version | +|--|--| +|dotnetCampus.WPF|[![](https://img.shields.io/nuget/v/dotnetCampus.WPF.svg)](https://www.nuget.org/packages/dotnetCampus.WPF)| +|dotnetCampus.WPF.Dependencies|[![](https://img.shields.io/nuget/v/dotnetCampus.WPF.Resource.svg)](https://www.nuget.org/packages/dotnetCampus.WPF.Resource)| +|dotnetCampus.WPF.Resource|[![](https://img.shields.io/nuget/v/dotnetCampus.WPF.Dependencies.svg)](https://www.nuget.org/packages/dotnetCampus.WPF.Dependencies)| + +## What version are we on? + +[v6.0.4](https://github.com/dotnet/wpf/releases/tag/v6.0.4) + +[fcb07d637abf53791e2c55c63d9207fc3232fe83](https://github.com/dotnet/wpf/commit/fcb07d637abf53791e2c55c63d9207fc3232fe83) + +## Features + +See [Merged PR Issue #10 dotnet-campus/dotnetCampus.CustomWpf](https://github.com/dotnet-campus/dotnetCampus.CustomWpf/issues/10 ) + +## Contribution + +We recommend that you submit the Pull Request to the official [WPF](https://github.com/dotnet/wpf) repository and then you can ask we to pick the commit to this repository. This repository does not accept commit. + +## Reference + +- https://github.com/Faithlife/wpf : This is a custom build of Windows Presentation Foundation maintained by Faithlife. + +----- + # Windows Presentation Foundation (WPF) [![.NET Foundation](https://img.shields.io/badge/.NET%20Foundation-blueviolet.svg)](https://www.dotnetfoundation.org/) [![Build Status](https://dnceng.visualstudio.com/public/_apis/build/status/dotnet/wpf/dotnet-wpf%20CI)](https://dnceng.visualstudio.com/public/_build/latest?definitionId=270) diff --git a/src/Microsoft.DotNet.Wpf/src/Common/src/Interop/Windows/zlib/zlib.cs b/src/Microsoft.DotNet.Wpf/src/Common/src/Interop/Windows/zlib/zlib.cs index ca6e67a7ad8..fa9aac6717f 100644 --- a/src/Microsoft.DotNet.Wpf/src/Common/src/Interop/Windows/zlib/zlib.cs +++ b/src/Microsoft.DotNet.Wpf/src/Common/src/Interop/Windows/zlib/zlib.cs @@ -7,7 +7,7 @@ internal static partial class Interop { - internal static partial class zlib + internal static partial class Zlib { internal static readonly byte[] ZLibVersion = { (byte)'1', (byte)'.', (byte)'2', (byte)'.', (byte)'3', 0 }; [DllImport(Libraries.CompressionNative, EntryPoint = "CompressionNative_DeflateInit2_")] diff --git a/src/Microsoft.DotNet.Wpf/src/Common/src/System/IO/Compression/DeflateZLib/ZLibNative.cs b/src/Microsoft.DotNet.Wpf/src/Common/src/System/IO/Compression/DeflateZLib/ZLibNative.cs index 352d9f2248d..5c73688e384 100644 --- a/src/Microsoft.DotNet.Wpf/src/Common/src/System/IO/Compression/DeflateZLib/ZLibNative.cs +++ b/src/Microsoft.DotNet.Wpf/src/Common/src/System/IO/Compression/DeflateZLib/ZLibNative.cs @@ -252,7 +252,7 @@ public ErrorCode DeflateInit2_(CompressionLevel level, int windowBits, int memLe EnsureNotDisposed(); EnsureState(State.NotInitialized); - ErrorCode errC = Interop.zlib.DeflateInit2_(ref _zStream, level, CompressionMethod.Deflated, windowBits, memLevel, strategy); + ErrorCode errC = Interop.Zlib.DeflateInit2_(ref _zStream, level, CompressionMethod.Deflated, windowBits, memLevel, strategy); _initializationState = State.InitializedForDeflate; return errC; @@ -263,7 +263,7 @@ public ErrorCode Deflate(FlushCode flush) { EnsureNotDisposed(); EnsureState(State.InitializedForDeflate); - return Interop.zlib.Deflate(ref _zStream, flush); + return Interop.Zlib.Deflate(ref _zStream, flush); } @@ -272,7 +272,7 @@ public ErrorCode DeflateEnd() EnsureNotDisposed(); EnsureState(State.InitializedForDeflate); - ErrorCode errC = Interop.zlib.DeflateEnd(ref _zStream); + ErrorCode errC = Interop.Zlib.DeflateEnd(ref _zStream); _initializationState = State.Disposed; return errC; @@ -284,7 +284,7 @@ public ErrorCode InflateInit2_(int windowBits) EnsureNotDisposed(); EnsureState(State.NotInitialized); - ErrorCode errC = Interop.zlib.InflateInit2_(ref _zStream, windowBits); + ErrorCode errC = Interop.Zlib.InflateInit2_(ref _zStream, windowBits); _initializationState = State.InitializedForInflate; return errC; @@ -295,7 +295,7 @@ public ErrorCode Inflate(FlushCode flush) { EnsureNotDisposed(); EnsureState(State.InitializedForInflate); - return Interop.zlib.Inflate(ref _zStream, flush); + return Interop.Zlib.Inflate(ref _zStream, flush); } @@ -304,7 +304,7 @@ public ErrorCode InflateEnd() EnsureNotDisposed(); EnsureState(State.InitializedForInflate); - ErrorCode errC = Interop.zlib.InflateEnd(ref _zStream); + ErrorCode errC = Interop.Zlib.InflateEnd(ref _zStream); _initializationState = State.Disposed; return errC; diff --git a/src/Microsoft.DotNet.Wpf/src/Common/src/System/SR.cs b/src/Microsoft.DotNet.Wpf/src/Common/src/System/SR.cs index 0ecaad06f94..5b2b5db760a 100644 --- a/src/Microsoft.DotNet.Wpf/src/Common/src/System/SR.cs +++ b/src/Microsoft.DotNet.Wpf/src/Common/src/System/SR.cs @@ -6,6 +6,8 @@ using System.Resources; using System.Runtime.CompilerServices; +[assembly:InternalsVisibleTo("dotnetCampus.WPF, PublicKey=0024000004800000940000000602000000240000525341310004000001000100256f5cb79140dbc25623807d6823ca4b5b602209eaaf71f064e5926a7039c24351c1e2ad3130e194631307ed36a76ad4b832e237a467fefbd693428c7ecc5d4cc26796f6f8b705311948e00f2be5fa2db52ddff50a5b3eb0acc715b45618c1a92532ae2326529fb9e0f58a44abf31e9b5701994464186d3b9f52169b6e0f80b9")] + #if WINDOWS_BASE namespace MS.Internal.WindowsBase #elif PRESENTATION_CORE diff --git a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FontFileStream.cpp b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FontFileStream.cpp index 7e9b51adde8..e1c7339e9bc 100644 --- a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FontFileStream.cpp +++ b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FontFileStream.cpp @@ -17,17 +17,15 @@ namespace MS { namespace Internal { namespace Text { namespace TextInterface // guarantee that this problem will be fixed so we will use the GetUnmanagedStream(). Note: This path will only // be taken for embedded fonts among which XPS is a main scenario. For local fonts we use DWrite's APIs. _fontSourceStream = fontSource->GetUnmanagedStream(); + _fontSourcePointer = _fontSourceStream->PositionPointer - _fontSourceStream->Position; try { _lastWriteTime = fontSource->GetLastWriteTimeUtc().ToFileTimeUtc(); - } + } catch(System::ArgumentOutOfRangeException^) //The resulting file time would represent a date and time before 12:00 midnight January 1, 1601 C.E. UTC. { _lastWriteTime = -1; - } - - // Create lock to control access to font source stream. - _fontSourceStreamLock = gcnew Object(); + } } FontFileStream::~FontFileStream() @@ -61,31 +59,9 @@ namespace MS { namespace Internal { namespace Text { namespace TextInterface return E_INVALIDARG; } - int fragmentSizeInt = (int)fragmentSize; - array^ buffer = gcnew array(fragmentSizeInt); - - // DWrite may call this method from multiple threads. We need to ensure thread safety by making Seek and Read atomic. - System::Threading::Monitor::Enter(_fontSourceStreamLock); - try - { - _fontSourceStream->Seek(fileOffset, //long - System::IO::SeekOrigin::Begin); - - _fontSourceStream->Read(buffer, //byte[] - 0, //int - fragmentSizeInt //int - ); - } - finally - { - System::Threading::Monitor::Exit(_fontSourceStreamLock); - } - - GCHandle gcHandle = GCHandle::Alloc(buffer, GCHandleType::Pinned); - - *fragmentStart = (byte*)(gcHandle.AddrOfPinnedObject().ToPointer()); - - *fragmentContext = GCHandle::ToIntPtr(gcHandle).ToPointer(); + // Return a pointer to the font data that is already loaded in memory (because the font source resource is mmapped into the process' address space). + *fragmentStart = _fontSourcePointer + fileOffset; + *fragmentContext = nullptr; } catch(System::Exception^ exception) { @@ -102,11 +78,6 @@ namespace MS { namespace Internal { namespace Text { namespace TextInterface void* fragmentContext ) { - if (fragmentContext != NULL) - { - GCHandle gcHandle = GCHandle::FromIntPtr(IntPtr(fragmentContext)); - gcHandle.Free(); - } } [ComVisible(true)] diff --git a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FontFileStream.h b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FontFileStream.h index fa1f3a50c24..49cf479b0b4 100644 --- a/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FontFileStream.h +++ b/src/Microsoft.DotNet.Wpf/src/DirectWriteForwarder/CPP/DWriteWrapper/FontFileStream.h @@ -20,9 +20,9 @@ namespace MS { namespace Internal { namespace Text { namespace TextInterface private ref class FontFileStream : public IDWriteFontFileStreamMirror { private: - Stream^ _fontSourceStream; + UnmanagedMemoryStream^ _fontSourceStream; + Byte* _fontSourcePointer; INT64 _lastWriteTime; - Object^ _fontSourceStreamLock; public: diff --git a/src/Microsoft.DotNet.Wpf/src/Extensions/PresentationFramework-SystemCore/DynamicAccessorImpl.cs b/src/Microsoft.DotNet.Wpf/src/Extensions/PresentationFramework-SystemCore/DynamicAccessorImpl.cs index 7675ce2586b..e68ab97d602 100644 --- a/src/Microsoft.DotNet.Wpf/src/Extensions/PresentationFramework-SystemCore/DynamicAccessorImpl.cs +++ b/src/Microsoft.DotNet.Wpf/src/Extensions/PresentationFramework-SystemCore/DynamicAccessorImpl.cs @@ -156,7 +156,7 @@ public static DynamicIndexerAccessor GetIndexerAccessor(int rank) MulticastDelegate _getterDelegate, _setterDelegate; static DynamicIndexerAccessor[] _accessors = new DynamicIndexerAccessor[1]; - static object _lock = new object(); + static readonly object _lock = new object(); } #endregion DynamicIndexerAccessor diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/AnimatedTypeHelpers.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/AnimatedTypeHelpers.cs index 76855e77479..7e7abfb455c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/AnimatedTypeHelpers.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/AnimatedTypeHelpers.cs @@ -844,7 +844,7 @@ internal static Rotation3D GetZeroValueRotation3D(Rotation3D baseValue) private static Boolean IsInvalidDouble(Double value) { return Double.IsInfinity(value) - || DoubleUtil.IsNaN(value); + || double.IsNaN(value); } #endregion diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FamilyCollection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FamilyCollection.cs index 0ad6a9a7454..35203cd7dae 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FamilyCollection.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FamilyCollection.cs @@ -499,10 +499,7 @@ private static Text.TextInterface.Font GetFontFromFamily(Text.TextInterface.Font foreach (KeyValuePair name in font.FaceNames) { string currentFontName = name.Value.ToUpper(CultureInfo.InvariantCulture); - if (!faces.ContainsKey(currentFontName)) - { - faces.Add(currentFontName, font); - } + faces.TryAdd(currentFontName, font); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FontCacheUtil.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FontCacheUtil.cs index f54f8b9dca2..74c9340a7eb 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FontCacheUtil.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/FontCacheUtil.cs @@ -315,7 +315,7 @@ internal static string CompositeFontExtension private const string EmptyFontFamilyReference = "#"; private const string EmptyCanonicalName = ""; - private static object _dpiLock = new object(); + private static readonly object _dpiLock = new object(); private static int _dpi; private static bool _dpiInitialized = false; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/TypefaceMetricsCache.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/TypefaceMetricsCache.cs index 8c5afa842cd..b1ba1f208ee 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/TypefaceMetricsCache.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontCache/TypefaceMetricsCache.cs @@ -68,7 +68,7 @@ internal static void Add(object key, object value) } private static Hashtable _hashTable = new Hashtable(MaxCacheCapacity); - private static object _lock = new object(); + private static readonly object _lock = new object(); private const int MaxCacheCapacity = 64; // Maximum cache capacity } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontFace/CompositeFontParser.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontFace/CompositeFontParser.cs index 23aa70f31d8..a92aa59c75f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontFace/CompositeFontParser.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/FontFace/CompositeFontParser.cs @@ -34,7 +34,7 @@ internal class CompositeFontParser { internal static void VerifyMultiplierOfEm(string propertyName, ref double value) { - if (DoubleUtil.IsNaN(value)) + if (double.IsNaN(value)) { throw new ArgumentException(SR.Get(SRID.PropertyValueCannotBeNaN, propertyName)); } @@ -50,7 +50,7 @@ internal static void VerifyMultiplierOfEm(string propertyName, ref double value) internal static void VerifyPositiveMultiplierOfEm(string propertyName, ref double value) { - if (DoubleUtil.IsNaN(value)) + if (double.IsNaN(value)) { throw new ArgumentException(SR.Get(SRID.PropertyValueCannotBeNaN, propertyName)); } @@ -66,7 +66,7 @@ internal static void VerifyPositiveMultiplierOfEm(string propertyName, ref doubl internal static void VerifyNonNegativeMultiplierOfEm(string propertyName, ref double value) { - if (DoubleUtil.IsNaN(value)) + if (double.IsNaN(value)) { throw new ArgumentException(SR.Get(SRID.PropertyValueCannotBeNaN, propertyName)); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/PreloadedPackages.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/PreloadedPackages.cs index 43faa492ae1..33188884498 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/PreloadedPackages.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/IO/Packaging/PreloadedPackages.cs @@ -241,7 +241,7 @@ internal bool ThreadSafe // Hashtable. HybridDictionary already has functionality of switching between // ListDictionary and Hashtable depending on the size of the collection static private HybridDictionary _packagePairs; - static private Object _globalLock; + static private readonly Object _globalLock; #endregion Private Fields } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/GestureRecognizer/NativeRecognizer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/GestureRecognizer/NativeRecognizer.cs index ed28449db4c..4dbf871e3ae 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/GestureRecognizer/NativeRecognizer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/GestureRecognizer/NativeRecognizer.cs @@ -834,7 +834,7 @@ enum RECO_TYPE : ushort /// /// Used to lock for instancing the native recognizer handle /// - private static object _syncRoot = new object(); + private static readonly object _syncRoot = new object(); /// /// All NativeRecognizer share a single handle to the recognizer diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/StrokeNode.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/StrokeNode.cs index 56224c40b17..1552dc7978b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/StrokeNode.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/Ink/StrokeNode.cs @@ -441,7 +441,6 @@ out bool missingIntersection { Rect node1Bounds = _operations.GetNodeBounds(previous._lastNode); Rect node2Bounds = _operations.GetNodeBounds(_lastNode); - Rect node3Bounds = _operations.GetNodeBounds(_thisNode); #if DEBUG_RENDERING_FEEDBACK if (showFeedback) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/SynchronizedInputHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/SynchronizedInputHelper.cs index 3d020a8e1cc..28cfd0a05ef 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/SynchronizedInputHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/SynchronizedInputHelper.cs @@ -297,21 +297,18 @@ internal static RoutedEvent[] MapInputTypeToRoutedEvents(SynchronizedInputType i internal static void RaiseAutomationEvents() { - if (InputElement.IsUIElement(InputManager.ListeningElement)) + if (InputManager.ListeningElement is UIElement e) { - UIElement e = (UIElement)InputManager.ListeningElement; //Raise InputDiscarded automation event SynchronizedInputHelper.RaiseAutomationEvent(e.GetAutomationPeer()); } - else if (InputElement.IsContentElement(InputManager.ListeningElement)) + else if (InputManager.ListeningElement is ContentElement ce) { - ContentElement ce = (ContentElement)InputManager.ListeningElement; //Raise InputDiscarded automation event SynchronizedInputHelper.RaiseAutomationEvent(ce.GetAutomationPeer()); } - else if (InputElement.IsUIElement3D(InputManager.ListeningElement)) + else if (InputManager.ListeningElement is UIElement3D e3D) { - UIElement3D e3D = (UIElement3D)InputManager.ListeningElement; //Raise InputDiscarded automation event SynchronizedInputHelper.RaiseAutomationEvent(e3D.GetAutomationPeer()); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/FullTextLine.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/FullTextLine.cs index f0236c6218a..13f66f965cd 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/FullTextLine.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/FullTextLine.cs @@ -2080,7 +2080,7 @@ public override IList> GetTextRunSpans() return Array.Empty>(); } - IList> lsrunList = new List>(2); + List> lsrunList = new List>(2); TextRun lastTextRun = null; int cchAcc = 0; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextFormatterImp.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextFormatterImp.cs index 160ba8fdc2d..94a4e74de23 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextFormatterImp.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextFormatterImp.cs @@ -481,7 +481,7 @@ TextRunCache textRunCache if (paragraphProperties.DefaultTextRunProperties.Typeface == null) throw new ArgumentNullException("paragraphProperties.DefaultTextRunProperties.Typeface"); - if (DoubleUtil.IsNaN(paragraphWidth)) + if (double.IsNaN(paragraphWidth)) throw new ArgumentOutOfRangeException("paragraphWidth", SR.Get(SRID.ParameterValueCannotBeNaN)); if (double.IsInfinity(paragraphWidth)) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextRunCacheImp.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextRunCacheImp.cs index ad01bbead6d..18b0a96edcd 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextRunCacheImp.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/TextFormatting/TextRunCacheImp.cs @@ -329,13 +329,13 @@ internal TextSpan GetPrecedingText(TextSour /// internal IList> GetTextRunSpans() { - IList> textRunList = new List>(_textRunVector.Count); + TextSpan[] textRunList = new TextSpan[_textRunVector.Count]; - for (int i = 0; i < _textRunVector.Count; i++) + for (int i = 0; i < textRunList.Length; i++) { - Span currentSpan = _textRunVector[i]; - textRunList.Add(new TextSpan(currentSpan.length, currentSpan.element as TextRun)); - } + Span currentSpan = _textRunVector[i]; + textRunList[i] = new TextSpan(currentSpan.length, currentSpan.element as TextRun); + } return textRunList; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/UIElementHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/UIElementHelper.cs index 4496a6a014f..b699b840377 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/UIElementHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/UIElementHelper.cs @@ -141,7 +141,7 @@ internal static DependencyObject GetUIParent(DependencyObject child, bool contin [FriendAccessAllowed] internal static bool IsUIElementOrUIElement3D(DependencyObject o) { - return (o is UIElement || o is UIElement3D); + return (o is UIElement or UIElement3D); } [FriendAccessAllowed] diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackageStore.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackageStore.cs index 0fd55d2fa3e..5fa28c27d67 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackageStore.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/IO/Packaging/PackageStore.cs @@ -172,7 +172,7 @@ private static void ValidatePackageUri(Uri uri) // Hashtable. HybridDictionary already has functionality of switching between // ListDictionary and Hashtable depending on the size of the collection static private HybridDictionary _packages; - static private Object _globalLock; + static private readonly Object _globalLock; #endregion Private Fields } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/CoreCompatibilityPreferences.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/CoreCompatibilityPreferences.cs index cfecfb1cdbd..e024c097b6d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/CoreCompatibilityPreferences.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/CoreCompatibilityPreferences.cs @@ -187,6 +187,6 @@ private static void Seal() } private static bool _isSealed; - private static object _lockObject = new object(); + private static readonly object _lockObject = new object(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/DataFormats.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/DataFormats.cs index 9990b2c9b11..8dd1510fe76 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/DataFormats.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/DataFormats.cs @@ -470,7 +470,7 @@ private static void EnsurePredefined() private static ArrayList _formatList; // This object is for locking the _formatList to access safe in the multi-thread. - private static Object _formatListlock = new Object(); + private static readonly Object _formatListlock = new Object(); #endregion Private Fields } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Diagnostics/XamlSourceInfoHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Diagnostics/XamlSourceInfoHelper.cs index 19b30cf6782..e2b53ec2d45 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Diagnostics/XamlSourceInfoHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Diagnostics/XamlSourceInfoHelper.cs @@ -38,7 +38,7 @@ internal static class XamlSourceInfoHelper private static ConditionalWeakTable s_sourceInfoTable; // no storage by default // While ConditionalWeakTable is thread safe we need to make multiple calls in a thread safe manner. - private static object s_lock = new object(); + private static readonly object s_lock = new object(); private static PropertyInfo s_sourceBamlUriProperty; private static PropertyInfo s_elementLineNumberProperty; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/EventRoute.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/EventRoute.cs index 7120dac9a6a..b10e199e26f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/EventRoute.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/EventRoute.cs @@ -321,7 +321,7 @@ public void PushBranchNode(object node, object source) branchNode.Node = node; branchNode.Source = source; - BranchNodeStack.Push(branchNode); + (_branchNodeStack ??= new Stack(1)).Push(branchNode); } /// @@ -343,12 +343,12 @@ public void PushBranchNode(object node, object source) [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] public object PopBranchNode() { - if (BranchNodeStack.Count == 0) - return null; - - BranchNode branchNode = BranchNodeStack.Pop(); + if (_branchNodeStack is { Count: > 0 } stack) + { + return stack.Pop().Node; + } - return branchNode.Node; + return null; } /// @@ -370,12 +370,12 @@ public object PopBranchNode() [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] public object PeekBranchNode() { - if (BranchNodeStack.Count == 0) - return null; - - BranchNode branchNode = BranchNodeStack.Peek(); + if (_branchNodeStack is { Count: > 0 } stack) + { + return stack.Peek().Node; + } - return branchNode.Node; + return null; } /// @@ -397,12 +397,12 @@ public object PeekBranchNode() [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] public object PeekBranchSource() { - if (BranchNodeStack.Count == 0) - return null; - - BranchNode branchNode = BranchNodeStack.Peek(); + if (_branchNodeStack is { Count: > 0 } stack) + { + return stack.Peek().Source; + } - return branchNode.Source; + return null; } #endregion External API @@ -429,20 +429,6 @@ private struct BranchNode public object Source; } - // Branch nodes are stored on a stack, which we create on-demand. - private Stack BranchNodeStack - { - get - { - if (_branchNodeStack == null) - { - _branchNodeStack = new Stack(1); - } - - return _branchNodeStack; - } - } - // Add the given source to the source item list // indicating what the source will be this point // onwards in the route diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/EventRouteFactory.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/EventRouteFactory.cs index ff03ba6bdbe..665a119b71d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/EventRouteFactory.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/EventRouteFactory.cs @@ -98,7 +98,7 @@ private static EventRoute Pop() private static EventRoute[] _eventRouteStack; private static int _stackTop; - private static object _synchronized = new object(); + private static readonly object _synchronized = new object(); #endregion Data } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandBinding.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandBinding.cs index 0890cda1424..02acc51b56a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandBinding.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandBinding.cs @@ -7,6 +7,7 @@ using System; using System.ComponentModel; +using System.Diagnostics; using System.Windows; using System.Windows.Markup; using MS.Internal; @@ -60,18 +61,13 @@ public CommandBinding(ICommand command, ExecutedRoutedEventHandler executed) /// Handler associated with determining if the command can execute. public CommandBinding(ICommand command, ExecutedRoutedEventHandler executed, CanExecuteRoutedEventHandler canExecute) { - if (command == null) - { - throw new ArgumentNullException("command"); - } + _command = command ?? throw new ArgumentNullException(nameof(command)); - _command = command; - - if (executed != null) + if (executed is not null) { Executed += executed; } - if (canExecute != null) + if (canExecute is not null) { CanExecute += canExecute; } @@ -87,20 +83,8 @@ public CommandBinding(ICommand command, ExecutedRoutedEventHandler executed, Can [Localizability(LocalizationCategory.NeverLocalize)] // cannot be localized public ICommand Command { - get - { - return _command; - } - - set - { - if (value == null) - { - throw new ArgumentNullException("value"); - } - - _command = value; - } + get => _command; + set => _command = value ?? throw new ArgumentNullException(nameof(value)); } #endregion @@ -138,49 +122,46 @@ public ICommand Command /// Event arguments. internal void OnCanExecute(object sender, CanExecuteRoutedEventArgs e) { - if (!e.Handled) + if (e.Handled) return; + if (e.RoutedEvent == CommandManager.CanExecuteEvent) { - if (e.RoutedEvent == CommandManager.CanExecuteEvent) + if (CanExecute is null) { - if (CanExecute != null) - { - CanExecute(sender, e); - if (e.CanExecute) - { - e.Handled = true; - } - } - else if (!e.CanExecute) - { - // If there is an Executed handler, then the command can be executed. - if (Executed != null) - { - e.CanExecute = true; - e.Handled = true; - } - } + if (e.CanExecute) return; + // If there is an Executed handler, then the command can be executed. + if (Executed is null) return; + e.CanExecute = true; + e.Handled = true; } - else // e.RoutedEvent == CommandManager.PreviewCanExecuteEvent + else { - if (PreviewCanExecute != null) + CanExecute(sender, e); + if (e.CanExecute) { - PreviewCanExecute(sender, e); - if (e.CanExecute) - { - e.Handled = true; - } + e.Handled = true; } } } + else // e.RoutedEvent == CommandManager.PreviewCanExecuteEvent + { + if (PreviewCanExecute is null) return; + PreviewCanExecute(sender, e); + if (e.CanExecute) + { + e.Handled = true; + } + } } private bool CheckCanExecute(object sender, ExecutedRoutedEventArgs e) { - CanExecuteRoutedEventArgs canExecuteArgs = new CanExecuteRoutedEventArgs(e.Command, e.Parameter); - canExecuteArgs.RoutedEvent = CommandManager.CanExecuteEvent; + CanExecuteRoutedEventArgs canExecuteArgs = new(e.Command, e.Parameter) + { + RoutedEvent = CommandManager.CanExecuteEvent, + // Since we don't actually raise this event, we have to explicitly set the source. + Source = e.OriginalSource + }; - // Since we don't actually raise this event, we have to explicitly set the source. - canExecuteArgs.Source = e.OriginalSource; canExecuteArgs.OverrideSource(e.Source); OnCanExecute(sender, canExecuteArgs); @@ -195,30 +176,22 @@ private bool CheckCanExecute(object sender, ExecutedRoutedEventArgs e) /// Event arguments. internal void OnExecuted(object sender, ExecutedRoutedEventArgs e) { - if (!e.Handled) + if (e.Handled) return; + if (e.RoutedEvent == CommandManager.ExecutedEvent) { - if (e.RoutedEvent == CommandManager.ExecutedEvent) - { - if (Executed != null) - { - if (CheckCanExecute(sender, e)) - { - Executed(sender, e); - e.Handled = true; - } - } - } - else // e.RoutedEvent == CommandManager.PreviewExecutedEvent - { - if (PreviewExecuted != null) - { - if (CheckCanExecute(sender, e)) - { - PreviewExecuted(sender, e); - e.Handled = true; - } - } - } + if (Executed is null) return; + if (!CheckCanExecute(sender, e)) return; + Debug.Assert(Executed != null, nameof(Executed) + " != null"); + Executed(sender, e); + e.Handled = true; + } + else // e.RoutedEvent == CommandManager.PreviewExecutedEvent + { + if (PreviewExecuted is null) return; + if (!CheckCanExecute(sender, e)) return; + Debug.Assert(PreviewExecuted != null, nameof(PreviewExecuted) + " != null"); + PreviewExecuted(sender, e); + e.Handled = true; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandBindingCollection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandBindingCollection.cs index 98725d64267..8adf9e4d232 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandBindingCollection.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandBindingCollection.cs @@ -52,9 +52,9 @@ public CommandBindingCollection() /// CommandBinding array public CommandBindingCollection(IList commandBindings) { - if (commandBindings != null && commandBindings.Count > 0) + if (commandBindings is { Count: > 0 }) { - AddRange(commandBindings as ICollection); + AddRange(commandBindings); } } @@ -76,12 +76,9 @@ public CommandBindingCollection(IList commandBindings) /// /// commandbinding array to copy into /// start index in current list to copy - void ICollection.CopyTo(System.Array array, int index) + void ICollection.CopyTo(System.Array array, int index) { - if (_innerCBList != null) - { - ((ICollection)_innerCBList).CopyTo(array, index); - } + ((ICollection)_innerCBList)?.CopyTo(array, index); } #endregion Implementation of ICollection @@ -92,7 +89,7 @@ void ICollection.CopyTo(System.Array array, int index) /// true - if found, false - otherwise bool IList.Contains(object key) { - return this.Contains(key as CommandBinding) ; + return Contains(key as CommandBinding) ; } /// @@ -102,8 +99,7 @@ bool IList.Contains(object key) /// int IList.IndexOf(object value) { - CommandBinding commandBinding = value as CommandBinding; - return ((commandBinding != null) ? this.IndexOf(commandBinding) : -1); + return ((value is CommandBinding commandBinding) ? IndexOf(commandBinding) : -1); } /// @@ -113,7 +109,7 @@ int IList.IndexOf(object value) /// item to insert void IList.Insert(int index, object value) { - this.Insert(index, value as CommandBinding); + Insert(index, value as CommandBinding); } /// @@ -122,7 +118,7 @@ void IList.Insert(int index, object value) /// CommandBinding object to add int IList.Add(object commandBinding) { - return this.Add(commandBinding as CommandBinding); + return Add(commandBinding as CommandBinding); } /// @@ -131,7 +127,7 @@ int IList.Add(object commandBinding) /// CommandBinding object to remove void IList.Remove(object commandBinding) { - this.Remove(commandBinding as CommandBinding); + Remove(commandBinding as CommandBinding); } /// @@ -145,8 +141,7 @@ object IList.this[int index] } set { - CommandBinding commandBinding = value as CommandBinding; - if (commandBinding == null) + if (value is not CommandBinding commandBinding) throw new NotSupportedException(SR.Get(SRID.CollectionOnlyAcceptsCommandBindings)); this[index] = commandBinding; @@ -160,7 +155,7 @@ public CommandBinding this[int index] { get { - return (_innerCBList != null ? _innerCBList[index] : null); + return (_innerCBList?[index]); } set { @@ -179,8 +174,7 @@ public int Add(CommandBinding commandBinding) { if (commandBinding != null) { - if (_innerCBList == null) - _innerCBList = new System.Collections.Generic.List(1); + _innerCBList ??= new Collections.Generic.List(1); _innerCBList.Add(commandBinding); return 0; // ICollection.Add no longer returns the indice @@ -200,27 +194,23 @@ public int Add(CommandBinding commandBinding) public void AddRange(ICollection collection) { if (collection==null) - throw new ArgumentNullException("collection"); - - if (collection.Count > 0) - { - if (_innerCBList == null) - _innerCBList = new System.Collections.Generic.List(collection.Count); + throw new ArgumentNullException(nameof(collection)); + + if (collection.Count <= 0) return; + _innerCBList ??= new System.Collections.Generic.List(collection.Count); - IEnumerator collectionEnum = collection.GetEnumerator(); - while(collectionEnum.MoveNext()) + IEnumerator collectionEnum = collection.GetEnumerator(); + while(collectionEnum.MoveNext()) + { + if (collectionEnum.Current is CommandBinding cmdBinding) { - CommandBinding cmdBinding = collectionEnum.Current as CommandBinding; - if (cmdBinding != null) - { - _innerCBList.Add(cmdBinding); - } - else - { - throw new NotSupportedException(SR.Get(SRID.CollectionOnlyAcceptsCommandBindings)); - } - } - } + _innerCBList.Add(cmdBinding); + } + else + { + throw new NotSupportedException(SR.Get(SRID.CollectionOnlyAcceptsCommandBindings)); + } + } } /// @@ -232,8 +222,7 @@ public void Insert(int index, CommandBinding commandBinding) { if (commandBinding != null) { - if (_innerCBList != null) - _innerCBList.Insert(index, commandBinding); + _innerCBList?.Insert(index, commandBinding); } else { @@ -257,8 +246,7 @@ public void Remove(CommandBinding commandBinding) /// index at which the item needs to be removed public void RemoveAt(int index) { - if (_innerCBList != null) - _innerCBList.RemoveAt(index); + _innerCBList?.RemoveAt(index); } /// @@ -276,11 +264,7 @@ public bool IsSynchronized { get { - if (_innerCBList != null) - { - return ((IList)_innerCBList).IsSynchronized; - } - return false; + return _innerCBList is not null && ((IList)_innerCBList).IsSynchronized; } } @@ -310,7 +294,7 @@ public int Count { get { - return (_innerCBList != null ? _innerCBList.Count : 0); + return _innerCBList?.Count ?? 0; } } @@ -319,11 +303,9 @@ public int Count /// public void Clear() { - if (_innerCBList != null) - { - _innerCBList.Clear(); - _innerCBList = null; - } + if (_innerCBList is null) return; + _innerCBList.Clear(); + _innerCBList = null; } /// @@ -333,7 +315,7 @@ public void Clear() /// public int IndexOf(CommandBinding value) { - return ((_innerCBList != null) ? _innerCBList.IndexOf(value) : -1); + return _innerCBList?.IndexOf(value) ?? -1; } /// @@ -355,10 +337,9 @@ public bool Contains(CommandBinding commandBinding) /// /// type-safe (CommandBinding) array /// start index in current list to copy - public void CopyTo(CommandBinding[] commandBindings, int index) + public void CopyTo(CommandBinding[] commandBindings, int index) { - if (_innerCBList != null) - _innerCBList.CopyTo(commandBindings, index); + _innerCBList?.CopyTo(commandBindings, index); } #region Implementation of Enumerable @@ -385,17 +366,11 @@ internal ICommand FindMatch(object targetElement, InputEventArgs inputEventArgs) for (int i = 0; i < Count; i++) { CommandBinding commandBinding = this[i]; - RoutedCommand routedCommand = commandBinding.Command as RoutedCommand; - if (routedCommand != null) + if (commandBinding.Command is not RoutedCommand routedCommand) continue; + InputGestureCollection inputGestures = routedCommand.InputGesturesInternal; + if (inputGestures?.FindMatch(targetElement, inputEventArgs) != null) { - InputGestureCollection inputGestures = routedCommand.InputGesturesInternal; - if (inputGestures != null) - { - if (inputGestures.FindMatch(targetElement, inputEventArgs) != null) - { - return routedCommand; - } - } + return routedCommand; } } @@ -423,7 +398,7 @@ internal CommandBinding FindMatch(ICommand command, ref int index) // //------------------------------------------------------ #region Private Fields - private System.Collections.Generic.List _innerCBList; + private Collections.Generic.List _innerCBList; #endregion Private Fields } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandManager.cs index 26f934c821f..3a0454e3212 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Command/CommandManager.cs @@ -352,9 +352,9 @@ internal static void TranslateInput(IInputElement targetElement, InputEventArgs // Determine UIElement/ContentElement/Neither type DependencyObject targetElementAsDO = targetElement as DependencyObject; - bool isUIElement = InputElement.IsUIElement(targetElementAsDO); - bool isContentElement = !isUIElement && InputElement.IsContentElement(targetElementAsDO); - bool isUIElement3D = !isUIElement && !isContentElement && InputElement.IsUIElement3D(targetElementAsDO); + bool isUIElement = targetElementAsDO is UIElement; + bool isContentElement = !isUIElement && targetElementAsDO is ContentElement; + bool isUIElement3D = !isUIElement && !isContentElement && targetElementAsDO is UIElement3D; // Step 1: Check local input bindings InputBindingCollection localInputBindings = null; @@ -370,6 +370,7 @@ internal static void TranslateInput(IInputElement targetElement, InputEventArgs { localInputBindings = ((UIElement3D)targetElement).InputBindingsInternal; } + if (localInputBindings != null) { InputBinding inputBinding = localInputBindings.FindMatch(targetElement, inputEventArgs); @@ -423,6 +424,7 @@ internal static void TranslateInput(IInputElement targetElement, InputEventArgs { localCommandBindings = ((UIElement3D)targetElement).CommandBindingsInternal; } + if (localCommandBindings != null) { command = localCommandBindings.FindMatch(targetElement, inputEventArgs); @@ -599,64 +601,56 @@ internal static void OnCommandDevice(object sender, CommandDeviceEventArgs e) private static void FindCommandBinding(object sender, RoutedEventArgs e, ICommand command, bool execute) { // Check local command bindings - CommandBindingCollection commandBindings = null; - DependencyObject senderAsDO = sender as DependencyObject; - if (InputElement.IsUIElement(senderAsDO)) - { - commandBindings = ((UIElement)senderAsDO).CommandBindingsInternal; - } - else if (InputElement.IsContentElement(senderAsDO)) + CommandBindingCollection commandBindings = sender switch { - commandBindings = ((ContentElement)senderAsDO).CommandBindingsInternal; - } - else if (InputElement.IsUIElement3D(senderAsDO)) - { - commandBindings = ((UIElement3D)senderAsDO).CommandBindingsInternal; - } - if (commandBindings != null) + UIElement uiElement => uiElement.CommandBindingsInternal, + ContentElement contentElement => contentElement.CommandBindingsInternal, + UIElement3D uiElement3d => uiElement3d.CommandBindingsInternal, + _ => default + }; + if (commandBindings is not null) { FindCommandBinding(commandBindings, sender, e, command, execute); } + Type senderType = sender.GetType(); + // If no command binding is found, check class command bindings // First find the relevant command bindings, under the lock. // Most of the time there are no such bindings; most of the rest of // the time there is only one. Lazy-allocate with this in mind. - Tuple tuple = null; // zero or one binding - List> list = null; // more than one - + ValueTuple? tuple = default; // zero or one binding + List> list = default; // more than one + lock (_classCommandBindings.SyncRoot) { // Check from the current type to all the base types - Type classType = sender.GetType(); - while (classType != null) + Type classType = senderType; + while (classType is not null) { - CommandBindingCollection classCommandBindings = _classCommandBindings[classType] as CommandBindingCollection; - if (classCommandBindings != null) + if (_classCommandBindings[classType] is CommandBindingCollection classCommandBindings) { int index = 0; while (true) { CommandBinding commandBinding = classCommandBindings.FindMatch(command, ref index); - if (commandBinding != null) + if (commandBinding is null) { - if (tuple == null) - { - tuple = new Tuple(classType, commandBinding); - } - else - { - if (list == null) - { - list = new List>(); - list.Add(tuple); - } - list.Add(new Tuple(classType, commandBinding)); - } + break; + } + + if (tuple is null) + { + tuple = ValueTuple.Create(classType, commandBinding); } else { - break; + list ??= new List>(8) + { + // We know that tuple cannot be null here + tuple.Value + }; + list.Add(new ValueTuple(classType, commandBinding)); } } } @@ -666,37 +660,35 @@ private static void FindCommandBinding(object sender, RoutedEventArgs e, IComman // execute the bindings. This can call into user code, so it must // be done outside the lock to avoid deadlock. - if (list != null) + if (list is not null) { // more than one binding - ExecutedRoutedEventArgs exArgs = execute ? (ExecutedRoutedEventArgs)e : null; - CanExecuteRoutedEventArgs canExArgs = execute ? null : (CanExecuteRoutedEventArgs)e; - for (int i=0; i + _transformToDeviceMatrices[compositionTarget.CurrentDpiScale] = + compositionTarget.TransformToDevice); + } - toDevice = _transformToDeviceMatrices[hwndSource.CompositionTarget.CurrentDpiScale]; + Debug.Assert(_transformToDeviceMatrices[compositionTarget.CurrentDpiScale].HasInverse); + } + + toDevice = _transformToDeviceMatrices[compositionTarget.CurrentDpiScale]; + } } return toDevice; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPoint.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPoint.cs index 439b7195015..b384391bd4b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPoint.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Common/StylusPoint.cs @@ -694,16 +694,7 @@ internal bool HasDefaultPressure /// private void CopyAdditionalData() { - if (null != _additionalValues) - { - int[] newData = new int[_additionalValues.Length]; - for (int x = 0; x < _additionalValues.Length; x++) - { - newData[x] = _additionalValues[x]; - } - - _additionalValues = newData; - } + _additionalValues = (int[])_additionalValues?.Clone(); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Pointer/PointerLogic.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Pointer/PointerLogic.cs index 437e2e6732e..6f29645dcc8 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Pointer/PointerLogic.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Pointer/PointerLogic.cs @@ -530,48 +530,52 @@ internal override void UpdateStylusCapture(StylusDeviceBase stylusDevice, IInput if (oldCapture != null) { o = oldCapture as DependencyObject; - if (InputElement.IsUIElement(o)) + if (o is UIElement element) { - UIElement element = o as UIElement; element.IsEnabledChanged -= _captureIsEnabledChangedEventHandler; element.IsVisibleChanged -= _captureIsVisibleChangedEventHandler; element.IsHitTestVisibleChanged -= _captureIsHitTestVisibleChangedEventHandler; } - else if (InputElement.IsContentElement(o)) + else if (o is ContentElement ce) { // NOTE: there are no IsVisible or IsHitTestVisible properties for ContentElements. - ((ContentElement)o).IsEnabledChanged -= _captureIsEnabledChangedEventHandler; + ce.IsEnabledChanged -= _captureIsEnabledChangedEventHandler; + } + else if (o is UIElement3D element3D) + { + element3D.IsEnabledChanged -= _captureIsEnabledChangedEventHandler; + element3D.IsVisibleChanged -= _captureIsVisibleChangedEventHandler; + element3D.IsHitTestVisibleChanged -= _captureIsHitTestVisibleChangedEventHandler; } else { - UIElement3D element = o as UIElement3D; - element.IsEnabledChanged -= _captureIsEnabledChangedEventHandler; - element.IsVisibleChanged -= _captureIsVisibleChangedEventHandler; - element.IsHitTestVisibleChanged -= _captureIsHitTestVisibleChangedEventHandler; + throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, oldCapture.GetType())); } } if (_stylusCapture != null) { o = _stylusCapture as DependencyObject; - if (InputElement.IsUIElement(o)) + if (o is UIElement element) { - UIElement element = o as UIElement; element.IsEnabledChanged += _captureIsEnabledChangedEventHandler; element.IsVisibleChanged += _captureIsVisibleChangedEventHandler; element.IsHitTestVisibleChanged += _captureIsHitTestVisibleChangedEventHandler; } - else if (InputElement.IsContentElement(o)) + else if (o is ContentElement ce) { // NOTE: there are no IsVisible or IsHitTestVisible properties for ContentElements. - ((ContentElement)o).IsEnabledChanged += _captureIsEnabledChangedEventHandler; + ce.IsEnabledChanged += _captureIsEnabledChangedEventHandler; + } + else if (o is UIElement3D element3D) + { + element3D.IsEnabledChanged += _captureIsEnabledChangedEventHandler; + element3D.IsVisibleChanged += _captureIsVisibleChangedEventHandler; + element3D.IsHitTestVisibleChanged += _captureIsHitTestVisibleChangedEventHandler; } else { - UIElement3D element = o as UIElement3D; - element.IsEnabledChanged += _captureIsEnabledChangedEventHandler; - element.IsVisibleChanged += _captureIsVisibleChangedEventHandler; - element.IsHitTestVisibleChanged += _captureIsHitTestVisibleChangedEventHandler; + throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, _stylusCapture.GetType())); } } @@ -613,55 +617,59 @@ internal override void UpdateOverProperty(StylusDeviceBase stylusDevice, IInputE if (oldOver != null) { o = oldOver as DependencyObject; - if (InputElement.IsUIElement(o)) + if (o is UIElement element) { - UIElement element = o as UIElement; element.IsEnabledChanged -= _overIsEnabledChangedEventHandler; element.IsVisibleChanged -= _overIsVisibleChangedEventHandler; element.IsHitTestVisibleChanged -= _overIsHitTestVisibleChangedEventHandler; } - else if (InputElement.IsContentElement(o)) + else if (o is ContentElement ce) { - ((ContentElement)o).IsEnabledChanged -= _overIsEnabledChangedEventHandler; + ce.IsEnabledChanged -= _overIsEnabledChangedEventHandler; // NOTE: there are no IsVisible or IsHitTestVisible properties for ContentElements. // - // ((ContentElement)o).IsVisibleChanged -= _overIsVisibleChangedEventHandler; - // ((ContentElement)o).IsHitTestVisibleChanged -= _overIsHitTestVisibleChangedEventHandler; + // ce.IsVisibleChanged -= _overIsVisibleChangedEventHandler; + // ce.IsHitTestVisibleChanged -= _overIsHitTestVisibleChangedEventHandler; + } + else if (o is UIElement3D element3D) + { + element3D.IsEnabledChanged -= _overIsEnabledChangedEventHandler; + element3D.IsVisibleChanged -= _overIsVisibleChangedEventHandler; + element3D.IsHitTestVisibleChanged -= _overIsHitTestVisibleChangedEventHandler; } else { - UIElement3D element = o as UIElement3D; - element.IsEnabledChanged -= _overIsEnabledChangedEventHandler; - element.IsVisibleChanged -= _overIsVisibleChangedEventHandler; - element.IsHitTestVisibleChanged -= _overIsHitTestVisibleChangedEventHandler; + throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, oldOver.GetType())); } } if (_stylusOver != null) { o = _stylusOver as DependencyObject; - if (InputElement.IsUIElement(o)) + if (o is UIElement element) { - UIElement element = o as UIElement; element.IsEnabledChanged += _overIsEnabledChangedEventHandler; element.IsVisibleChanged += _overIsVisibleChangedEventHandler; element.IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler; } - else if (InputElement.IsContentElement(o)) + else if (o is ContentElement ce) { - ((ContentElement)o).IsEnabledChanged += _overIsEnabledChangedEventHandler; + ce.IsEnabledChanged += _overIsEnabledChangedEventHandler; // NOTE: there are no IsVisible or IsHitTestVisible properties for ContentElements. // - // ((ContentElement)o).IsVisibleChanged += _overIsVisibleChangedEventHandler; - // ((ContentElement)o).IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler; + // ce.IsVisibleChanged += _overIsVisibleChangedEventHandler; + // ce.IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler; + } + else if (o is UIElement3D element3D) + { + element3D.IsEnabledChanged += _overIsEnabledChangedEventHandler; + element3D.IsVisibleChanged += _overIsVisibleChangedEventHandler; + element3D.IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler; } else { - UIElement3D element = o as UIElement3D; - element.IsEnabledChanged += _overIsEnabledChangedEventHandler; - element.IsVisibleChanged += _overIsVisibleChangedEventHandler; - element.IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler; + throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, _stylusOver.GetType())); } } @@ -783,17 +791,21 @@ private object ReevaluateCaptureAsync(object arg) // First, check things like IsEnabled, IsVisible, etc. on a // UIElement vs. ContentElement basis. // - if (InputElement.IsUIElement(dependencyObject)) + if (dependencyObject is UIElement uie) + { + killCapture = !ValidateUIElementForCapture(uie); + } + else if (dependencyObject is ContentElement ce) { - killCapture = !ValidateUIElementForCapture((UIElement)_stylusCapture); + killCapture = !ValidateContentElementForCapture(ce); } - else if (InputElement.IsContentElement(dependencyObject)) + else if (dependencyObject is UIElement3D uie3D) { - killCapture = !ValidateContentElementForCapture((ContentElement)_stylusCapture); + killCapture = !ValidateUIElement3DForCapture(uie3D); } else { - killCapture = !ValidateUIElement3DForCapture((UIElement3D)_stylusCapture); + throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, _stylusCapture.GetType())); } // diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Pointer/PointerTabletDevice.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Pointer/PointerTabletDevice.cs index 9dc2bbeafc7..1a72a293563 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Pointer/PointerTabletDevice.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Pointer/PointerTabletDevice.cs @@ -121,13 +121,9 @@ private void BuildStylusDevices() /// /// Updates the various size parameters for drag/drop/tap. /// - /// - /// internal void UpdateSizeDeltas() { // Query default settings for mouse drag and double tap (with minimum of 1x1 size). - Size mouseDragDefault = new Size(Math.Max(1, MS.Win32.SafeSystemMetrics.DragDeltaX / 2), - Math.Max(1, MS.Win32.SafeSystemMetrics.DragDeltaY / 2)); Size mouseDoubleTapDefault = new Size(Math.Max(1, MS.Win32.SafeSystemMetrics.DoubleClickDeltaX / 2), Math.Max(1, MS.Win32.SafeSystemMetrics.DoubleClickDeltaY / 2)); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/PenContexts.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/PenContexts.cs index 35f433daef4..17446dcfe8d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/PenContexts.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/PenContexts.cs @@ -440,7 +440,7 @@ internal void InvokeStylusPluginCollection(RawStylusInputReport inputReport) { // Create new RawStylusInput to send GeneralTransformGroup transformTabletToView = new GeneralTransformGroup(); - transformTabletToView.Children.Add(new MatrixTransform(_stylusLogic.GetTabletToViewTransform(stylusDevice.CriticalActiveSource ?? inputReport.InputSource, stylusDevice.TabletDevice))); // this gives matrix in measured units (not device) + transformTabletToView.Children.Add(new MatrixTransform(_stylusLogic.GetTabletToViewTransform(inputReport.InputSource, stylusDevice.TabletDevice))); // this gives matrix in measured units (not device) transformTabletToView.Children.Add(currentPic.ViewToElement); // Make it relative to the element. transformTabletToView.Freeze(); // Must be frozen for multi-threaded access. @@ -459,7 +459,7 @@ internal void InvokeStylusPluginCollection(RawStylusInputReport inputReport) // The transformTabletToView matrix and plugincollection rects though can change based // off of layout events which is why we need to lock this. GeneralTransformGroup transformTabletToView = new GeneralTransformGroup(); - transformTabletToView.Children.Add(new MatrixTransform(_stylusLogic.GetTabletToViewTransform(stylusDevice.CriticalActiveSource ?? inputReport.InputSource, stylusDevice.TabletDevice))); // this gives matrix in measured units (not device) + transformTabletToView.Children.Add(new MatrixTransform(_stylusLogic.GetTabletToViewTransform(inputReport.InputSource, stylusDevice.TabletDevice))); // this gives matrix in measured units (not device) transformTabletToView.Children.Add(pic.ViewToElement); // Make it relative to the element. transformTabletToView.Freeze(); // Must be frozen for multi-threaded access. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs index 07fde1dd090..5d089505bb9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispLogic.cs @@ -2059,51 +2059,59 @@ internal override void UpdateStylusCapture(StylusDeviceBase stylusDevice, IInput if (oldCapture != null) { o = oldCapture as DependencyObject; - if (InputElement.IsUIElement(o)) + if (o is UIElement uie) { - ((UIElement)o).IsEnabledChanged -= _captureIsEnabledChangedEventHandler; - ((UIElement)o).IsVisibleChanged -= _captureIsVisibleChangedEventHandler; - ((UIElement)o).IsHitTestVisibleChanged -= _captureIsHitTestVisibleChangedEventHandler; + uie.IsEnabledChanged -= _captureIsEnabledChangedEventHandler; + uie.IsVisibleChanged -= _captureIsVisibleChangedEventHandler; + uie.IsHitTestVisibleChanged -= _captureIsHitTestVisibleChangedEventHandler; } - else if (InputElement.IsContentElement(o)) + else if (o is ContentElement ce) { - ((ContentElement)o).IsEnabledChanged -= _captureIsEnabledChangedEventHandler; + ce.IsEnabledChanged -= _captureIsEnabledChangedEventHandler; // NOTE: there are no IsVisible or IsHitTestVisible properties for ContentElements. // - // ((ContentElement)o).IsVisibleChanged -= _captureIsVisibleChangedEventHandler; - // ((ContentElement)o).IsHitTestVisibleChanged -= _captureIsHitTestVisibleChangedEventHandler; + // ce.IsVisibleChanged -= _captureIsVisibleChangedEventHandler; + // ce.IsHitTestVisibleChanged -= _captureIsHitTestVisibleChangedEventHandler; + } + else if (o is UIElement3D uie3D) + { + uie3D.IsEnabledChanged -= _captureIsEnabledChangedEventHandler; + uie3D.IsVisibleChanged -= _captureIsVisibleChangedEventHandler; + uie3D.IsHitTestVisibleChanged -= _captureIsHitTestVisibleChangedEventHandler; } else { - ((UIElement3D)o).IsEnabledChanged -= _captureIsEnabledChangedEventHandler; - ((UIElement3D)o).IsVisibleChanged -= _captureIsVisibleChangedEventHandler; - ((UIElement3D)o).IsHitTestVisibleChanged -= _captureIsHitTestVisibleChangedEventHandler; + throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, oldCapture.GetType())); } } if (_stylusCapture != null) { o = _stylusCapture as DependencyObject; - if (InputElement.IsUIElement(o)) + if (o is UIElement uie) { - ((UIElement)o).IsEnabledChanged += _captureIsEnabledChangedEventHandler; - ((UIElement)o).IsVisibleChanged += _captureIsVisibleChangedEventHandler; - ((UIElement)o).IsHitTestVisibleChanged += _captureIsHitTestVisibleChangedEventHandler; + uie.IsEnabledChanged += _captureIsEnabledChangedEventHandler; + uie.IsVisibleChanged += _captureIsVisibleChangedEventHandler; + uie.IsHitTestVisibleChanged += _captureIsHitTestVisibleChangedEventHandler; } - else if (InputElement.IsContentElement(o)) + else if (o is ContentElement ce) { - ((ContentElement)o).IsEnabledChanged += _captureIsEnabledChangedEventHandler; + ce.IsEnabledChanged += _captureIsEnabledChangedEventHandler; // NOTE: there are no IsVisible or IsHitTestVisible properties for ContentElements. // - // ((ContentElement)o).IsVisibleChanged += _captureIsVisibleChangedEventHandler; - // ((ContentElement)o).IsHitTestVisibleChanged += _captureIsHitTestVisibleChangedEventHandler; + // ce.IsVisibleChanged += _captureIsVisibleChangedEventHandler; + // ce.IsHitTestVisibleChanged += _captureIsHitTestVisibleChangedEventHandler; + } + else if (o is UIElement3D uie3D) + { + uie3D.IsEnabledChanged += _captureIsEnabledChangedEventHandler; + uie3D.IsVisibleChanged += _captureIsVisibleChangedEventHandler; + uie3D.IsHitTestVisibleChanged += _captureIsHitTestVisibleChangedEventHandler; } else { - ((UIElement3D)o).IsEnabledChanged += _captureIsEnabledChangedEventHandler; - ((UIElement3D)o).IsVisibleChanged += _captureIsVisibleChangedEventHandler; - ((UIElement3D)o).IsHitTestVisibleChanged += _captureIsHitTestVisibleChangedEventHandler; + throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, _stylusCapture.GetType())); } } @@ -2139,51 +2147,59 @@ internal override void UpdateOverProperty(StylusDeviceBase stylusDevice, IInputE if (oldOver != null) { o = oldOver as DependencyObject; - if (InputElement.IsUIElement(o)) + if (o is UIElement uie) { - ((UIElement)o).IsEnabledChanged -= _overIsEnabledChangedEventHandler; - ((UIElement)o).IsVisibleChanged -= _overIsVisibleChangedEventHandler; - ((UIElement)o).IsHitTestVisibleChanged -= _overIsHitTestVisibleChangedEventHandler; + uie.IsEnabledChanged -= _overIsEnabledChangedEventHandler; + uie.IsVisibleChanged -= _overIsVisibleChangedEventHandler; + uie.IsHitTestVisibleChanged -= _overIsHitTestVisibleChangedEventHandler; } - else if (InputElement.IsContentElement(o)) + else if (o is ContentElement ce) { - ((ContentElement)o).IsEnabledChanged -= _overIsEnabledChangedEventHandler; + ce.IsEnabledChanged -= _overIsEnabledChangedEventHandler; // NOTE: there are no IsVisible or IsHitTestVisible properties for ContentElements. // - // ((ContentElement)o).IsVisibleChanged -= _overIsVisibleChangedEventHandler; - // ((ContentElement)o).IsHitTestVisibleChanged -= _overIsHitTestVisibleChangedEventHandler; + // ce.IsVisibleChanged -= _overIsVisibleChangedEventHandler; + // ce.IsHitTestVisibleChanged -= _overIsHitTestVisibleChangedEventHandler; + } + else if (o is UIElement3D uie3D) + { + uie3D.IsEnabledChanged -= _overIsEnabledChangedEventHandler; + uie3D.IsVisibleChanged -= _overIsVisibleChangedEventHandler; + uie3D.IsHitTestVisibleChanged -= _overIsHitTestVisibleChangedEventHandler; } else { - ((UIElement3D)o).IsEnabledChanged -= _overIsEnabledChangedEventHandler; - ((UIElement3D)o).IsVisibleChanged -= _overIsVisibleChangedEventHandler; - ((UIElement3D)o).IsHitTestVisibleChanged -= _overIsHitTestVisibleChangedEventHandler; + throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, oldOver.GetType())); } } if (_stylusOver != null) { o = _stylusOver as DependencyObject; - if (InputElement.IsUIElement(o)) + if (o is UIElement uie) { - ((UIElement)o).IsEnabledChanged += _overIsEnabledChangedEventHandler; - ((UIElement)o).IsVisibleChanged += _overIsVisibleChangedEventHandler; - ((UIElement)o).IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler; + uie.IsEnabledChanged += _overIsEnabledChangedEventHandler; + uie.IsVisibleChanged += _overIsVisibleChangedEventHandler; + uie.IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler; } - else if (InputElement.IsContentElement(o)) + else if (o is ContentElement ce) { - ((ContentElement)o).IsEnabledChanged += _overIsEnabledChangedEventHandler; + ce.IsEnabledChanged += _overIsEnabledChangedEventHandler; // NOTE: there are no IsVisible or IsHitTestVisible properties for ContentElements. // - // ((ContentElement)o).IsVisibleChanged += _overIsVisibleChangedEventHandler; - // ((ContentElement)o).IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler; + // ce.IsVisibleChanged += _overIsVisibleChangedEventHandler; + // ce.IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler; + } + else if (o is UIElement3D uie3D) + { + uie3D.IsEnabledChanged += _overIsEnabledChangedEventHandler; + uie3D.IsVisibleChanged += _overIsVisibleChangedEventHandler; + uie3D.IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler; } else { - ((UIElement3D)o).IsEnabledChanged += _overIsEnabledChangedEventHandler; - ((UIElement3D)o).IsVisibleChanged += _overIsVisibleChangedEventHandler; - ((UIElement3D)o).IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler; + throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, _stylusOver.GetType())); } } @@ -2409,17 +2425,21 @@ private object ReevaluateCaptureAsync(object arg) // First, check things like IsEnabled, IsVisible, etc. on a // UIElement vs. ContentElement basis. // - if (InputElement.IsUIElement(dependencyObject)) + if (dependencyObject is UIElement uie) + { + killCapture = !ValidateUIElementForCapture(uie); + } + else if (dependencyObject is ContentElement ce) { - killCapture = !ValidateUIElementForCapture((UIElement)_stylusCapture); + killCapture = !ValidateContentElementForCapture(ce); } - else if (InputElement.IsContentElement(dependencyObject)) + else if (dependencyObject is UIElement3D uie3D) { - killCapture = !ValidateContentElementForCapture((ContentElement)_stylusCapture); + killCapture = !ValidateUIElement3DForCapture(uie3D); } else { - killCapture = !ValidateUIElement3DForCapture((UIElement3D)_stylusCapture); + throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, _stylusCapture.GetType())); } // @@ -2670,8 +2690,7 @@ private void VerifyStylusPlugInCollectionTarget(RawStylusInputReport rawStylusIn // The transformTabletToView matrix and plugincollection rects though can change based // off of layout events which is why we need to lock this. GeneralTransformGroup transformTabletToView = new GeneralTransformGroup(); - transformTabletToView.Children.Add(new MatrixTransform(GetTabletToViewTransform( - stylusDevice.CriticalActiveSource ?? rawStylusInputReport.InputSource, stylusDevice.TabletDevice))); // this gives matrix in measured units (not device) + transformTabletToView.Children.Add(new MatrixTransform(GetTabletToViewTransform(rawStylusInputReport.InputSource, stylusDevice.TabletDevice))); // this gives matrix in measured units (not device) transformTabletToView.Children.Add(targetPIC.ViewToElement); // Make it relative to the element. transformTabletToView.Freeze(); // Must be frozen for multi-threaded access. @@ -2690,7 +2709,7 @@ private void VerifyStylusPlugInCollectionTarget(RawStylusInputReport rawStylusIn if (originalRSI == null) { GeneralTransformGroup transformTabletToView = new GeneralTransformGroup(); - transformTabletToView.Children.Add(new MatrixTransform(GetTabletToViewTransform(stylusDevice.CriticalActiveSource ?? rawStylusInputReport.InputSource, stylusDevice.TabletDevice))); // this gives matrix in measured units (not device) + transformTabletToView.Children.Add(new MatrixTransform(GetTabletToViewTransform(rawStylusInputReport.InputSource, stylusDevice.TabletDevice))); // this gives matrix in measured units (not device) transformTabletToView.Children.Add(currentTarget.ViewToElement); // Make it relative to the element. transformTabletToView.Freeze(); // Must be frozen for multi-threaded access. originalRSI = new RawStylusInput(rawStylusInputReport, transformTabletToView, currentTarget); @@ -3674,11 +3693,11 @@ internal long IncrementVersion() bool _inputEnabled = false; bool _updatingScreenMeasurements = false; DispatcherOperationCallback _processDisplayChanged; - object __penContextsLock = new object(); + readonly object __penContextsLock = new object(); Dictionary __penContextsMap = new Dictionary(2); - object __stylusDeviceLock = new object(); + readonly object __stylusDeviceLock = new object(); Dictionary __stylusDeviceMap = new Dictionary(2); bool _inDragDrop; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispStylusDevice.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispStylusDevice.cs index bf933843a7c..1f3125ee99d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispStylusDevice.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispStylusDevice.cs @@ -418,51 +418,59 @@ private void UpdateOverProperty(IInputElement oldOver, IInputElement newOver) if (oldOver != null) { o = oldOver as DependencyObject; - if (InputElement.IsUIElement(o)) + if (o is UIElement uie) { - ((UIElement)o).IsEnabledChanged -= _overIsEnabledChangedEventHandler; - ((UIElement)o).IsVisibleChanged -= _overIsVisibleChangedEventHandler; - ((UIElement)o).IsHitTestVisibleChanged -= _overIsHitTestVisibleChangedEventHandler; + uie.IsEnabledChanged -= _overIsEnabledChangedEventHandler; + uie.IsVisibleChanged -= _overIsVisibleChangedEventHandler; + uie.IsHitTestVisibleChanged -= _overIsHitTestVisibleChangedEventHandler; } - else if (InputElement.IsContentElement(o)) + else if (o is ContentElement ce) { - ((ContentElement)o).IsEnabledChanged -= _overIsEnabledChangedEventHandler; + ce.IsEnabledChanged -= _overIsEnabledChangedEventHandler; // NOTE: there are no IsVisible or IsHitTestVisible properties for ContentElements. // - // ((ContentElement)o).IsVisibleChanged -= _overIsVisibleChangedEventHandler; - // ((ContentElement)o).IsHitTestVisibleChanged -= _overIsHitTestVisibleChangedEventHandler; + // ce.IsVisibleChanged -= _overIsVisibleChangedEventHandler; + // ce.IsHitTestVisibleChanged -= _overIsHitTestVisibleChangedEventHandler; + } + else if (o is UIElement3D uie3D) + { + uie3D.IsEnabledChanged -= _overIsEnabledChangedEventHandler; + uie3D.IsVisibleChanged -= _overIsVisibleChangedEventHandler; + uie3D.IsHitTestVisibleChanged -= _overIsHitTestVisibleChangedEventHandler; } else { - ((UIElement3D)o).IsEnabledChanged -= _overIsEnabledChangedEventHandler; - ((UIElement3D)o).IsVisibleChanged -= _overIsVisibleChangedEventHandler; - ((UIElement3D)o).IsHitTestVisibleChanged -= _overIsHitTestVisibleChangedEventHandler; + throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, oldOver.GetType())); } } if (_stylusOver != null) { o = _stylusOver as DependencyObject; - if (InputElement.IsUIElement(o)) + if (o is UIElement uie) { - ((UIElement)o).IsEnabledChanged += _overIsEnabledChangedEventHandler; - ((UIElement)o).IsVisibleChanged += _overIsVisibleChangedEventHandler; - ((UIElement)o).IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler; + uie.IsEnabledChanged += _overIsEnabledChangedEventHandler; + uie.IsVisibleChanged += _overIsVisibleChangedEventHandler; + uie.IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler; } - else if (InputElement.IsContentElement(o)) + else if (o is ContentElement ce) { - ((ContentElement)o).IsEnabledChanged += _overIsEnabledChangedEventHandler; + ce.IsEnabledChanged += _overIsEnabledChangedEventHandler; // NOTE: there are no IsVisible or IsHitTestVisible properties for ContentElements. // - // ((ContentElement)o).IsVisibleChanged += _overIsVisibleChangedEventHandler; - // ((ContentElement)o).IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler; + // ce.IsVisibleChanged += _overIsVisibleChangedEventHandler; + // ce.IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler; + } + else if (o is UIElement3D uie3D) + { + uie3D.IsEnabledChanged += _overIsEnabledChangedEventHandler; + uie3D.IsVisibleChanged += _overIsVisibleChangedEventHandler; + uie3D.IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler; } else { - ((UIElement3D)o).IsEnabledChanged += _overIsEnabledChangedEventHandler; - ((UIElement3D)o).IsVisibleChanged += _overIsVisibleChangedEventHandler; - ((UIElement3D)o).IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler; + throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, _stylusOver.GetType())); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/RepeatBehavior.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/RepeatBehavior.cs index 97eb874841b..4d1292e36c0 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/RepeatBehavior.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/RepeatBehavior.cs @@ -48,7 +48,7 @@ public struct RepeatBehavior : IFormattable public RepeatBehavior(double count) { if ( Double.IsInfinity(count) - || DoubleUtil.IsNaN(count) + || double.IsNaN(count) || count < 0.0) { throw new ArgumentOutOfRangeException("count", SR.Get(SRID.Timing_RepeatBehaviorInvalidIterationCount, count)); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/ShaderEffect.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/ShaderEffect.cs index d7b8a191096..6e4f4fa01bb 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/ShaderEffect.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Effects/ShaderEffect.cs @@ -436,11 +436,10 @@ private void UpdateShaderSampler(DependencyProperty dp, object newValue, int reg if (newValue != null) { - if (!(typeof(VisualBrush).IsInstanceOfType(newValue) || - typeof(BitmapCacheBrush).IsInstanceOfType(newValue) || - typeof(ImplicitInputBrush).IsInstanceOfType(newValue) || - typeof(ImageBrush).IsInstanceOfType(newValue)) - ) + if (newValue is not VisualBrush + and not BitmapCacheBrush + and not ImplicitInputBrush + and not ImageBrush) { // Note that if the type of the brush is ImplicitInputBrush and the value is non null, the value is actually // Effect.ImplicitInput. This is because ImplicitInputBrush is internal and the user can only get to the singleton diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FactoryMaker.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FactoryMaker.cs index 174a6f4ffa7..5f81b1f1f0c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FactoryMaker.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FactoryMaker.cs @@ -139,7 +139,7 @@ internal IntPtr ImagingFactoryPtr /// "FactoryMaker" is free threaded. This lock is used to synchronize /// access to the FactoryMaker. /// - private static object s_factoryMakerLock = new object(); + private static readonly object s_factoryMakerLock = new object(); private bool _fValidObject; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FormattedText.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FormattedText.cs index 6648abfd343..deb286cd8e1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FormattedText.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/FormattedText.cs @@ -300,7 +300,7 @@ private static void ValidateFontSize(double emSize) if (emSize > MaxFontEmSize) throw new ArgumentOutOfRangeException("emSize", SR.Get(SRID.ParameterCannotBeGreaterThan, MaxFontEmSize)); - if (DoubleUtil.IsNaN(emSize)) + if (double.IsNaN(emSize)) throw new ArgumentOutOfRangeException("emSize", SR.Get(SRID.ParameterValueCannotBeNaN)); } @@ -1359,7 +1359,7 @@ public double MaxTextHeight if (value <= 0) throw new ArgumentOutOfRangeException("value", SR.Get(SRID.PropertyMustBeGreaterThanZero, "MaxTextHeight")); - if (DoubleUtil.IsNaN(value)) + if (double.IsNaN(value)) throw new ArgumentOutOfRangeException("value", SR.Get(SRID.PropertyValueCannotBeNaN, "MaxTextHeight")); _maxTextHeight = value; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphRun.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphRun.cs index 4a7304aec3b..71fa960f599 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphRun.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphRun.cs @@ -454,7 +454,7 @@ TextFormattingMode textFormattingMode } else { - if (DoubleUtil.IsNaN(renderingEmSize)) + if (double.IsNaN(renderingEmSize)) throw new ArgumentOutOfRangeException("renderingEmSize", SR.Get(SRID.ParameterValueCannotBeNaN)); if (renderingEmSize < 0.0) @@ -1781,11 +1781,11 @@ internal Scale(ref Matrix matrix) _baseVectorX = Math.Sqrt(m11 * m11 + m12 * m12); // Check for wrong matrix. - if (DoubleUtil.IsNaN(_baseVectorX)) + if (double.IsNaN(_baseVectorX)) _baseVectorX = 0; _baseVectorY = _baseVectorX == 0 ? 0 : Math.Abs(m11 * m22 - m12 * m21) / _baseVectorX; - if (DoubleUtil.IsNaN(_baseVectorY)) + if (double.IsNaN(_baseVectorY)) _baseVectorY = 0; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDecoder.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDecoder.cs index 165353e529d..8425e15feac 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDecoder.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDecoder.cs @@ -1687,7 +1687,7 @@ internal bool CanConvertToString() internal UniqueEventHelper _failedEvent = new UniqueEventHelper(); /// SyncObject - private object _syncObject = new Object(); + private readonly object _syncObject = new Object(); // For UnmanagedMemoryStream we want to make sure that buffer // its pointing to is not getting release until decoder is alive diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDownload.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDownload.cs index a51d8c40ba2..c973be56c8b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDownload.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/BitmapDownload.cs @@ -472,7 +472,7 @@ Exception e private static Thread _thread; /// lock object - private static object _syncLock; + private static readonly object _syncLock; /// Default async read size private const int READ_SIZE = 1024; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ParsersCommon.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ParsersCommon.cs index 10fbabc394f..0918c796f4b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ParsersCommon.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/ParsersCommon.cs @@ -435,6 +435,7 @@ double ReadNumber(bool allowComma) } else { +#if NETFRAMEWORK string subString = _pathString.Substring(start, _curIndex - start); try @@ -445,6 +446,17 @@ double ReadNumber(bool allowComma) { throw new System.FormatException(SR.Get(SRID.Parser_UnexpectedToken, _pathString, start), except); } +#else + var span = _pathString.AsSpan(start, _curIndex - start); + try + { + return double.Parse(span, provider: _formatProvider); + } + catch (FormatException except) + { + throw new System.FormatException(SR.Get(SRID.Parser_UnexpectedToken, _pathString, start), except); + } +#endif } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/VisualTreeHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/VisualTreeHelper.cs index 3d8d9e3b2db..a9356fdfe5f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/VisualTreeHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/VisualTreeHelper.cs @@ -254,14 +254,11 @@ internal static bool IsAncestorOf(DependencyObject ancestor, DependencyObject de while ((current != null) && (current != ancestor) && !stopType.IsInstanceOfType(current)) { - Visual visual; - Visual3D visual3D; - - if ((visual = current as Visual) != null) + if (current is Visual visual) { current = visual.InternalVisualParent; } - else if ((visual3D = current as Visual3D) != null) + else if (current is Visual3D visual3D) { current = visual3D.InternalVisualParent; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextFormatter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextFormatter.cs index 978962b62a7..f732c25d926 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextFormatter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextFormatter.cs @@ -35,7 +35,7 @@ namespace System.Windows.Media.TextFormatting /// public abstract class TextFormatter : IDisposable { - private static object _staticLock = new object(); + private static readonly object _staticLock = new object(); /// /// Client to create a new instance of TextFormatter diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextParagraphCache.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextParagraphCache.cs index 2b0febfac08..c02abdd3f3b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextParagraphCache.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/textformatting/TextParagraphCache.cs @@ -178,7 +178,7 @@ private void Dispose(bool disposing) /// private int VerifyMaxLineWidth(double maxLineWidth) { - if (DoubleUtil.IsNaN(maxLineWidth)) + if (double.IsNaN(maxLineWidth)) throw new ArgumentOutOfRangeException("maxLineWidth", SR.Get(SRID.ParameterValueCannotBeNaN)); if (maxLineWidth == 0 || double.IsPositiveInfinity(maxLineWidth)) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/PresentationSource.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/PresentationSource.cs index 5a167579145..41515937df3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/PresentationSource.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/PresentationSource.cs @@ -145,9 +145,8 @@ public static void AddSourceChangedHandler(IInputElement element, SourceChangedE { FrugalObjectList info; - if (InputElement.IsUIElement(o)) + if (o is UIElement uie) { - UIElement uie = o as UIElement; uie.AddHandler(SourceChangedEvent, handler); info = uie.EventHandlersStore[SourceChangedEvent]; if (1 == info.Count) @@ -156,9 +155,8 @@ public static void AddSourceChangedHandler(IInputElement element, SourceChangedE AddElementToWatchList(uie); } } - else if (InputElement.IsUIElement3D(o)) + else if (o is UIElement3D uie3D) { - UIElement3D uie3D = o as UIElement3D; uie3D.AddHandler(SourceChangedEvent, handler); info = uie3D.EventHandlersStore[SourceChangedEvent]; if (1 == info.Count) @@ -167,13 +165,18 @@ public static void AddSourceChangedHandler(IInputElement element, SourceChangedE AddElementToWatchList(uie3D); } } - else + else if (o is ContentElement ce) { - ContentElement ce = o as ContentElement; ce.AddHandler(SourceChangedEvent, handler); info = ce.EventHandlersStore[SourceChangedEvent]; if (1 == info.Count) + { AddElementToWatchList(ce); + } + } + else + { + throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, o.GetType())); } } } @@ -211,9 +214,8 @@ public static void RemoveSourceChangedHandler(IInputElement e, SourceChangedEven EventHandlersStore store; // Either UIElement or ContentElement. - if (InputElement.IsUIElement(o)) + if (o is UIElement uie) { - UIElement uie = o as UIElement; uie.RemoveHandler(SourceChangedEvent, handler); store = uie.EventHandlersStore; if (store != null) @@ -226,9 +228,8 @@ public static void RemoveSourceChangedHandler(IInputElement e, SourceChangedEven RemoveElementFromWatchList(uie); } } - else if (InputElement.IsUIElement3D(o)) + else if (o is UIElement3D uie3D) { - UIElement3D uie3D = o as UIElement3D; uie3D.RemoveHandler(SourceChangedEvent, handler); store = uie3D.EventHandlersStore; if (store != null) @@ -241,9 +242,8 @@ public static void RemoveSourceChangedHandler(IInputElement e, SourceChangedEven RemoveElementFromWatchList(uie3D); } } - else + else if (o is ContentElement ce) { - ContentElement ce = o as ContentElement; ce.RemoveHandler(SourceChangedEvent, handler); store = ce.EventHandlersStore; if (store != null) @@ -255,6 +255,10 @@ public static void RemoveSourceChangedHandler(IInputElement e, SourceChangedEven RemoveElementFromWatchList(ce); } } + else + { + throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, o.GetType())); + } } } @@ -548,7 +552,7 @@ protected void ClearContentRenderedListeners() /// Event Args. internal static void OnVisualAncestorChanged(DependencyObject uie, AncestorChangedEventArgs e) { - Debug.Assert(InputElement.IsUIElement3D(uie) || InputElement.IsUIElement(uie)); + Debug.Assert(uie is UIElement3D or UIElement); if (true == (bool)uie.GetValue(GetsSourceChangedEventProperty)) { @@ -740,17 +744,21 @@ private static bool UpdateSourceOfElement(DependencyObject doTarget, SourceChangedEventArgs args = new SourceChangedEventArgs(cachedSource, realSource); args.RoutedEvent=SourceChangedEvent; - if (InputElement.IsUIElement(doTarget)) + if (doTarget is UIElement uiElement) { - ((UIElement)doTarget).RaiseEvent(args); + uiElement.RaiseEvent(args); } - else if (InputElement.IsContentElement(doTarget)) + else if (doTarget is ContentElement contentElement) + { + contentElement.RaiseEvent(args); + } + else if (doTarget is UIElement3D uiElement3D) { - ((ContentElement)doTarget).RaiseEvent(args); + uiElement3D.RaiseEvent(args); } else { - ((UIElement3D)doTarget).RaiseEvent(args); + throw new InvalidOperationException(SR.Get(SRID.Invalid_IInputElement, doTarget.GetType())); } calledOut = true; @@ -792,7 +800,7 @@ private static readonly DependencyProperty CachedSourceProperty private static readonly RoutedEvent SourceChangedEvent = EventManager.RegisterRoutedEvent("SourceChanged", RoutingStrategy.Direct, typeof(SourceChangedEventHandler), typeof(PresentationSource)); // The lock we use to protect our static data. - private static object _globalLock = new object(); + private static readonly object _globalLock = new object(); // An array of weak-references to sources that we know about. private static WeakReferenceList _sources = new WeakReferenceList(_globalLock); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement.cs index 5ffd03107f9..49d9a88f4f3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement.cs @@ -585,7 +585,7 @@ public void Measure(Size availableSize) using (Dispatcher.DisableProcessing()) { //enforce that Measure can not receive NaN size . - if (DoubleUtil.IsNaN(availableSize.Width) || DoubleUtil.IsNaN(availableSize.Height)) + if (double.IsNaN(availableSize.Width) || double.IsNaN(availableSize.Height)) throw new InvalidOperationException(SR.Get(SRID.UIElement_Layout_NaNMeasure)); bool neverMeasured = NeverMeasured; @@ -682,7 +682,7 @@ public void Measure(Size availableSize) throw new InvalidOperationException(SR.Get(SRID.UIElement_Layout_PositiveInfinityReturned, this.GetType().FullName)); //enforce that MeasureCore can not return NaN size . - if (DoubleUtil.IsNaN(desiredSize.Width) || DoubleUtil.IsNaN(desiredSize.Height)) + if (double.IsNaN(desiredSize.Width) || double.IsNaN(desiredSize.Height)) throw new InvalidOperationException(SR.Get(SRID.UIElement_Layout_NaNReturned, this.GetType().FullName)); //reset measure dirtiness @@ -801,8 +801,8 @@ public void Arrange(Rect finalRect) //enforce that Arrange can not come with Infinity size or NaN if (double.IsPositiveInfinity(finalRect.Width) || double.IsPositiveInfinity(finalRect.Height) - || DoubleUtil.IsNaN(finalRect.Width) - || DoubleUtil.IsNaN(finalRect.Height) + || double.IsNaN(finalRect.Width) + || double.IsNaN(finalRect.Height) ) { DependencyObject parent = GetUIParent() as UIElement; @@ -1095,7 +1095,7 @@ internal static double RoundLayoutValue(double value, double dpiScale) { newValue = Math.Round(value * dpiScale) / dpiScale; // If rounding produces a value unacceptable to layout (NaN, Infinity or MaxValue), use the original value. - if (DoubleUtil.IsNaN(newValue) || + if (double.IsNaN(newValue) || Double.IsInfinity(newValue) || DoubleUtil.AreClose(newValue, Double.MaxValue)) { @@ -1403,8 +1403,8 @@ private static void RenderTransform_Changed(DependencyObject d, DependencyProper private static bool IsRenderTransformOriginValid(object value) { Point v = (Point)value; - return ( (!DoubleUtil.IsNaN(v.X) && !Double.IsPositiveInfinity(v.X) && !Double.IsNegativeInfinity(v.X)) - && (!DoubleUtil.IsNaN(v.Y) && !Double.IsPositiveInfinity(v.Y) && !Double.IsNegativeInfinity(v.Y))); + return ( (!double.IsNaN(v.X) && !Double.IsPositiveInfinity(v.X) && !Double.IsNegativeInfinity(v.X)) + && (!double.IsNaN(v.Y) && !Double.IsPositiveInfinity(v.Y) && !Double.IsNegativeInfinity(v.Y))); } @@ -1443,7 +1443,7 @@ protected internal override void OnVisualParentChanged(DependencyObject oldParen { DependencyObject parent = _parent; - if (!InputElement.IsUIElement(parent) && !InputElement.IsUIElement3D(parent)) + if (parent is not UIElement and not UIElement3D) { Visual parentAsVisual = parent as Visual; @@ -1490,7 +1490,7 @@ protected internal override void OnVisualParentChanged(DependencyObject oldParen { DependencyObject parent = oldParent; - if (!InputElement.IsUIElement(parent) && !InputElement.IsUIElement3D(parent)) + if (parent is not UIElement and not UIElement3D) { // We are being unplugged from a non-UIElement visual. This // means that our parent didn't play by the same rules we diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement3D.cs b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement3D.cs index f6761dfe11d..33efb11b54f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement3D.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement3D.cs @@ -148,7 +148,7 @@ protected internal override void OnVisualParentChanged(DependencyObject oldParen { DependencyObject parent = InternalVisualParent; - if (!InputElement.IsUIElement(parent) && !InputElement.IsUIElement3D(parent)) + if (parent is not UIElement and not UIElement3D) { Visual parentAsVisual = parent as Visual; @@ -192,7 +192,7 @@ protected internal override void OnVisualParentChanged(DependencyObject oldParen { DependencyObject parent = oldParent; - if (!InputElement.IsUIElement(parent) && !InputElement.IsUIElement3D(parent)) + if (parent is not UIElement and not UIElement3D) { // We are being unplugged from a non-UIElement visual. This // means that our parent didn't play by the same rules we diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AnimatedTypeHelpers.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AnimatedTypeHelpers.cs index 81d22c79820..897c5ccfb43 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AnimatedTypeHelpers.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AnimatedTypeHelpers.cs @@ -166,7 +166,7 @@ internal static Thickness GetZeroValueThickness(Thickness baseValue) private static bool IsInvalidDouble(double value) { return Double.IsInfinity(value) - || DoubleUtil.IsNaN(value); + || double.IsNaN(value); } #endregion diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/PathNode.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/PathNode.cs index 1ff7bf6c7b6..7f5dd44dec9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/PathNode.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Annotations/Anchoring/PathNode.cs @@ -229,7 +229,7 @@ internal static DependencyObject GetParent(DependencyObject node) Debug.Assert(node != null, "node can not be null"); DependencyObject current = node; - DependencyObject parent = null; + DependencyObject parent; while (true) { @@ -255,16 +255,15 @@ internal static DependencyObject GetParent(DependencyObject node) } // Check if located a parent, if so, check if it's the correct type - if ((parent == null) || - FrameworkElement.DType.IsInstanceOfType(parent) || - FrameworkContentElement.DType.IsInstanceOfType(parent)) + if (parent is null + or FrameworkElement + or FrameworkContentElement) { break; } // Parent found but not of correct type, continue current = parent; - parent = null; } return parent; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/AppSecurityManager.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/AppSecurityManager.cs index a2e9c04dc1d..9d6e400186f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/AppSecurityManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/AppSecurityManager.cs @@ -427,7 +427,7 @@ internal class InternetSecurityManager // Object to be used for locking. Using typeof(Util) causes an FxCop // violation DoNotLockOnObjectsWithWeakIdentity - private static object _lockObj = new object(); + private static readonly object _lockObj = new object(); private static UnsafeNativeMethods.IInternetSecurityManager _secMgr; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/AssemblyFilter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/AssemblyFilter.cs index 2488be41b25..c158ae0700d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/AssemblyFilter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/AssemblyFilter.cs @@ -104,7 +104,7 @@ private void ExtractDisallowedRegistryList() static SecurityCriticalDataForSet _disallowedListExtracted; - static object _lock = new object(); + static readonly object _lock = new object(); private const string FILEVERSION_STRING = @", FileVersion="; // This is the location in the registry where all the keys are stored diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ResourcePart.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ResourcePart.cs index 1e71bdbcfbb..effc07d8f55 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ResourcePart.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/AppModel/ResourcePart.cs @@ -185,7 +185,7 @@ private Stream EnsureResourceLocationSet() private SecurityCriticalDataForSet _rmWrapper; private bool _ensureResourceIsCalled = false; private string _name; - private Object _globalLock = new Object(); + private readonly Object _globalLock = new Object(); #endregion Private Members } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/InkCanvasInnerCanvas.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/InkCanvasInnerCanvas.cs index b75175ab3e3..4e80a2ec105 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/InkCanvasInnerCanvas.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/InkCanvasInnerCanvas.cs @@ -92,7 +92,7 @@ protected override Size MeasureOverride(Size constraint) // For Right/Bottom, only the child.Width/Height will be used. Those properties will be used by the arrange // but not the measure. double left = (double)InkCanvas.GetLeft(child); - if (!DoubleUtil.IsNaN(left)) + if (!double.IsNaN(left)) { newSize.Width = Math.Max(newSize.Width, left + child.DesiredSize.Width); } @@ -102,7 +102,7 @@ protected override Size MeasureOverride(Size constraint) } double top = (double)InkCanvas.GetTop(child); - if (!DoubleUtil.IsNaN(top)) + if (!double.IsNaN(top)) { newSize.Height = Math.Max(newSize.Height, top + child.DesiredSize.Height); } @@ -143,7 +143,7 @@ protected override Size ArrangeOverride(Size arrangeSize) //If Left is not specified, then Right is used //If both are not there, then 0 double left = (double)InkCanvas.GetLeft(child); - if (!DoubleUtil.IsNaN(left)) + if (!double.IsNaN(left)) { x = left; } @@ -151,14 +151,14 @@ protected override Size ArrangeOverride(Size arrangeSize) { double right = (double)InkCanvas.GetRight(child); - if (!DoubleUtil.IsNaN(right)) + if (!double.IsNaN(right)) { x = arrangeSize.Width - child.DesiredSize.Width - right; } } double top = (double)InkCanvas.GetTop(child); - if (!DoubleUtil.IsNaN(top)) + if (!double.IsNaN(top)) { y = top; } @@ -166,7 +166,7 @@ protected override Size ArrangeOverride(Size arrangeSize) { double bottom = (double)InkCanvas.GetBottom(child); - if (!DoubleUtil.IsNaN(bottom)) + if (!double.IsNaN(bottom)) { y = arrangeSize.Height - child.DesiredSize.Height - bottom; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/AsyncDataRequest.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/AsyncDataRequest.cs index 1cc78eeed5f..12773f0682d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/AsyncDataRequest.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/AsyncDataRequest.cs @@ -219,7 +219,7 @@ bool ChangeStatus(AsyncRequestStatus newStatus) AsyncRequestCallback _workCallback; AsyncRequestCallback _completedCallback; - object SyncRoot = new object(); // for synchronization + readonly object SyncRoot = new object(); // for synchronization } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/DataBindEngine.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/DataBindEngine.cs index a7108a642cc..d54ec62b132 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/DataBindEngine.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/DataBindEngine.cs @@ -755,7 +755,7 @@ internal override void OnShutDown(object target, object sender, EventArgs e) private CleanupHelper _cleanupHelper; private Queue _crossThreadQueue = new Queue(); - private object _crossThreadQueueLock = new object(); + private readonly object _crossThreadQueueLock = new object(); private int _crossThreadCost; private DispatcherOperation _crossThreadDispatcherOperation; internal const int CrossThreadThreshold = 50000; // 50 msec diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/LiveShapingList.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/LiveShapingList.cs index 629daa62740..77171862f76 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/LiveShapingList.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/LiveShapingList.cs @@ -799,7 +799,7 @@ object IEnumerator.Current static List s_dpList = new List(); // static list of DPs, shared by all instances of lists - static object s_Sync = new object(); // lock for s_dpList + static readonly object s_Sync = new object(); // lock for s_dpList #endregion } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/PathParser.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/PathParser.cs index de9d4bc6993..858686dd0e4 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/PathParser.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/PathParser.cs @@ -189,7 +189,7 @@ void AddProperty() while (_index < _n && _path[_index] == '.') ++_index; - while (_index < _n && (level > 0 || SpecialChars.IndexOf(_path[_index]) < 0)) + while (_index < _n && (level > 0 || !IsSpecialChar(_path[_index]))) { if (_path[_index] == '(') ++level; @@ -386,6 +386,11 @@ void StartNewLevel() _drillIn = DrillIn.Never; } + private static bool IsSpecialChar(char ch) + { + return ch == '.' || ch == '/' || ch == '[' || ch == ']'; + } + State _state; string _path; int _index; @@ -395,7 +400,6 @@ void StartNewLevel() const char NullChar = Char.MinValue; const char EscapeChar = '^'; static SourceValueInfo[] EmptyInfo = Array.Empty(); - static string SpecialChars = @"./[]"; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/FrameworkObject.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/FrameworkObject.cs index 4234020478c..bde4847e41a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/FrameworkObject.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/FrameworkObject.cs @@ -57,21 +57,8 @@ internal FrameworkObject(DependencyObject d) // [code should be identical to Reset(d)] _do = d; - if (FrameworkElement.DType.IsInstanceOfType(d)) - { - _fe = (FrameworkElement)d; - _fce = null; - } - else if (FrameworkContentElement.DType.IsInstanceOfType(d)) - { - _fe = null; - _fce = (FrameworkContentElement)d; - } - else - { - _fe = null; - _fce = null; - } + _fe = d as FrameworkElement; + _fce = d as FrameworkContentElement; } internal FrameworkObject(DependencyObject d, bool throwIfNeither) @@ -99,21 +86,8 @@ internal void Reset(DependencyObject d) { _do = d; - if (FrameworkElement.DType.IsInstanceOfType(d)) - { - _fe = (FrameworkElement)d; - _fce = null; - } - else if (FrameworkContentElement.DType.IsInstanceOfType(d)) - { - _fe = null; - _fce = (FrameworkContentElement)d; - } - else - { - _fe = null; - _fce = null; - } + _fe = d as FrameworkElement; + _fce = d as FrameworkContentElement; } #endregion Constructors diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/LocalizationComments.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/LocalizationComments.cs index 8b3614c2a5b..4eb94c5ae0a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/LocalizationComments.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Globalization/LocalizationComments.cs @@ -103,7 +103,7 @@ internal static PropertyComment[] ParsePropertyComments(string input) { // terminate the PropertyName by an unesacped whitespace currentPair.PropertyName = tokenBuffer.ToString(); - tokenBuffer = new StringBuilder(); + tokenBuffer.Clear(); } // else ignore whitespace at the beginning of the PropertyName name @@ -116,7 +116,7 @@ internal static PropertyComment[] ParsePropertyComments(string input) { // terminate the PropertyName by an unescaped CommentStart char currentPair.PropertyName = tokenBuffer.ToString(); - tokenBuffer = new StringBuilder(); + tokenBuffer.Clear(); i--; // put back this char and continue } else @@ -161,9 +161,9 @@ internal static PropertyComment[] ParsePropertyComments(string input) if (!escaped) { // terminated by unescaped Comment - currentPair.Value = tokenBuffer.ToString().Substring(1); + currentPair.Value = tokenBuffer.ToString(1, tokenBuffer.Length - 1); tokens.Add(currentPair); - tokenBuffer = new StringBuilder(); + tokenBuffer.Clear(); currentPair = new PropertyComment(); } else @@ -228,7 +228,7 @@ private static LocalizabilityGroup LookupAndSetLocalizabilityAttribute(string in attributeGroup ); - builder = new StringBuilder(); + builder.Clear(); } } else diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Helper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Helper.cs index a45d7b9df42..197122f118c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Helper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Helper.cs @@ -286,15 +286,15 @@ internal static void DowncastToFEorFCE(DependencyObject d, out FrameworkElement fe, out FrameworkContentElement fce, bool throwIfNeither) { - if (FrameworkElement.DType.IsInstanceOfType(d)) + if (d is FrameworkElement frameworkElement) { - fe = (FrameworkElement)d; + fe = frameworkElement; fce = null; } - else if (FrameworkContentElement.DType.IsInstanceOfType(d)) + else if (d is FrameworkContentElement frameworkContentElement) { fe = null; - fce = (FrameworkContentElement)d; + fce = frameworkContentElement; } else if (throwIfNeither) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/ClipboardProcessor.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/ClipboardProcessor.cs index 40aecf7e5e8..e7160832144 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/ClipboardProcessor.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/ClipboardProcessor.cs @@ -213,9 +213,9 @@ internal bool PasteData(IDataObject dataObject, ref StrokeCollection newStrokes, // If the Xaml data has been set in an InkCanvas, the top element will be a container InkCanvas. // In this case, the new elements will be the children of the container. // Otherwise, the new elements will be whatever data from the data object. - if (elements.Count == 1 && ClipboardProcessor.InkCanvasDType.IsInstanceOfType(elements[0])) + if (elements.Count == 1 && elements[0] is InkCanvas inkCanvas) { - TearDownInkCanvasContainer((InkCanvas)( elements[0] ), ref newStrokes, ref newElements); + TearDownInkCanvasContainer(inkCanvas, ref newStrokes, ref newElements); } else { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/HighContrastHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/HighContrastHelper.cs index f6e118ea293..80931afe616 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/HighContrastHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Ink/HighContrastHelper.cs @@ -215,7 +215,7 @@ private static void OnUpdateHighContrast(HighContrastCallback highContrastCallba #region Private Fields - private static object __lock = new object(); + private static readonly object __lock = new object(); private static List __highContrastCallbackList; private static int __increaseCount; private const int CleanTolerance = 100; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PrePostDescendentsWalker.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PrePostDescendentsWalker.cs index e40e1032aa9..4a4f884039d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PrePostDescendentsWalker.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PrePostDescendentsWalker.cs @@ -72,7 +72,7 @@ public override void StartWalk(DependencyObject startNode, bool skipStartNode) { // This type checking is done in DescendentsWalker. Doing it here // keeps us consistent. - if (FrameworkElement.DType.IsInstanceOfType(startNode) || FrameworkContentElement.DType.IsInstanceOfType(startNode)) + if (startNode is FrameworkElement or FrameworkContentElement) { _postCallback(startNode, this.Data, _priority == TreeWalkPriority.VisualTree); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ColumnPropertiesGroup.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ColumnPropertiesGroup.cs index 453ebd5979c..d1ffddec15f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ColumnPropertiesGroup.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/ColumnPropertiesGroup.cs @@ -81,7 +81,7 @@ internal double ColumnGap // ------------------------------------------------------------------ // Column width is set? // ------------------------------------------------------------------ - internal bool ColumnWidthAuto { get { return DoubleUtil.IsNaN(_columnWidth); } } + internal bool ColumnWidthAuto { get { return double.IsNaN(_columnWidth); } } // ------------------------------------------------------------------ // Column gap is set? @@ -90,7 +90,7 @@ internal bool ColumnGapAuto { get { - return DoubleUtil.IsNaN(_columnGap); + return double.IsNaN(_columnGap); } } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureHelper.cs index 1b67fc4570b..c8a5071fd10 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/FigureHelper.cs @@ -123,7 +123,7 @@ internal static double CalculateFigureWidth(StructuralCache structuralCache, Fig } } - Invariant.Assert(!DoubleUtil.IsNaN(value)); + Invariant.Assert(!double.IsNaN(value)); return value; } @@ -174,7 +174,7 @@ internal static double CalculateFigureHeight(StructuralCache structuralCache, Fi value = FigureHelper.CalculateFigureCommon(figureLength); } - if(!DoubleUtil.IsNaN(value)) + if(!double.IsNaN(value)) { FigureVerticalAnchor verticalAnchor = figure.VerticalAnchor; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Line.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Line.cs index 07bb9c1afb1..03511eba538 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Line.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/Line.cs @@ -359,7 +359,7 @@ internal Size MeasureChild(InlineObjectRun inlineObject) Size desiredSize; if (_formattingContext.MeasureMode) { - Debug.Assert(!DoubleUtil.IsNaN(_trackWidth), "Track width must be set for measure pass."); + Debug.Assert(!double.IsNaN(_trackWidth), "Track width must be set for measure pass."); // Always measure at infinity for bottomless, consistent constraint. double pageHeight = _paraClient.Paragraph.StructuralCache.CurrentFormatContext.DocumentPageSize.Height; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsCache.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsCache.cs index 9c65339ee4d..c02d565254d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsCache.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/PtsCache.cs @@ -765,7 +765,7 @@ private unsafe void InitTableObjInfo(PtsHost ptsHost, ref PTS.FSTABLEOBJINIT tab /// /// Lock. /// - private object _lock = new object(); + private readonly object _lock = new object(); /// /// Whether object is already disposed. diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/RunClient.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/RunClient.cs index a88449e4993..e8834b2e04d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/RunClient.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/PtsHost/RunClient.cs @@ -59,7 +59,7 @@ public override TextEmbeddedObjectMetrics Format(double remainingParagraphWidth) double baseline = desiredSize.Height; double baselineOffsetValue = (double)UIElementIsland.Root.GetValue(TextBlock.BaselineOffsetProperty); - if(!DoubleUtil.IsNaN(baselineOffsetValue)) + if(!double.IsNaN(baselineOffsetValue)) { baseline = baselineOffsetValue; } @@ -82,7 +82,7 @@ public override Rect ComputeBoundingBox(bool rightToLeft, bool sideways) double baseline = !sideways ? size.Height : size.Width; double baselineOffsetValue = (double)UIElementIsland.Root.GetValue(TextBlock.BaselineOffsetProperty); - if (!sideways && !DoubleUtil.IsNaN(baselineOffsetValue)) + if (!sideways && !double.IsNaN(baselineOffsetValue)) { baseline = (double) baselineOffsetValue; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/DynamicPropertyReader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/DynamicPropertyReader.cs index 266a4d9d08c..88882c5a535 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/DynamicPropertyReader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/DynamicPropertyReader.cs @@ -208,7 +208,7 @@ internal static double GetLineHeightValue(DependencyObject d) { double lineHeight = (double)d.GetValue(Block.LineHeightProperty); // If LineHeight value is 'Auto', treat it as LineSpacing * FontSize. - if (DoubleUtil.IsNaN(lineHeight)) + if (double.IsNaN(lineHeight)) { FontFamily fontFamily = (FontFamily)d.GetValue(TextElement.FontFamilyProperty); double fontSize = (double)d.GetValue(TextElement.FontSizeProperty); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/InlineObject.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/InlineObject.cs index 8d9370387f5..f85ba890cff 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/InlineObject.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/InlineObject.cs @@ -54,7 +54,7 @@ public override TextEmbeddedObjectMetrics Format(double remainingParagraphWidth) double baseline = desiredSize.Height; double baselineOffsetValue = (double) Element.GetValue(TextBlock.BaselineOffsetProperty); - if(!DoubleUtil.IsNaN(baselineOffsetValue)) + if(!double.IsNaN(baselineOffsetValue)) { baseline = baselineOffsetValue; } @@ -76,7 +76,7 @@ public override Rect ComputeBoundingBox(bool rightToLeft, bool sideways) double baseline = !sideways ? size.Height : size.Width; double baselineOffsetValue = (double)Element.GetValue(TextBlock.BaselineOffsetProperty); - if (!sideways && !DoubleUtil.IsNaN(baselineOffsetValue)) + if (!sideways && !double.IsNaN(baselineOffsetValue)) { baseline = (double)baselineOffsetValue; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/LineProperties.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/LineProperties.cs index 23fcf65f005..561fce4af5b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/LineProperties.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Text/LineProperties.cs @@ -164,7 +164,7 @@ internal LineProperties( /// internal double CalcLineAdvanceForTextParagraph(TextParagraph textParagraph, int dcp, double lineAdvance) { - if (!DoubleUtil.IsNaN(_lineHeight)) + if (!double.IsNaN(_lineHeight)) { switch (LineStackingStrategy) { @@ -206,7 +206,7 @@ internal double CalcLineAdvanceForTextParagraph(TextParagraph textParagraph, int internal double CalcLineAdvance(double lineAdvance) { // We support MaxHeight and BlockLineHeight stacking strategies - if (!DoubleUtil.IsNaN(_lineHeight)) + if (!double.IsNaN(_lineHeight)) { switch (LineStackingStrategy) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/FlowDocumentFormatter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/FlowDocumentFormatter.cs index 40a18503d6f..0e48f879dea 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/FlowDocumentFormatter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/FlowDocumentFormatter.cs @@ -194,7 +194,7 @@ private Size ComputePageSize(Size constraint) { double max, min; Size pageSize = new Size(_document.PageWidth, double.PositiveInfinity); - if (DoubleUtil.IsNaN(pageSize.Width)) + if (double.IsNaN(pageSize.Width)) { pageSize.Width = constraint.Width; max = _document.MaxPageWidth; @@ -225,19 +225,19 @@ private Thickness ComputePageMargin() Thickness pageMargin = _document.PagePadding; // If Padding value is 'Auto', treat it as 1*LineHeight. - if (DoubleUtil.IsNaN(pageMargin.Left)) + if (double.IsNaN(pageMargin.Left)) { pageMargin.Left = lineHeight; } - if (DoubleUtil.IsNaN(pageMargin.Top)) + if (double.IsNaN(pageMargin.Top)) { pageMargin.Top = lineHeight; } - if (DoubleUtil.IsNaN(pageMargin.Right)) + if (double.IsNaN(pageMargin.Right)) { pageMargin.Right = lineHeight; } - if (DoubleUtil.IsNaN(pageMargin.Bottom)) + if (double.IsNaN(pageMargin.Bottom)) { pageMargin.Bottom = lineHeight; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/FlowDocumentPaginator.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/FlowDocumentPaginator.cs index 9bd092ffe6b..90f5b6d0ebe 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/FlowDocumentPaginator.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/FlowDocumentPaginator.cs @@ -534,11 +534,11 @@ public override Size PageSize _dispatcherObject.VerifyAccess(); Size newPageSize = value; - if (DoubleUtil.IsNaN(newPageSize.Width)) + if (double.IsNaN(newPageSize.Width)) { newPageSize.Width = _defaultPageSize.Width; } - if (DoubleUtil.IsNaN(newPageSize.Height)) + if (double.IsNaN(newPageSize.Height)) { newPageSize.Height = _defaultPageSize.Height; } @@ -853,7 +853,7 @@ private Size ComputePageSize() { double max, min; Size pageSize = new Size(_document.PageWidth, _document.PageHeight); - if (DoubleUtil.IsNaN(pageSize.Width)) + if (double.IsNaN(pageSize.Width)) { pageSize.Width = _pageSize.Width; max = _document.MaxPageWidth; @@ -867,7 +867,7 @@ private Size ComputePageSize() pageSize.Width = min; } } - if (DoubleUtil.IsNaN(pageSize.Height)) + if (double.IsNaN(pageSize.Height)) { pageSize.Height = _pageSize.Height; max = _document.MaxPageHeight; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextBoxView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextBoxView.cs index 8a52c111910..cf64985af76 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextBoxView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextBoxView.cs @@ -783,7 +783,7 @@ ITextPointer ITextView.GetPositionAtNextLine(ITextPointer position, double sugge { nextLinePosition = position.GetFrozenPointer(position.LogicalDirection); } - else if (DoubleUtil.IsNaN(suggestedX)) + else if (double.IsNaN(suggestedX)) { nextLinePosition = _host.TextContainer.CreatePointerAtOffset(_lineMetrics[lineIndex + linesMoved].Offset, LogicalDirection.Forward); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextDocumentView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextDocumentView.cs index 4f8a47b22e5..47ca4feaacc 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextDocumentView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextDocumentView.cs @@ -2521,7 +2521,7 @@ private ITextPointer GetPositionAtNextLine(ReadOnlyCollection p { // Get position at suggested X. If suggested X is not provided, // use the first position in the line. - if (!DoubleUtil.IsNaN(suggestedX)) + if (!double.IsNaN(suggestedX)) { positionOut = lines[lineIndex].GetTextPositionFromDistance(suggestedX); } @@ -2541,7 +2541,7 @@ private ITextPointer GetPositionAtNextLine(ReadOnlyCollection p else if (count < 0) { // Just in case there are no lines above, set position to the first line. - if (!DoubleUtil.IsNaN(suggestedX)) + if (!double.IsNaN(suggestedX)) { positionOut = lines[0].GetTextPositionFromDistance(suggestedX); } @@ -2553,7 +2553,7 @@ private ITextPointer GetPositionAtNextLine(ReadOnlyCollection p else { // Just in case there are no lines below, set position to the last line. - if (!DoubleUtil.IsNaN(suggestedX)) + if (!double.IsNaN(suggestedX)) { positionOut = lines[lines.Count - 1].GetTextPositionFromDistance(suggestedX); } @@ -3003,7 +3003,7 @@ private ITextPointer GetPositionAtNextLineFromSiblingTextPara(TextParagraphResul { // Get position at suggested X. If suggested X is not provided, // use the first position in the line. - if (!DoubleUtil.IsNaN(suggestedX)) + if (!double.IsNaN(suggestedX)) { positionOut = lines[lineIndex].GetTextPositionFromDistance(suggestedX); } @@ -3018,7 +3018,7 @@ private ITextPointer GetPositionAtNextLineFromSiblingTextPara(TextParagraphResul if (count < 0) { // Just in case there are no lines above, set position to the first line. - if (!DoubleUtil.IsNaN(suggestedX)) + if (!double.IsNaN(suggestedX)) { positionOut = lines[0].GetTextPositionFromDistance(suggestedX); } @@ -3030,7 +3030,7 @@ private ITextPointer GetPositionAtNextLineFromSiblingTextPara(TextParagraphResul else { // Just in case there are no lines below, set position to the last line. - if (!DoubleUtil.IsNaN(suggestedX)) + if (!double.IsNaN(suggestedX)) { positionOut = lines[lines.Count - 1].GetTextPositionFromDistance(suggestedX); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextParagraphView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextParagraphView.cs index 3dabe60010a..0add7b8bf32 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextParagraphView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/documents/TextParagraphView.cs @@ -187,7 +187,7 @@ internal override ITextPointer GetPositionAtNextLine(ITextPointer position, doub { positionOut = position; } - else if (!DoubleUtil.IsNaN(suggestedX)) + else if (!double.IsNaN(suggestedX)) { positionOut = lines[lineIndex].GetTextPositionFromDistance(suggestedX); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/AnnotationStore.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/AnnotationStore.cs index e0c9643efac..6413862d947 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/AnnotationStore.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Annotations/Storage/AnnotationStore.cs @@ -392,7 +392,7 @@ protected bool IsDisposed private bool _disposed = false; /// Private object used for synchronization - private Object lockObject = new Object(); + private readonly Object lockObject = new Object(); #endregion Private Fields } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/MenuItemAutomationPeer.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/MenuItemAutomationPeer.cs index 0cf50a7b53d..10bce1bcb12 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/MenuItemAutomationPeer.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Automation/Peers/MenuItemAutomationPeer.cs @@ -316,6 +316,16 @@ internal void RaiseExpandCollapseAutomationEvent(bool oldValue, bool newValue) newValue ? ExpandCollapseState.Expanded : ExpandCollapseState.Collapsed); } + [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] + internal void RaiseToggleStatePropertyChangedEvent(bool oldValue, bool newValue) + { + RaisePropertyChangedEvent(TogglePatternIdentifiers.ToggleStateProperty, + oldValue ? ConvertToToggleState(oldValue) : ConvertToToggleState(newValue), + newValue ? ConvertToToggleState(oldValue) : ConvertToToggleState(newValue)); + } + + private static ToggleState ConvertToToggleState(bool value) => value ? ToggleState.On : ToggleState.Off; + // Return the base without the AccessKey character /// override protected string GetNameCore() diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/BroadcastEventHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/BroadcastEventHelper.cs index 056f12d17e6..ace65f98990 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/BroadcastEventHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/BroadcastEventHelper.cs @@ -292,12 +292,10 @@ private static bool OnBroadcastCallback(DependencyObject d, BroadcastEventData d DependencyObject root = data.Root; RoutedEvent routedEvent = data.RoutedEvent; List eventRoute = data.EventRoute; - - if (FrameworkElement.DType.IsInstanceOfType(d)) - { - // If this is a FrameworkElement - FrameworkElement fe = (FrameworkElement)d; + // If this is a FrameworkElement + if (d is FrameworkElement fe) + { if (fe != root && routedEvent == FrameworkElement.LoadedEvent && fe.UnloadedPending != null) { // If there is a pending Unloaded event wait till we've broadcast @@ -422,22 +420,22 @@ private static bool OnBroadcastCallback(DependencyObject d, BroadcastEventData d private static bool SubtreeHasLoadedChangeHandlerHelper(DependencyObject d) { - if (FrameworkElement.DType.IsInstanceOfType(d)) + if (d is FrameworkElement fe) { - return ((FrameworkElement)d).SubtreeHasLoadedChangeHandler; + return fe.SubtreeHasLoadedChangeHandler; } - else if (FrameworkContentElement.DType.IsInstanceOfType(d)) + else if (d is FrameworkContentElement fce) { - return ((FrameworkContentElement)d).SubtreeHasLoadedChangeHandler; + return fce.SubtreeHasLoadedChangeHandler; } return false; } private static void FireLoadedOnDescendentsHelper(DependencyObject d) { - if (FrameworkElement.DType.IsInstanceOfType(d)) + if (d is FrameworkElement fe) { - ((FrameworkElement)d).FireLoadedOnDescendentsInternal(); + fe.FireLoadedOnDescendentsInternal(); } else { @@ -447,9 +445,9 @@ private static void FireLoadedOnDescendentsHelper(DependencyObject d) private static void FireUnloadedOnDescendentsHelper(DependencyObject d) { - if (FrameworkElement.DType.IsInstanceOfType(d)) + if (d is FrameworkElement fe) { - ((FrameworkElement)d).FireUnloadedOnDescendentsInternal(); + fe.FireUnloadedOnDescendentsInternal(); } else { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Canvas.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Canvas.cs index 5f64b580c68..2ef2f86537f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Canvas.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Canvas.cs @@ -303,7 +303,7 @@ protected override Size ArrangeOverride(Size arrangeSize) //If Left is not specified, then Right is used //If both are not there, then 0 double left = GetLeft(child); - if(!DoubleUtil.IsNaN(left)) + if(!double.IsNaN(left)) { x = left; } @@ -311,14 +311,14 @@ protected override Size ArrangeOverride(Size arrangeSize) { double right = GetRight(child); - if(!DoubleUtil.IsNaN(right)) + if(!double.IsNaN(right)) { x = arrangeSize.Width - child.DesiredSize.Width - right; } } double top = GetTop(child); - if(!DoubleUtil.IsNaN(top)) + if(!double.IsNaN(top)) { y = top; } @@ -326,7 +326,7 @@ protected override Size ArrangeOverride(Size arrangeSize) { double bottom = GetBottom(child); - if(!DoubleUtil.IsNaN(bottom)) + if(!double.IsNaN(bottom)) { y = arrangeSize.Height - child.DesiredSize.Height - bottom; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGrid.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGrid.cs index 08f5e11b4ab..c74b30f92bf 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGrid.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGrid.cs @@ -206,7 +206,7 @@ private static void OnColumnSizeConstraintChanged(DependencyObject d, Dependency private static bool ValidateMinColumnWidth(object v) { double value = (double)v; - return !(value < 0d || DoubleUtil.IsNaN(value) || Double.IsPositiveInfinity(value)); + return !(value < 0d || double.IsNaN(value) || Double.IsPositiveInfinity(value)); } /// @@ -215,7 +215,7 @@ private static bool ValidateMinColumnWidth(object v) private static bool ValidateMaxColumnWidth(object v) { double value = (double)v; - return !(value < 0d || DoubleUtil.IsNaN(value)); + return !(value < 0d || double.IsNaN(value)); } /// @@ -1262,7 +1262,7 @@ private static void OnNotifyRowHeaderWidthPropertyChanged(DependencyObject d, De var dataGrid = ((DataGrid)d); var newValue = (double)e.NewValue; - if (!DoubleUtil.IsNaN(newValue)) + if (!double.IsNaN(newValue)) { dataGrid.RowHeaderActualWidth = newValue; } @@ -1281,7 +1281,7 @@ private static void OnNotifyRowHeaderWidthPropertyChanged(DependencyObject d, De /// private void ResetRowHeaderActualWidth() { - if (DoubleUtil.IsNaN(RowHeaderWidth)) + if (double.IsNaN(RowHeaderWidth)) { RowHeaderActualWidth = 0.0; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellsPanel.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellsPanel.cs index 521845cde37..e5dc25ea775 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellsPanel.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridCellsPanel.cs @@ -146,7 +146,7 @@ private static void MeasureChild(UIElement child, Size constraint) // the desired width is greater than display value. DataGridLength width = column.Width; if (remeasure && - !DoubleUtil.IsNaN(width.DisplayValue) && + !double.IsNaN(width.DisplayValue) && DoubleUtil.GreaterThan(desiredWidth, width.DisplayValue)) { childMeasureConstraint.Width = width.DisplayValue; @@ -575,7 +575,7 @@ private UIElement GenerateChild( DataGridLength width = column.Width; childSize = child.DesiredSize; - if (!DoubleUtil.IsNaN(width.DisplayValue)) + if (!double.IsNaN(width.DisplayValue)) { childSize = new Size(width.DisplayValue, childSize.Height); } @@ -1474,7 +1474,7 @@ private void ArrangeChild( { Debug.Assert(cell.Column != null, "column cannot be null."); childWidth = cell.Column.Width.DisplayValue; - if (DoubleUtil.IsNaN(childWidth)) + if (double.IsNaN(childWidth)) { childWidth = cell.Column.ActualWidth; } @@ -1903,7 +1903,7 @@ private static double GetColumnEstimatedMeasureWidth(DataGridColumn column, doub } double childMeasureWidth = column.Width.DisplayValue; - if (DoubleUtil.IsNaN(childMeasureWidth)) + if (double.IsNaN(childMeasureWidth)) { childMeasureWidth = Math.Max(averageColumnWidth, column.MinWidth); childMeasureWidth = Math.Min(childMeasureWidth, column.MaxWidth); @@ -2024,7 +2024,7 @@ private double GetViewportWidth() if (DoubleUtil.AreClose(availableViewportWidth, 0.0) && parentRowsPresenter != null) { Size rowPresenterAvailableSize = parentRowsPresenter.AvailableSize; - if (!DoubleUtil.IsNaN(rowPresenterAvailableSize.Width) && !Double.IsInfinity(rowPresenterAvailableSize.Width)) + if (!double.IsNaN(rowPresenterAvailableSize.Width) && !Double.IsInfinity(rowPresenterAvailableSize.Width)) { availableViewportWidth = rowPresenterAvailableSize.Width; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumn.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumn.cs index bb773912061..2be07ca14ae 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumn.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumn.cs @@ -368,7 +368,7 @@ private static void OnMaxWidthPropertyChanged(DependencyObject d, DependencyProp /// private static double CoerceDesiredOrDisplayWidthValue(double widthValue, double memberValue, DataGridLengthUnitType type) { - if (DoubleUtil.IsNaN(memberValue)) + if (double.IsNaN(memberValue)) { if (type == DataGridLengthUnitType.Pixel) { @@ -399,8 +399,8 @@ private static object OnCoerceWidth(DependencyObject d, object baseValue) double newDesiredValue = CoerceDesiredOrDisplayWidthValue(width.Value, width.DesiredValue, width.UnitType); double newDisplayValue = CoerceDesiredOrDisplayWidthValue(width.Value, width.DisplayValue, width.UnitType); - newDisplayValue = (DoubleUtil.IsNaN(newDisplayValue) ? newDisplayValue : DataGridHelper.CoerceToMinMax(newDisplayValue, column.MinWidth, column.MaxWidth)); - if (DoubleUtil.IsNaN(newDisplayValue) || DoubleUtil.AreClose(newDisplayValue, width.DisplayValue)) + newDisplayValue = (double.IsNaN(newDisplayValue) ? newDisplayValue : DataGridHelper.CoerceToMinMax(newDisplayValue, column.MinWidth, column.MaxWidth)); + if (double.IsNaN(newDisplayValue) || DoubleUtil.AreClose(newDisplayValue, width.DisplayValue)) { return width; } @@ -455,7 +455,7 @@ private static object OnCoerceMaxWidth(DependencyObject d, object baseValue) private static bool ValidateMinWidth(object v) { double value = (double)v; - return !(value < 0d || DoubleUtil.IsNaN(value) || Double.IsPositiveInfinity(value)); + return !(value < 0d || double.IsNaN(value) || Double.IsPositiveInfinity(value)); } /// @@ -464,7 +464,7 @@ private static bool ValidateMinWidth(object v) private static bool ValidateMaxWidth(object v) { double value = (double)v; - return !(value < 0d || DoubleUtil.IsNaN(value)); + return !(value < 0d || double.IsNaN(value)); } /// @@ -515,7 +515,7 @@ private static object OnCoerceActualWidth(DependencyObject d, object baseValue) internal double GetConstraintWidth(bool isHeader) { DataGridLength width = Width; - if (!DoubleUtil.IsNaN(width.DisplayValue)) + if (!double.IsNaN(width.DisplayValue)) { return width.DisplayValue; } @@ -553,10 +553,10 @@ internal void UpdateDesiredWidthForAutoColumn(bool isHeader, double pixelWidth) (width.IsSizeToCells && !isHeader) || (width.IsSizeToHeader && isHeader)) { - if (DoubleUtil.IsNaN(width.DesiredValue) || + if (double.IsNaN(width.DesiredValue) || DoubleUtil.LessThan(width.DesiredValue, pixelWidth)) { - if (DoubleUtil.IsNaN(width.DisplayValue)) + if (double.IsNaN(width.DisplayValue)) { SetWidthInternal(new DataGridLength(width.Value, width.UnitType, pixelWidth, displayWidth)); } @@ -573,7 +573,7 @@ internal void UpdateDesiredWidthForAutoColumn(bool isHeader, double pixelWidth) width = Width; } - if (DoubleUtil.IsNaN(width.DisplayValue)) + if (double.IsNaN(width.DisplayValue)) { if (ActualWidth < displayWidth) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumnCollection.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumnCollection.cs index 29576126526..6376c4ef4c7 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumnCollection.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumnCollection.cs @@ -886,7 +886,7 @@ private void RecomputeStarColumnWidths() } } - if (DoubleUtil.IsNaN(nonStarSpace)) + if (double.IsNaN(nonStarSpace)) { return; } @@ -900,7 +900,7 @@ private void RecomputeStarColumnWidths() private double ComputeStarColumnWidths(double availableStarSpace) { Debug.Assert( - !DoubleUtil.IsNaN(availableStarSpace) && !Double.IsNegativeInfinity(availableStarSpace), + !double.IsNaN(availableStarSpace) && !Double.IsNegativeInfinity(availableStarSpace), "availableStarSpace is not valid"); List unResolvedColumns = new List(); @@ -1089,7 +1089,7 @@ private double ComputeAverageColumnWidth() foreach (DataGridColumn column in this) { DataGridLength width = column.Width; - if (column.IsVisible && !DoubleUtil.IsNaN(width.DisplayValue)) + if (column.IsVisible && !double.IsNaN(width.DisplayValue)) { eligibleDisplayValue += width.DisplayValue; totalFactors++; @@ -1192,7 +1192,7 @@ private void InitializeColumnDisplayValues() if (!width.IsStar) { double minWidth = column.MinWidth; - double displayValue = DataGridHelper.CoerceToMinMax(DoubleUtil.IsNaN(width.DesiredValue) ? minWidth : width.DesiredValue, minWidth, column.MaxWidth); + double displayValue = DataGridHelper.CoerceToMinMax(double.IsNaN(width.DesiredValue) ? minWidth : width.DesiredValue, minWidth, column.MaxWidth); if (!DoubleUtil.AreClose(width.DisplayValue, displayValue)) { column.SetWidthInternal(new DataGridLength(width.Value, width.UnitType, width.DesiredValue, displayValue)); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumnDropSeparator.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumnDropSeparator.cs index 3de69212606..97e2b074008 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumnDropSeparator.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumnDropSeparator.cs @@ -40,7 +40,7 @@ static DataGridColumnDropSeparator() private static object OnCoerceWidth(DependencyObject d, object baseValue) { double width = (double)baseValue; - if (DoubleUtil.IsNaN(width)) + if (double.IsNaN(width)) { return 2.0; } @@ -52,7 +52,7 @@ private static object OnCoerceHeight(DependencyObject d, object baseValue) { double height = (double)baseValue; DataGridColumnDropSeparator separator = (DataGridColumnDropSeparator)d; - if (separator._referenceHeader != null && DoubleUtil.IsNaN(height)) + if (separator._referenceHeader != null && double.IsNaN(height)) { return separator._referenceHeader.ActualHeight; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumnFloatingHeader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumnFloatingHeader.cs index 52cd3d8411d..5b55ceed92f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumnFloatingHeader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridColumnFloatingHeader.cs @@ -43,7 +43,7 @@ private static void OnWidthChanged(DependencyObject d, DependencyPropertyChanged { DataGridColumnFloatingHeader header = (DataGridColumnFloatingHeader)d; double width = (double)e.NewValue; - if (header._visualBrushCanvas != null && !DoubleUtil.IsNaN(width)) + if (header._visualBrushCanvas != null && !double.IsNaN(width)) { VisualBrush brush = header._visualBrushCanvas.Background as VisualBrush; if (brush != null) @@ -58,7 +58,7 @@ private static object OnCoerceWidth(DependencyObject d, object baseValue) { double width = (double)baseValue; DataGridColumnFloatingHeader header = (DataGridColumnFloatingHeader)d; - if (header._referenceHeader != null && DoubleUtil.IsNaN(width)) + if (header._referenceHeader != null && double.IsNaN(width)) { return header._referenceHeader.ActualWidth + header.GetVisualCanvasMarginX(); } @@ -70,7 +70,7 @@ private static void OnHeightChanged(DependencyObject d, DependencyPropertyChange { DataGridColumnFloatingHeader header = (DataGridColumnFloatingHeader)d; double height = (double)e.NewValue; - if (header._visualBrushCanvas != null && !DoubleUtil.IsNaN(height)) + if (header._visualBrushCanvas != null && !double.IsNaN(height)) { VisualBrush brush = header._visualBrushCanvas.Background as VisualBrush; if (brush != null) @@ -85,7 +85,7 @@ private static object OnCoerceHeight(DependencyObject d, object baseValue) { double height = (double)baseValue; DataGridColumnFloatingHeader header = (DataGridColumnFloatingHeader)d; - if (header._referenceHeader != null && DoubleUtil.IsNaN(height)) + if (header._referenceHeader != null && double.IsNaN(height)) { return header._referenceHeader.ActualHeight + header.GetVisualCanvasMarginY(); } @@ -126,7 +126,7 @@ private void UpdateVisualBrush() visualBrush.ViewboxUnits = BrushMappingMode.Absolute; double width = Width; - if (DoubleUtil.IsNaN(width)) + if (double.IsNaN(width)) { width = _referenceHeader.ActualWidth; } @@ -136,7 +136,7 @@ private void UpdateVisualBrush() } double height = Height; - if (DoubleUtil.IsNaN(height)) + if (double.IsNaN(height)) { height = _referenceHeader.ActualHeight; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridHelper.cs index 6f2763e5838..b150f9fc907 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridHelper.cs @@ -272,7 +272,7 @@ public static void OnColumnWidthChanged(IProvideDataGridColumn cell, DependencyP desiredWidth = oldWidth.DesiredValue; } - if (DoubleUtil.IsNaN(width.DesiredValue) || + if (double.IsNaN(width.DesiredValue) || DoubleUtil.LessThan(width.DesiredValue, desiredWidth)) { column.SetWidthInternal(new DataGridLength(width.Value, width.UnitType, desiredWidth, width.DisplayValue)); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLength.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLength.cs index 22b188a21d7..3c8191f5321 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLength.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLength.cs @@ -76,7 +76,7 @@ public DataGridLength(double value, DataGridLengthUnitType type) /// public DataGridLength(double value, DataGridLengthUnitType type, double desiredValue, double displayValue) { - if (DoubleUtil.IsNaN(value) || Double.IsInfinity(value)) + if (double.IsNaN(value) || Double.IsInfinity(value)) { throw new ArgumentException( SR.Get(SRID.DataGridLength_Infinity), @@ -130,8 +130,8 @@ public DataGridLength(double value, DataGridLengthUnitType type, double desiredV { return gl1.UnitType == gl2.UnitType && gl1.Value == gl2.Value - && ((gl1.DesiredValue == gl2.DesiredValue) || (DoubleUtil.IsNaN(gl1.DesiredValue) && DoubleUtil.IsNaN(gl2.DesiredValue))) - && ((gl1.DisplayValue == gl2.DisplayValue) || (DoubleUtil.IsNaN(gl1.DisplayValue) && DoubleUtil.IsNaN(gl2.DisplayValue))); + && ((gl1.DesiredValue == gl2.DesiredValue) || (double.IsNaN(gl1.DesiredValue) && double.IsNaN(gl2.DesiredValue))) + && ((gl1.DisplayValue == gl2.DisplayValue) || (double.IsNaN(gl1.DisplayValue) && double.IsNaN(gl2.DisplayValue))); } /// @@ -145,8 +145,8 @@ public DataGridLength(double value, DataGridLengthUnitType type, double desiredV { return gl1.UnitType != gl2.UnitType || gl1.Value != gl2.Value - || ((gl1.DesiredValue != gl2.DesiredValue) && !(DoubleUtil.IsNaN(gl1.DesiredValue) && DoubleUtil.IsNaN(gl2.DesiredValue))) - || ((gl1.DisplayValue != gl2.DisplayValue) && !(DoubleUtil.IsNaN(gl1.DisplayValue) && DoubleUtil.IsNaN(gl2.DisplayValue))); + || ((gl1.DesiredValue != gl2.DesiredValue) && !(double.IsNaN(gl1.DesiredValue) && double.IsNaN(gl2.DesiredValue))) + || ((gl1.DisplayValue != gl2.DisplayValue) && !(double.IsNaN(gl1.DisplayValue) && double.IsNaN(gl2.DisplayValue))); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLengthConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLengthConverter.cs index ad7a28268eb..9224a5c5805 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLengthConverter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DataGridLengthConverter.cs @@ -85,7 +85,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c DataGridLengthUnitType type; double doubleValue = Convert.ToDouble(value, culture); - if (DoubleUtil.IsNaN(doubleValue)) + if (double.IsNaN(doubleValue)) { // This allows for conversion from Width / Height = "Auto" doubleValue = 1.0; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DefinitionBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DefinitionBase.cs index 20c1f8ffe8a..354b7d63c94 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DefinitionBase.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/DefinitionBase.cs @@ -211,7 +211,7 @@ internal static void OnUserMinSizePropertyChanged(DependencyObject d, Dependency internal static bool IsUserMinSizePropertyValueValid(object value) { double v = (double)value; - return (!DoubleUtil.IsNaN(v) && v >= 0.0d && !Double.IsPositiveInfinity(v)); + return (!double.IsNaN(v) && v >= 0.0d && !Double.IsPositiveInfinity(v)); } /// @@ -240,7 +240,7 @@ internal static void OnUserMaxSizePropertyChanged(DependencyObject d, Dependency internal static bool IsUserMaxSizePropertyValueValid(object value) { double v = (double)value; - return (!DoubleUtil.IsNaN(v) && v >= 0.0d); + return (!double.IsNaN(v) && v >= 0.0d); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs index d1f57f02fc0..c100d4df875 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Grid.cs @@ -1618,10 +1618,10 @@ private void EnsureMinSizeInDefinitionRange( // sanity check: totalRemainingSize and sizeToDistribute must be real positive numbers Debug.Assert( !double.IsInfinity(totalRemainingSize) - && !DoubleUtil.IsNaN(totalRemainingSize) + && !double.IsNaN(totalRemainingSize) && totalRemainingSize > 0 && !double.IsInfinity(sizeToDistribute) - && !DoubleUtil.IsNaN(sizeToDistribute) + && !double.IsNaN(sizeToDistribute) && sizeToDistribute > 0 ); for (int i = 0; i < count; ++i) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/InkCanvas.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/InkCanvas.cs index a7be2e91b47..72011976f08 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/InkCanvas.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/InkCanvas.cs @@ -1892,8 +1892,8 @@ public void Paste(Point point) { VerifyAccess(); - if (DoubleUtil.IsNaN(point.X) || - DoubleUtil.IsNaN(point.Y) || + if (double.IsNaN(point.X) || + double.IsNaN(point.Y) || Double.IsInfinity(point.X)|| Double.IsInfinity(point.Y) ) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs index 18b01f43097..5891c18c4fc 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/MenuItem.cs @@ -946,7 +946,10 @@ private static void OnIsCheckedChanged(DependencyObject d, DependencyPropertyCha { MenuItem menuItem = (MenuItem) d; - if ((bool) e.NewValue) + bool oldValue = (bool)e.OldValue; + bool newValue = (bool)e.NewValue; + + if (newValue) { menuItem.OnChecked(new RoutedEventArgs(CheckedEvent)); } @@ -954,6 +957,12 @@ private static void OnIsCheckedChanged(DependencyObject d, DependencyPropertyCha { menuItem.OnUnchecked(new RoutedEventArgs(UncheckedEvent)); } + + MenuItemAutomationPeer peer = UIElementAutomationPeer.FromElement(menuItem) as MenuItemAutomationPeer; + if (peer != null) + { + peer.RaiseToggleStatePropertyChangedEvent(oldValue, newValue); + } } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs index 01f59ca5a09..dafc48583bd 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/PopupControlService.cs @@ -973,17 +973,17 @@ private bool RaiseContextMenuOpeningEvent(IInputElement source, double x, double DependencyObject sourceDO = source as DependencyObject; if (userInitiated && sourceDO != null) { - if (InputElement.IsUIElement(sourceDO)) + if (sourceDO is UIElement uiElement) { - ((UIElement)sourceDO).RaiseEvent(args, userInitiated); + uiElement.RaiseEvent(args, userInitiated); } - else if (InputElement.IsContentElement(sourceDO)) + else if (sourceDO is ContentElement contentElement) { - ((ContentElement)sourceDO).RaiseEvent(args, userInitiated); + contentElement.RaiseEvent(args, userInitiated); } - else if (InputElement.IsUIElement3D(sourceDO)) + else if (sourceDO is UIElement3D uiElement3D) { - ((UIElement3D)sourceDO).RaiseEvent(args, userInitiated); + uiElement3D.RaiseEvent(args, userInitiated); } else { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridColumnHeadersPresenter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridColumnHeadersPresenter.cs index e3a3cb87aad..d9366040dd9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridColumnHeadersPresenter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridColumnHeadersPresenter.cs @@ -917,7 +917,7 @@ private Point FindColumnHeaderPositionByCurrentPosition(Point startPos, bool fin private static double GetColumnEstimatedWidth(DataGridColumn column, double averageColumnWidth) { double columnEstimatedWidth = column.Width.DisplayValue; - if (DoubleUtil.IsNaN(columnEstimatedWidth)) + if (double.IsNaN(columnEstimatedWidth)) { columnEstimatedWidth = Math.Max(averageColumnWidth, column.MinWidth); columnEstimatedWidth = Math.Min(columnEstimatedWidth, column.MaxWidth); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridRowHeader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridRowHeader.cs index cdbb2118093..760baaf69b9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridRowHeader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DataGridRowHeader.cs @@ -193,7 +193,7 @@ protected override Size MeasureOverride(Size availableSize) return baseSize; } - if (DoubleUtil.IsNaN(dataGridOwner.RowHeaderWidth) && + if (double.IsNaN(dataGridOwner.RowHeaderWidth) && baseSize.Width > dataGridOwner.RowHeaderActualWidth) { dataGridOwner.RowHeaderActualWidth = baseSize.Width; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DatePickerTextBox.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DatePickerTextBox.cs index c9fff7ac270..2b63c8484a7 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DatePickerTextBox.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/DatePickerTextBox.cs @@ -153,7 +153,7 @@ private T ExtractTemplatePart(string partName) where T : DependencyObject private static T ExtractTemplatePart(string partName, DependencyObject obj) where T : DependencyObject { Debug.Assert( - obj == null || typeof(T).IsInstanceOfType(obj), + obj == null || obj is T, string.Format(CultureInfo.InvariantCulture, SR.Get(SRID.DatePickerTextBox_TemplatePartIsOfIncorrectType), partName, typeof(T).Name)); return obj as T; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/RangeBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/RangeBase.cs index 4d68bd15d92..f7880d2391f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/RangeBase.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/RangeBase.cs @@ -269,7 +269,7 @@ private static bool IsValidDoubleValue(object value) { double d = (double)value; - return !(DoubleUtil.IsNaN(d) || double.IsInfinity(d)); + return !(double.IsNaN(d) || double.IsInfinity(d)); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ScrollContentPresenter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ScrollContentPresenter.cs index 623bc48e8bc..b72856ab2fe 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ScrollContentPresenter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ScrollContentPresenter.cs @@ -690,7 +690,7 @@ internal static double ComputeScrollOffsetWithMinimalScroll( static internal double ValidateInputOffset(double offset, string parameterName) { - if (DoubleUtil.IsNaN(offset)) + if (double.IsNaN(offset)) { throw new ArgumentOutOfRangeException(parameterName, SR.Get(SRID.ScrollViewer_CannotBeNaN, parameterName)); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/TabPanel.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/TabPanel.cs index a8c26255136..0e774aa12ad 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/TabPanel.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/TabPanel.cs @@ -137,7 +137,7 @@ protected override Size MeasureOverride(Size constraint) contentSize.Height = _rowHeight * _numRows; // If we don't have constraint or content wisth is smaller than constraint width then size to content - if (double.IsInfinity(contentSize.Width) || DoubleUtil.IsNaN(contentSize.Width) || maxRowWidth < constraint.Width) + if (double.IsInfinity(contentSize.Width) || double.IsNaN(contentSize.Width) || maxRowWidth < constraint.Width) contentSize.Width = maxRowWidth; else contentSize.Width = constraint.Width; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ToolBarOverflowPanel.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ToolBarOverflowPanel.cs index 8822866e6d6..61297f0b31c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ToolBarOverflowPanel.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Primitives/ToolBarOverflowPanel.cs @@ -47,7 +47,7 @@ public double WrapWidth private static bool IsWrapWidthValid(object value) { double v = (double)value; - return (DoubleUtil.IsNaN(v)) || (DoubleUtil.GreaterThanOrClose(v, 0d) && !Double.IsPositiveInfinity(v)); + return (double.IsNaN(v)) || (DoubleUtil.GreaterThanOrClose(v, 0d) && !Double.IsPositiveInfinity(v)); } #endregion Properties diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Slider.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Slider.cs index 3722af70288..f49e9d80c9d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Slider.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/Slider.cs @@ -1362,7 +1362,7 @@ private static bool IsValidDoubleValue(object value) { double d = (double)value; - return !(DoubleUtil.IsNaN(d) || double.IsInfinity(d)); + return !(double.IsNaN(d) || double.IsInfinity(d)); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextBlock.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextBlock.cs index 282b5e18a4e..a265f240e48 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextBlock.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextBlock.cs @@ -4140,7 +4140,7 @@ private static object CoerceBaselineOffset(DependencyObject d, object value) { TextBlock tb = (TextBlock) d; - if(DoubleUtil.IsNaN((double) value)) + if(double.IsNaN((double) value)) { return tb._baselineOffset; } @@ -4156,7 +4156,7 @@ private static object CoerceBaselineOffset(DependencyObject d, object value) public bool ShouldSerializeBaselineOffset() { object localBaseline = ReadLocalValue(BaselineOffsetProperty); - return (localBaseline != DependencyProperty.UnsetValue) && !DoubleUtil.IsNaN((double) localBaseline); + return (localBaseline != DependencyProperty.UnsetValue) && !double.IsNaN((double) localBaseline); } //------------------------------------------------------------------- diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextRangeAdaptor.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextRangeAdaptor.cs index 38848e13ad2..3b8cc6a2bfb 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextRangeAdaptor.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/TextRangeAdaptor.cs @@ -1368,7 +1368,7 @@ private static TextDecorationLineStyle GetTextDecorationLineStyle(TextDecoration /// private static double NativeObjectLengthToPoints(double length) { - return (DoubleUtil.IsNaN(length) ? 0d : (length * 72.0 / 96.0)); + return (double.IsNaN(length) ? 0d : (length * 72.0 / 96.0)); } /// diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizationCacheLength.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizationCacheLength.cs index db40b3ceb5f..8e1f3878687 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizationCacheLength.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/VirtualizationCacheLength.cs @@ -65,12 +65,12 @@ public VirtualizationCacheLength(double cacheBeforeAndAfterViewport) public VirtualizationCacheLength(double cacheBeforeViewport, double cacheAfterViewport) { - if (DoubleUtil.IsNaN(cacheBeforeViewport)) + if (double.IsNaN(cacheBeforeViewport)) { throw new ArgumentException(SR.Get(SRID.InvalidCtorParameterNoNaN, "cacheBeforeViewport")); } - if (DoubleUtil.IsNaN(cacheAfterViewport)) + if (double.IsNaN(cacheAfterViewport)) { throw new ArgumentException(SR.Get(SRID.InvalidCtorParameterNoNaN, "cacheAfterViewport")); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/WrapPanel.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/WrapPanel.cs index d6284bc6f94..08eb16fa18b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/WrapPanel.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/WrapPanel.cs @@ -76,7 +76,7 @@ public WrapPanel() : base() private static bool IsWidthHeightValid(object value) { double v = (double)value; - return (DoubleUtil.IsNaN(v)) || (v >= 0.0d && !Double.IsPositiveInfinity(v)); + return (double.IsNaN(v)) || (v >= 0.0d && !Double.IsPositiveInfinity(v)); } /// @@ -225,8 +225,8 @@ protected override Size MeasureOverride(Size constraint) UVSize uvConstraint = new UVSize(Orientation, constraint.Width, constraint.Height); double itemWidth = ItemWidth; double itemHeight = ItemHeight; - bool itemWidthSet = !DoubleUtil.IsNaN(itemWidth); - bool itemHeightSet = !DoubleUtil.IsNaN(itemHeight); + bool itemWidthSet = !double.IsNaN(itemWidth); + bool itemHeightSet = !double.IsNaN(itemHeight); Size childConstraint = new Size( (itemWidthSet ? itemWidth : constraint.Width), @@ -288,8 +288,8 @@ protected override Size ArrangeOverride(Size finalSize) double itemU = (Orientation == Orientation.Horizontal ? itemWidth : itemHeight); UVSize curLineSize = new UVSize(Orientation); UVSize uvFinalSize = new UVSize(Orientation, finalSize.Width, finalSize.Height); - bool itemWidthSet = !DoubleUtil.IsNaN(itemWidth); - bool itemHeightSet = !DoubleUtil.IsNaN(itemHeight); + bool itemWidthSet = !double.IsNaN(itemWidth); + bool itemHeightSet = !double.IsNaN(itemHeight); bool useItemU = (Orientation == Orientation.Horizontal ? itemWidthSet : itemHeightSet); UIElementCollection children = InternalChildren; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/CornerRadius.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/CornerRadius.cs index 13767eff56c..29982e81768 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/CornerRadius.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/CornerRadius.cs @@ -124,10 +124,10 @@ public override string ToString() // SEEALSO public static bool operator==(CornerRadius cr1, CornerRadius cr2) { - return ( (cr1._topLeft == cr2._topLeft || (DoubleUtil.IsNaN(cr1._topLeft) && DoubleUtil.IsNaN(cr2._topLeft))) - && (cr1._topRight == cr2._topRight || (DoubleUtil.IsNaN(cr1._topRight) && DoubleUtil.IsNaN(cr2._topRight))) - && (cr1._bottomRight == cr2._bottomRight || (DoubleUtil.IsNaN(cr1._bottomRight) && DoubleUtil.IsNaN(cr2._bottomRight))) - && (cr1._bottomLeft == cr2._bottomLeft || (DoubleUtil.IsNaN(cr1._bottomLeft) && DoubleUtil.IsNaN(cr2._bottomLeft))) + return ( (cr1._topLeft == cr2._topLeft || (double.IsNaN(cr1._topLeft) && double.IsNaN(cr2._topLeft))) + && (cr1._topRight == cr2._topRight || (double.IsNaN(cr1._topRight) && double.IsNaN(cr2._topRight))) + && (cr1._bottomRight == cr2._bottomRight || (double.IsNaN(cr1._bottomRight) && double.IsNaN(cr2._bottomRight))) + && (cr1._bottomLeft == cr2._bottomLeft || (double.IsNaN(cr1._bottomLeft) && double.IsNaN(cr2._bottomLeft))) ); } @@ -204,7 +204,7 @@ internal bool IsValid(bool allowNegative, bool allowNaN, bool allowPositiveInfin if (!allowNaN) { - if (DoubleUtil.IsNaN(_topLeft) || DoubleUtil.IsNaN(_topRight) || DoubleUtil.IsNaN(_bottomLeft) || DoubleUtil.IsNaN(_bottomRight)) + if (double.IsNaN(_topLeft) || double.IsNaN(_topRight) || double.IsNaN(_bottomLeft) || double.IsNaN(_bottomRight)) { return (false); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingExpressionBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingExpressionBase.cs index 7bd783c79da..9b5cf70ab1f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingExpressionBase.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingExpressionBase.cs @@ -2464,7 +2464,7 @@ internal static WeakDependencySource[] CombineSources(int index, count++; } - Collection tempList = new Collection(); + var tempList = new List(); if (commonSources != null) { @@ -2502,19 +2502,9 @@ internal static WeakDependencySource[] CombineSources(int index, } } - WeakDependencySource[] result; - if (tempList.Count > 0) - { - result = new WeakDependencySource[tempList.Count]; - tempList.CopyTo(result, 0); - tempList.Clear(); - } - else - { - result = null; - } - - return result; + return tempList.Count > 0 ? + tempList.ToArray() : + null; } internal void ResolvePropertyDefaultSettings(BindingMode mode, UpdateSourceTrigger updateTrigger, FrameworkPropertyMetadata fwMetaData) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DescendentsWalker.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DescendentsWalker.cs index 8dbaa7d402c..7338bf29dfb 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DescendentsWalker.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DescendentsWalker.cs @@ -56,8 +56,8 @@ public virtual void StartWalk(DependencyObject startNode, bool skipStartNode) if (!skipStartNode) { - if (FrameworkElement.DType.IsInstanceOfType(_startNode) || - FrameworkContentElement.DType.IsInstanceOfType(_startNode)) + if (_startNode is FrameworkElement + or FrameworkContentElement) { // Callback for the root of the subtree continueWalk = _callback(_startNode, _data, _priority == TreeWalkPriority.VisualTree); @@ -79,9 +79,8 @@ private void IterateChildren(DependencyObject d) { _recursionDepth++; - if (FrameworkElement.DType.IsInstanceOfType(d)) + if (d is FrameworkElement fe) { - FrameworkElement fe = (FrameworkElement) d; bool hasLogicalChildren = fe.HasLogicalChildren; // FrameworkElement have both a visual and a logical tree. @@ -100,11 +99,10 @@ private void IterateChildren(DependencyObject d) Debug.Assert( false, "Tree walk priority should be Visual first or Logical first - but this instance of DescendentsWalker has an invalid priority setting that's neither of the two." ); } } - else if (FrameworkContentElement.DType.IsInstanceOfType(d)) + else if (d is FrameworkContentElement fce) { // FrameworkContentElement only has a logical tree, so we // Walk logical children - FrameworkContentElement fce = d as FrameworkContentElement; if (fce.HasLogicalChildren) { WalkLogicalChildren( null, fce, fce.LogicalChildren ); @@ -114,18 +112,13 @@ private void IterateChildren(DependencyObject d) { // Neither a FrameworkElement nor FrameworkContentElement. See // if it's a Visual and if so walk the Visual collection - Visual v = d as Visual; - if (v != null) + if (d is Visual v) { WalkVisualChildren(v); } - else + else if (d is Visual3D v3D) { - Visual3D v3D = d as Visual3D; - if (v3D != null) - { - WalkVisualChildren(v3D); - } + WalkVisualChildren(v3D); } } @@ -324,12 +317,12 @@ private void WalkFrameworkElementLogicalThenVisualChildren( for(int i = 0; i < count; i++) { Visual child = feParent.InternalGetVisualChild(i); - if (child != null && FrameworkElement.DType.IsInstanceOfType(child)) + if (child != null && child is FrameworkElement fe) { // For the case that both parents are identical, this node should // have already been visited when walking through logical // children, hence we short-circuit here - if (VisualTreeHelper.GetParent(child) != ((FrameworkElement) child).Parent) + if (VisualTreeHelper.GetParent(child) != fe.Parent) { bool visitedViaVisualTree = true; VisitNode(child, visitedViaVisualTree); @@ -404,11 +397,11 @@ private void VisitNode(DependencyObject d, bool visitedViaVisualTree) { if (_recursionDepth <= ContextLayoutManager.s_LayoutRecursionLimit) { - if (FrameworkElement.DType.IsInstanceOfType(d)) + if (d is FrameworkElement fe) { - VisitNode(d as FrameworkElement, visitedViaVisualTree); + VisitNode(fe, visitedViaVisualTree); } - else if (FrameworkContentElement.DType.IsInstanceOfType(d)) + else if (d is FrameworkContentElement) { _VisitNode(d, visitedViaVisualTree); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DescendentsWalkerBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DescendentsWalkerBase.cs index 86e62723dbd..50fe3198db9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DescendentsWalkerBase.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DescendentsWalkerBase.cs @@ -38,9 +38,8 @@ internal bool WasVisited(DependencyObject d) { DependencyObject logicalParent; - if (FrameworkElement.DType.IsInstanceOfType(ancestor)) + if (ancestor is FrameworkElement fe) { - FrameworkElement fe = ancestor as FrameworkElement; logicalParent = fe.Parent; // FrameworkElement DependencyObject dependencyObjectParent = VisualTreeHelper.GetParent(fe); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Diagnostics/ResourceDictionaryDiagnostics.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Diagnostics/ResourceDictionaryDiagnostics.cs index 939361e527f..51020f0058a 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Diagnostics/ResourceDictionaryDiagnostics.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Diagnostics/ResourceDictionaryDiagnostics.cs @@ -273,7 +273,7 @@ private static void RemoveEntries(Uri uri, } private static Dictionary>> _dictionariesFromUri; - private static object _dictionariesFromUriLock = new object(); + private static readonly object _dictionariesFromUriLock = new object(); private static IReadOnlyCollection EmptyResourceDictionaries => Array.Empty(); diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDSBuilder.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDSBuilder.cs index fb6b94acf6b..5436049845f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDSBuilder.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDSBuilder.cs @@ -17,7 +17,7 @@ namespace System.Windows.Documents using System.Windows.Markup; using System.Windows.Shapes; using System.Windows.Documents.DocumentStructures; - using ds=System.Windows.Documents.DocumentStructures; + using Ds=System.Windows.Documents.DocumentStructures; using System; using System.Collections; using System.Collections.Generic; @@ -219,7 +219,7 @@ private void AddChildofFixedNodeinFlow(int[] childIndex, NamedElement ne) private void SpecialProcessing(SemanticBasicElement sbe) { - ds.ListItemStructure listItem = sbe as ds.ListItemStructure; + Ds.ListItemStructure listItem = sbe as Ds.ListItemStructure; if (listItem != null && listItem.Marker != null) { NameHashFixedNode fen; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs index 678259047d6..7e972b80f49 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedDocument.cs @@ -730,14 +730,14 @@ internal void EnsurePageSize(FixedPage fp) double width = fp.Width; - if (DoubleUtil.IsNaN(width)) + if (double.IsNaN(width)) { fp.Width = _pageWidth; } double height = fp.Height; - if (DoubleUtil.IsNaN(height)) + if (double.IsNaN(height)) { fp.Height = _pageHeight; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedPage.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedPage.cs index d831d8a2feb..c77f9ec0c66 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedPage.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedPage.cs @@ -785,7 +785,7 @@ protected override Size ArrangeOverride(Size arrangeSize) //If Left is not specified, then Right is used //If both are not there, then 0 double left = GetLeft(child); - if(!DoubleUtil.IsNaN(left)) + if(!double.IsNaN(left)) { x = left; } @@ -793,14 +793,14 @@ protected override Size ArrangeOverride(Size arrangeSize) { double right = GetRight(child); - if(!DoubleUtil.IsNaN(right)) + if(!double.IsNaN(right)) { x = arrangeSize.Width - child.DesiredSize.Width - right; } } double top = GetTop(child); - if(!DoubleUtil.IsNaN(top)) + if(!double.IsNaN(top)) { y = top; } @@ -808,7 +808,7 @@ protected override Size ArrangeOverride(Size arrangeSize) { double bottom = GetBottom(child); - if(!DoubleUtil.IsNaN(bottom)) + if(!double.IsNaN(bottom)) { y = arrangeSize.Height - child.DesiredSize.Height - bottom; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextView.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextView.cs index 863cdd89cb2..02d2bf2653f 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextView.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedTextView.cs @@ -386,7 +386,7 @@ internal override ITextPointer GetPositionAtNextLine(ITextPointer position, doub return position; } - if (DoubleUtil.IsNaN(suggestedX)) + if (double.IsNaN(suggestedX)) { suggestedX = 0; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FlowDocument.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FlowDocument.cs index 9889632e604..76bcacffb2d 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FlowDocument.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FlowDocument.cs @@ -1008,19 +1008,19 @@ internal Thickness ComputePageMargin() Thickness pageMargin = this.PagePadding; // If Padding value is 'Auto', treat it as 1*LineHeight. - if (DoubleUtil.IsNaN(pageMargin.Left)) + if (double.IsNaN(pageMargin.Left)) { pageMargin.Left = lineHeight; } - if (DoubleUtil.IsNaN(pageMargin.Top)) + if (double.IsNaN(pageMargin.Top)) { pageMargin.Top = lineHeight; } - if (DoubleUtil.IsNaN(pageMargin.Right)) + if (double.IsNaN(pageMargin.Right)) { pageMargin.Right = lineHeight; } - if (DoubleUtil.IsNaN(pageMargin.Bottom)) + if (double.IsNaN(pageMargin.Bottom)) { pageMargin.Bottom = lineHeight; } @@ -1335,7 +1335,7 @@ private static object CoercePageWidth(DependencyObject d, object value) FlowDocument fd = (FlowDocument) d; double width = (double) value; - if (!DoubleUtil.IsNaN(width)) + if (!double.IsNaN(width)) { double max = fd.MaxPageWidth; if (width > max) @@ -1361,7 +1361,7 @@ private static object CoercePageHeight(DependencyObject d, object value) FlowDocument fd = (FlowDocument) d; double height = (double) value; - if (!DoubleUtil.IsNaN(height)) + if (!double.IsNaN(height)) { double max = fd.MaxPageHeight; if (height > max) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs index eca91af6199..ac7c8d4ab04 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextStore.cs @@ -586,7 +586,7 @@ public void GetEmbedded(int index, ref Guid guidService, ref Guid riid, out obje } // See msdn's ITextStoreACP documentation for a full description. - public void QueryInsertEmbedded(ref Guid guidService, int formatEtc, out bool insertable) + public void QueryInsertEmbedded(ref Guid guidService, IntPtr formatEtc, out bool insertable) { #if true // diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Tracing/SpellerCOMActionTraceLogger.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Tracing/SpellerCOMActionTraceLogger.cs index b47a503e1be..cb71300c0a3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Tracing/SpellerCOMActionTraceLogger.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/Tracing/SpellerCOMActionTraceLogger.cs @@ -114,7 +114,7 @@ private static WeakDictionary _instanceInfos /// A lock object to serialize updates to /// and the instances contained therein. /// - private static object _lockObject = new object(); + private static readonly object _lockObject = new object(); /// /// The current COM action being tracked @@ -298,4 +298,4 @@ private struct SpellerCOMTimingData public long RunningAverageCallTimeForCOMCallsMs { get; set; } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/glyphs.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/glyphs.cs index 92d2546b2af..5d1102e7407 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/glyphs.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/glyphs.cs @@ -191,8 +191,8 @@ private void ComputeMeasurementGlyphRunAndOrigin() bool leftToRight = ((BidiLevel & 1) == 0); - bool haveOriginX = !DoubleUtil.IsNaN(OriginX); - bool haveOriginY = !DoubleUtil.IsNaN(OriginY); + bool haveOriginX = !double.IsNaN(OriginX); + bool haveOriginY = !double.IsNaN(OriginY); bool measurementGlyphRunOriginValid = false; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkCompatibilityPreferences.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkCompatibilityPreferences.cs index 3b52e0f5272..032a568f259 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkCompatibilityPreferences.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkCompatibilityPreferences.cs @@ -478,6 +478,6 @@ private static void Seal() } private static bool _isSealed; - private static object _lockObject = new object(); + private static readonly object _lockObject = new object(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs index 11bf46851d8..325623a60d2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs @@ -2233,8 +2233,10 @@ protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e) { //let incrementally-updating FrameworkElements to mark the vicinity of the affected child //to perform partial update. - if(FrameworkElement.DType.IsInstanceOfType(layoutParent)) - ((FrameworkElement)layoutParent).ParentLayoutInvalidated(this); + if(layoutParent is FrameworkElement fe) + { + fe.ParentLayoutInvalidated(this); + } if (affectsParentMeasure) { @@ -3458,19 +3460,19 @@ private static void OnLayoutTransformChanged(DependencyObject d, DependencyPrope private static bool IsWidthHeightValid(object value) { double v = (double)value; - return (DoubleUtil.IsNaN(v)) || (v >= 0.0d && !Double.IsPositiveInfinity(v)); + return (double.IsNaN(v)) || (v >= 0.0d && !Double.IsPositiveInfinity(v)); } private static bool IsMinWidthHeightValid(object value) { double v = (double)value; - return (!DoubleUtil.IsNaN(v) && v >= 0.0d && !Double.IsPositiveInfinity(v)); + return (!double.IsNaN(v) && v >= 0.0d && !Double.IsPositiveInfinity(v)); } private static bool IsMaxWidthHeightValid(object value) { double v = (double)value; - return (!DoubleUtil.IsNaN(v) && v >= 0.0d); + return (!double.IsNaN(v) && v >= 0.0d); } private static void OnTransformDirty(DependencyObject d, DependencyPropertyChangedEventArgs e) @@ -4062,20 +4064,20 @@ internal MinMax(FrameworkElement e) minHeight = e.MinHeight; double l = e.Height; - double height = (DoubleUtil.IsNaN(l) ? Double.PositiveInfinity : l); + double height = (double.IsNaN(l) ? Double.PositiveInfinity : l); maxHeight = Math.Max(Math.Min(height, maxHeight), minHeight); - height = (DoubleUtil.IsNaN(l) ? 0 : l); + height = (double.IsNaN(l) ? 0 : l); minHeight = Math.Max(Math.Min(maxHeight, height), minHeight); maxWidth = e.MaxWidth; minWidth = e.MinWidth; l = e.Width; - double width = (DoubleUtil.IsNaN(l) ? Double.PositiveInfinity : l); + double width = (double.IsNaN(l) ? Double.PositiveInfinity : l); maxWidth = Math.Max(Math.Min(width, maxWidth), minWidth); - width = (DoubleUtil.IsNaN(l) ? 0 : l); + width = (double.IsNaN(l) ? 0 : l); minWidth = Math.Max(Math.Min(maxWidth, width), minWidth); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElementFactory.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElementFactory.cs index 4e3aeb50cdb..098464626e2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElementFactory.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElementFactory.cs @@ -1320,7 +1320,7 @@ private bool IsValueDefined(DependencyProperty dp) private FrameworkElementFactory _nextSibling; // Instance-based synchronization - private object _synchronized = new object(); + private readonly object _synchronized = new object(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkContentElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkContentElement.cs index c49f4b1f165..801648178a4 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkContentElement.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkContentElement.cs @@ -1218,19 +1218,6 @@ internal event InheritedPropertyChangedEventHandler InheritedPropertyChanged #endregion Internal Properties - //------------------------------------------------------ - // - // Internal Fields - // - //------------------------------------------------------ - - #region Internal Fields - - // Optimization, to avoid calling FromSystemType too often - internal new static DependencyObjectType DType = DependencyObjectType.FromSystemTypeInternal(typeof(FrameworkContentElement)); - - #endregion Internal Fields - //------------------------------------------------------ // // Private Fields diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkElement.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkElement.cs index 1066e2efac8..c5ab045f7c3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkElement.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Generated/FrameworkElement.cs @@ -1267,19 +1267,6 @@ internal event InheritedPropertyChangedEventHandler InheritedPropertyChanged #endregion Internal Properties - //------------------------------------------------------ - // - // Internal Fields - // - //------------------------------------------------------ - - #region Internal Fields - - // Optimization, to avoid calling FromSystemType too often - internal new static DependencyObjectType DType = DependencyObjectType.FromSystemTypeInternal(typeof(FrameworkElement)); - - #endregion Internal Fields - //------------------------------------------------------ // // Private Fields diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/GridLength.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/GridLength.cs index b23cce98a11..8739c69181c 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/GridLength.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/GridLength.cs @@ -89,7 +89,7 @@ public GridLength(double pixels) /// public GridLength(double value, GridUnitType type) { - if (DoubleUtil.IsNaN(value)) + if (double.IsNaN(value)) { throw new ArgumentException(SR.Get(SRID.InvalidCtorParameterNoNaN, "value")); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/GridLengthConverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/GridLengthConverter.cs index d1f3caa8d61..c93373690fd 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/GridLengthConverter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/GridLengthConverter.cs @@ -126,7 +126,7 @@ public override object ConvertFrom( value = Convert.ToDouble(source, cultureInfo); - if (DoubleUtil.IsNaN(value)) + if (double.IsNaN(value)) { // this allows for conversion from Width / Height = "Auto" value = 1.0; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Input/KeyboardNavigation.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Input/KeyboardNavigation.cs index 53b12fcbdff..a9a4cf409d3 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Input/KeyboardNavigation.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Input/KeyboardNavigation.cs @@ -903,7 +903,7 @@ private void ShowFocusVisual(DependencyObject element) // then we load the default FocusVisualStyle from ResourceDictionary. if (fvs == FrameworkElement.DefaultFocusVisualStyle) { - fvs = SystemResources.FindResourceInternal(SystemParameters.FocusVisualStyleKey) as Style; + fvs = FrameworkElement.FindResourceInternal(fe, fce: null, SystemParameters.FocusVisualStyleKey) as Style; } if (fvs != null) @@ -930,7 +930,7 @@ private void ShowFocusVisual(DependencyObject element) // then we load the default FocusVisualStyle from ResourceDictionary. if (fvs == FrameworkElement.DefaultFocusVisualStyle) { - fvs = SystemResources.FindResourceInternal(SystemParameters.FocusVisualStyleKey) as Style; + fvs = FrameworkElement.FindResourceInternal(fe: null, fce, SystemParameters.FocusVisualStyleKey) as Style; } if (fvs != null) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006Reader.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006Reader.cs index e55260737de..d7741a0db51 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006Reader.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006Reader.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Buffers; using System.Collections.Generic; using System.IO; using System.Xaml; @@ -1122,13 +1123,27 @@ private void Process_ConstructorParameterType() private void Process_Header() { - Int32 stringLength = _binaryReader.ReadInt32(); + int stringLength = _binaryReader.ReadInt32(); + int toRead = stringLength + (3 * sizeof(int)); // stringLength bytes + readerVersion, updateVersion, and writerVersion Int32s. - byte[] headerString = _binaryReader.ReadBytes(stringLength); - - Int32 readerVersion = _binaryReader.ReadInt32(); - Int32 updateVersion = _binaryReader.ReadInt32(); - Int32 writerVersion = _binaryReader.ReadInt32(); + // Ignore toRead bytes. + Stream s = _binaryReader.BaseStream; + if (s.CanSeek) + { + // If the stream underlying the reader is seekable, we can just skip past the bytes. + s.Position += toRead; + } + else + { + // In the less common case where it's not seekable, we need to actually read. + byte[] pooledArray = ArrayPool.Shared.Rent(toRead); + int totalRead = 0, bytesRead; + while (totalRead < toRead && (bytesRead = s.Read(pooledArray, 0, toRead - totalRead)) > 0) + { + totalRead += bytesRead; + } + ArrayPool.Shared.Return(pooledArray); + } } private void Process_ElementStart() @@ -2078,7 +2093,7 @@ private string Logic_GetFullXmlns(string uriInput) // We need to append local assembly return uriInput + ((_settings.LocalAssembly != null) - ? ";assembly=" + GetAssemblyNameForNamespace(_settings.LocalAssembly) + ? string.Concat(";assembly=", GetAssemblyNameForNamespace(_settings.LocalAssembly)) : String.Empty); } else @@ -2097,7 +2112,7 @@ private string Logic_GetFullXmlns(string uriInput) ReadOnlySpan assemblyName = uriInput.AsSpan(equalIdx + 1); if (assemblyName.TrimStart().IsEmpty) { - return uriInput + GetAssemblyNameForNamespace(_settings.LocalAssembly); + return string.Concat(uriInput, GetAssemblyNameForNamespace(_settings.LocalAssembly)); } } } @@ -2106,14 +2121,13 @@ private string Logic_GetFullXmlns(string uriInput) return uriInput; } - // Providing the assembly short name may lead to ambiguity between two versions of the same assembly, but we need to + // Providing the assembly short name may lead to ambiguity between two versions of the same assembly, but we need to // keep it this way since it is exposed publicly via the Namespace property, Baml2006ReaderInternal provides the full Assembly name. // We need to avoid Assembly.GetName() so we run in PartialTrust without asserting. - internal virtual string GetAssemblyNameForNamespace(Assembly assembly) + internal virtual ReadOnlySpan GetAssemblyNameForNamespace(Assembly assembly) { string assemblyLongName = assembly.FullName; - string assemblyShortName = assemblyLongName.Substring(0, assemblyLongName.IndexOf(',')); - return assemblyShortName; + return assemblyLongName.AsSpan(0, assemblyLongName.IndexOf(',')); } // (prefix, namespaceUri) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006ReaderInternal.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006ReaderInternal.cs index 9aaf4f950a9..d53dcc19012 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006ReaderInternal.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006ReaderInternal.cs @@ -42,7 +42,7 @@ internal Baml2006ReaderInternal( #endregion // Return the full assembly name, this includes the assembly version - internal override string GetAssemblyNameForNamespace(Assembly asm) + internal override ReadOnlySpan GetAssemblyNameForNamespace(Assembly asm) { return asm.FullName; } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006SchemaContext.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006SchemaContext.cs index 13d76c2c884..64eab82de99 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006SchemaContext.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006SchemaContext.cs @@ -708,7 +708,7 @@ private static readonly Lazy _frameworkTemplateTemplateProperty private static readonly Lazy _staticResourceExtensionType = new Lazy(() => System.Windows.Markup.XamlReader.BamlSharedSchemaContext.GetXamlType(typeof(StaticResourceExtension))); - private object _syncObject = new object(); + private readonly object _syncObject = new object(); private Assembly _localAssembly; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfSharedXamlSchemaContext.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfSharedXamlSchemaContext.cs index 4e295fadf6f..a4ca69b899e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfSharedXamlSchemaContext.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/WpfSharedXamlSchemaContext.cs @@ -64,7 +64,7 @@ internal XamlType GetXamlTypeInternal(string xamlNamespace, string name, params } private Dictionary _masterTypeTable = new Dictionary(); - private object _syncObject = new Object(); + private readonly object _syncObject = new Object(); private bool _useV3Rules; } } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/ElementMarkupObject.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/ElementMarkupObject.cs index 0abad26e58e..c89f5da52dd 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/ElementMarkupObject.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/ElementMarkupObject.cs @@ -406,7 +406,7 @@ private bool TryGetConstructorInfoArguments(object instance, out ParameterInfo[] return false; } - private static object _shouldSerializeCacheLock = new object(); + private static readonly object _shouldSerializeCacheLock = new object(); private static Hashtable _shouldSerializeCache = new Hashtable(); private static Type[] _shouldSerializeArgsObject = new Type[] { typeof(DependencyObject) }; private static Type[] _shouldSerializeArgsManager = new Type[] { typeof(XamlDesignerSerializationManager) }; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/MarkupWriter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/MarkupWriter.cs index 3a6ba41674c..c6e55e2dd88 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/MarkupWriter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Primitives/MarkupWriter.cs @@ -1561,7 +1561,7 @@ private static class NamespaceCache { private static Dictionary> XmlnsDefinitions = new Dictionary>(); private static Dictionary DefaultPrefixes = new Dictionary(); - private static object SyncObject = new object(); + private static readonly object SyncObject = new object(); static Dictionary GetMappingsFor(Assembly assembly) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapperSchemaContext.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapperSchemaContext.cs index 394874e8e98..bd63b3c0f76 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapperSchemaContext.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/XamlTypeMapperSchemaContext.cs @@ -24,7 +24,7 @@ internal class XamlTypeMapperSchemaContext : XamlSchemaContext WpfSharedXamlSchemaContext _sharedSchemaContext; // Lock on syncObject - object syncObject = new object(); + readonly object syncObject = new object(); Dictionary _piNamespaces; IEnumerable _allXamlNamespaces; Dictionary _allowedInternalTypes; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs index 073e59f15f3..34d61b14856 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Media/Animation/Storyboard.cs @@ -929,13 +929,13 @@ private bool PropertyCloningRequired( object targetPropertyValue ) /// private void VerifyComplexPathSupport( DependencyObject targetObject ) { - if( FrameworkElement.DType.IsInstanceOfType(targetObject) ) + if(targetObject is FrameworkElement) { // FrameworkElement and derived types are supported. return; } - if( FrameworkContentElement.DType.IsInstanceOfType(targetObject) ) + if(targetObject is FrameworkContentElement) { // FrameworkContentElement and derived types are supported. return; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shapes/Shape.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shapes/Shape.cs index 1a160144b32..fa7f247b604 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shapes/Shape.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shapes/Shape.cs @@ -445,8 +445,8 @@ protected abstract Geometry DefiningGeometry internal bool SizeIsInvalidOrEmpty(Size size) { - return (DoubleUtil.IsNaN(size.Width) || - DoubleUtil.IsNaN(size.Height) || + return (double.IsNaN(size.Width) || + double.IsNaN(size.Height) || size.IsEmpty); } @@ -455,7 +455,7 @@ internal bool IsPenNoOp get { double strokeThickness = StrokeThickness; - return (Stroke == null) || DoubleUtil.IsNaN(strokeThickness) || DoubleUtil.IsZero(strokeThickness); + return (Stroke == null) || double.IsNaN(strokeThickness) || DoubleUtil.IsZero(strokeThickness); } } @@ -524,12 +524,12 @@ internal Pen GetPen() internal static bool IsDoubleFiniteNonNegative(object o) { double d = (double)o; - return !(Double.IsInfinity(d) || DoubleUtil.IsNaN(d) || d < 0.0); + return !(Double.IsInfinity(d) || double.IsNaN(d) || d < 0.0); } internal static bool IsDoubleFinite(object o) { double d = (double)o; - return !(Double.IsInfinity(d) || DoubleUtil.IsNaN(d)); + return !(Double.IsInfinity(d) || double.IsNaN(d)); } internal static bool IsDoubleFiniteOrNaN(object o) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Utilities.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Utilities.cs index 23d2d156eea..32c93605d31 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Utilities.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Standard/Utilities.cs @@ -48,13 +48,15 @@ public static Color ColorFromArgbDword(uint color) [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] public static int GET_X_LPARAM(IntPtr lParam) { - return LOWORD(lParam.ToInt32()); + // ToInt64 to fix https://github.com/dotnet/wpf/issues/6777 + return LOWORD((int) lParam.ToInt64()); } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] public static int GET_Y_LPARAM(IntPtr lParam) { - return HIWORD(lParam.ToInt32()); + // ToInt64 to fix https://github.com/dotnet/wpf/issues/6777 + return HIWORD((int) lParam.ToInt64()); } [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs index 9d76b939e4e..508435ee9d9 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/StyleHelper.cs @@ -2327,15 +2327,15 @@ internal static void SpecialDowncastToFEorFCE(DependencyObject d, out FrameworkElement fe, out FrameworkContentElement fce, bool throwIfNeither) { - if (FrameworkElement.DType.IsInstanceOfType(d)) + if (d is FrameworkElement frameworkElement) { - fe = (FrameworkElement)d; + fe = frameworkElement; fce = null; } - else if (FrameworkContentElement.DType.IsInstanceOfType(d)) + else if (d is FrameworkContentElement frameworkContentElement) { fe = null; - fce = (FrameworkContentElement)d; + fce = frameworkContentElement; } else if (throwIfNeither && !(d is System.Windows.Media.Media3D.Visual3D) ) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemParameters.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemParameters.cs index e179d9e637f..19f2e15458e 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemParameters.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemParameters.cs @@ -1018,6 +1018,14 @@ public static bool MenuDropAlignment } return _menuDropAlignment; } + set + { + lock (_cacheValid) + { + _cacheValid[(int)CacheSlot.MenuDropAlignment] = true; + _menuDropAlignment = value; + } + } } /// @@ -1046,6 +1054,14 @@ public static bool MenuFade return _menuFade; } + set + { + lock (_cacheValid) + { + _cacheValid[(int)CacheSlot.MenuFade] = true; + _menuFade = value; + } + } } /// @@ -1075,6 +1091,14 @@ public static int MenuShowDelay return _menuShowDelay; } + set + { + lock (_cacheValid) + { + _cacheValid[(int)CacheSlot.MenuShowDelay] = true; + _menuShowDelay = value; + } + } } #endregion diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Thickness.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Thickness.cs index a821b64beea..46a6bb35808 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Thickness.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Thickness.cs @@ -156,7 +156,7 @@ internal bool IsValid(bool allowNegative, bool allowNaN, bool allowPositiveInfin if(!allowNaN) { - if(DoubleUtil.IsNaN(Left) || DoubleUtil.IsNaN(Right) || DoubleUtil.IsNaN(Top) || DoubleUtil.IsNaN(Bottom)) + if(double.IsNaN(Left) || double.IsNaN(Right) || double.IsNaN(Top) || double.IsNaN(Bottom)) return false; } @@ -227,10 +227,10 @@ static internal bool AreClose(Thickness thickness0, Thickness thickness1) // SEEALSO public static bool operator==(Thickness t1, Thickness t2) { - return ( (t1._Left == t2._Left || (DoubleUtil.IsNaN(t1._Left) && DoubleUtil.IsNaN(t2._Left))) - && (t1._Top == t2._Top || (DoubleUtil.IsNaN(t1._Top) && DoubleUtil.IsNaN(t2._Top))) - && (t1._Right == t2._Right || (DoubleUtil.IsNaN(t1._Right) && DoubleUtil.IsNaN(t2._Right))) - && (t1._Bottom == t2._Bottom || (DoubleUtil.IsNaN(t1._Bottom) && DoubleUtil.IsNaN(t2._Bottom))) + return ( (t1._Left == t2._Left || (double.IsNaN(t1._Left) && double.IsNaN(t2._Left))) + && (t1._Top == t2._Top || (double.IsNaN(t1._Top) && double.IsNaN(t2._Top))) + && (t1._Right == t2._Right || (double.IsNaN(t1._Right) && double.IsNaN(t2._Right))) + && (t1._Bottom == t2._Bottom || (double.IsNaN(t1._Bottom) && double.IsNaN(t2._Bottom))) ); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs index a109668b0e1..1489ff80f3b 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TreeWalkHelper.cs @@ -1000,7 +1000,7 @@ private static bool OnInheritablePropertyChanged( // only then do we need to Invalidate the property if (BaseValueSourceInternal.Inherited >= oldEntry.BaseValueSourceInternal) { - if (visitedViaVisualTree && FrameworkElement.DType.IsInstanceOfType(d)) + if (visitedViaVisualTree && d is FrameworkElement) { DependencyObject logicalParent = LogicalTreeHelper.GetParent(d); if (logicalParent != null) diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerBase.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerBase.cs index d528226fbd8..bed61d16404 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerBase.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerBase.cs @@ -393,7 +393,7 @@ internal TriggerCondition[] TriggerConditions /* property */ internal FrugalStructList PropertyValues = new FrugalStructList(); // Global, cross-object synchronization - private static object Synchronized = new object(); + private static readonly object Synchronized = new object(); // Conditions TriggerCondition[] _triggerConditions; diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs index c2022c7d3af..26177c8a9a2 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs @@ -2608,7 +2608,7 @@ internal virtual void SetupInitialState(double requestedTop, double requestedLef Point requestedLocationDeviceUnits = LogicalToDeviceUnits(new Point(requestedLeft, requestedTop)); // if Width was specified and is not the same as the current width, then update it - if ((!DoubleUtil.IsNaN(requestedWidth)) && (!DoubleUtil.AreClose(sizeDeviceUnits.Width, requestedSizeDeviceUnits.X))) + if ((!double.IsNaN(requestedWidth)) && (!DoubleUtil.AreClose(sizeDeviceUnits.Width, requestedSizeDeviceUnits.X))) { // at this stage, ActualWidth/Height is not set since // layout has not happened (it happens when we set the @@ -2625,7 +2625,7 @@ internal virtual void SetupInitialState(double requestedTop, double requestedLef } // if Height was specified and is not the same as the current height, then update it - if (!DoubleUtil.IsNaN(requestedHeight) && (!DoubleUtil.AreClose(sizeDeviceUnits.Height, requestedSizeDeviceUnits.Y))) + if (!double.IsNaN(requestedHeight) && (!DoubleUtil.AreClose(sizeDeviceUnits.Height, requestedSizeDeviceUnits.Y))) { // at this stage, ActualWidth/Height is not set since // layout has not happened (it happens when we set the @@ -2642,7 +2642,7 @@ internal virtual void SetupInitialState(double requestedTop, double requestedLef } // if left was specified and is not the same as the current left, then update it - if (!DoubleUtil.IsNaN(requestedLeft) && (!DoubleUtil.AreClose(xDeviceUnits, requestedLocationDeviceUnits.X))) + if (!double.IsNaN(requestedLeft) && (!DoubleUtil.AreClose(xDeviceUnits, requestedLocationDeviceUnits.X))) { updateHwndPlacement = true; xDeviceUnits = requestedLocationDeviceUnits.X; @@ -2655,7 +2655,7 @@ internal virtual void SetupInitialState(double requestedTop, double requestedLef } // if top was specified and is not the same as the current top, then update it - if (!DoubleUtil.IsNaN(requestedTop) && (!DoubleUtil.AreClose(yDeviceUnits, requestedLocationDeviceUnits.Y))) + if (!double.IsNaN(requestedTop) && (!DoubleUtil.AreClose(yDeviceUnits, requestedLocationDeviceUnits.Y))) { updateHwndPlacement = true; yDeviceUnits = requestedLocationDeviceUnits.Y; @@ -3788,16 +3788,16 @@ private bool CanCenterOverWPFOwner // then we cannot CenterOwner if (Owner.IsSourceWindowNull) { - if ((DoubleUtil.IsNaN(Owner.Width)) || - (DoubleUtil.IsNaN(Owner.Height))) + if ((double.IsNaN(Owner.Width)) || + (double.IsNaN(Owner.Height))) { return false; } } // if Owner's Top or Left is not specified, we cannot CenterOwner - if ((DoubleUtil.IsNaN(Owner.Left)) || - (DoubleUtil.IsNaN(Owner.Top))) + if ((double.IsNaN(Owner.Left)) || + (double.IsNaN(Owner.Top))) { return false; } @@ -5540,7 +5540,7 @@ private static void ValidateLengthForHeightWidth(double l) { //basically, NaN and PositiveInfinity are ok, and then anything //that can be converted to Int32 - if (!Double.IsPositiveInfinity(l) && !DoubleUtil.IsNaN(l) && + if (!Double.IsPositiveInfinity(l) && !double.IsNaN(l) && ((l > Int32.MaxValue) || (l < Int32.MinValue))) { throw new ArgumentException(SR.Get(SRID.ValueNotBetweenInt32MinMax, l)); @@ -5581,7 +5581,7 @@ private void OnHeightChanged(double height) ValidateLengthForHeightWidth(height); // Adding check for IsCompositionTargetInvalid - if (IsSourceWindowNull == false && IsCompositionTargetInvalid == false && !DoubleUtil.IsNaN(height)) + if (IsSourceWindowNull == false && IsCompositionTargetInvalid == false && !double.IsNaN(height)) { UpdateHeight(height); } @@ -5679,7 +5679,7 @@ private void OnWidthChanged(double width) ValidateLengthForHeightWidth(width); // Adding check for IsCompositionTargetInvalid - if (IsSourceWindowNull == false && IsCompositionTargetInvalid == false && !DoubleUtil.IsNaN(width)) + if (IsSourceWindowNull == false && IsCompositionTargetInvalid == false && !double.IsNaN(width)) { UpdateWidth(width); } @@ -5970,7 +5970,7 @@ private void OnTopChanged(double newTop) { // NaN is special and indicates using Win32 default, // so we exclude that. - if (DoubleUtil.IsNaN(newTop) == false) + if (double.IsNaN(newTop) == false) { if (WindowState == WindowState.Normal) { @@ -6065,7 +6065,7 @@ private void OnLeftChanged(double newLeft) { // NaN is special and indicates using Win32 default, // so we exclude that here. - if (DoubleUtil.IsNaN(newLeft) == false) + if (double.IsNaN(newLeft) == false) { if (WindowState == WindowState.Normal) { diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/figurelength.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/figurelength.cs index 496c6fdd455..be7d9ddb263 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/figurelength.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/figurelength.cs @@ -100,7 +100,7 @@ public FigureLength(double value, FigureUnitType type) double maxColumns = PTS.Restrictions.tscColumnRestriction; double maxPixel = Math.Min(1000000, PTS.MaxPageSize); - if (DoubleUtil.IsNaN(value)) + if (double.IsNaN(value)) { throw new ArgumentException(SR.Get(SRID.InvalidCtorParameterNoNaN, "value")); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/lengthconverter.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/lengthconverter.cs index b15380c5b3e..32f868144b1 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/lengthconverter.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/lengthconverter.cs @@ -152,7 +152,7 @@ public override object ConvertTo(ITypeDescriptorContext typeDescriptorContext, double l = (double)value; if (destinationType == typeof(string)) { - if(DoubleUtil.IsNaN(l)) + if(double.IsNaN(l)) return "Auto"; else return Convert.ToString(l, cultureInfo); @@ -240,7 +240,7 @@ static internal double FromString(string s, CultureInfo cultureInfo) static internal string ToString(double l, CultureInfo cultureInfo) { - if(DoubleUtil.IsNaN(l)) return "Auto"; + if(double.IsNaN(l)) return "Auto"; return Convert.ToString(l, cultureInfo); } diff --git a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/ref/PresentationFramework.cs b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/ref/PresentationFramework.cs index 56d0358293b..b2967c8a947 100644 --- a/src/Microsoft.DotNet.Wpf/src/PresentationFramework/ref/PresentationFramework.cs +++ b/src/Microsoft.DotNet.Wpf/src/PresentationFramework/ref/PresentationFramework.cs @@ -1563,15 +1563,15 @@ public static partial class SystemParameters public static System.Windows.ResourceKey MenuCheckmarkHeightKey { get { throw null; } } public static double MenuCheckmarkWidth { get { throw null; } } public static System.Windows.ResourceKey MenuCheckmarkWidthKey { get { throw null; } } - public static bool MenuDropAlignment { get { throw null; } } + public static bool MenuDropAlignment { get { throw null; } set {} } public static System.Windows.ResourceKey MenuDropAlignmentKey { get { throw null; } } - public static bool MenuFade { get { throw null; } } + public static bool MenuFade { get { throw null; } set { } } public static System.Windows.ResourceKey MenuFadeKey { get { throw null; } } public static double MenuHeight { get { throw null; } } public static System.Windows.ResourceKey MenuHeightKey { get { throw null; } } public static System.Windows.Controls.Primitives.PopupAnimation MenuPopupAnimation { get { throw null; } } public static System.Windows.ResourceKey MenuPopupAnimationKey { get { throw null; } } - public static int MenuShowDelay { get { throw null; } } + public static int MenuShowDelay { get { throw null; } set { } } public static System.Windows.ResourceKey MenuShowDelayKey { get { throw null; } } public static double MenuWidth { get { throw null; } } public static System.Windows.ResourceKey MenuWidthKey { get { throw null; } } diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentSequenceSerializer.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentSequenceSerializer.cs index 83c6e68732e..e1496822ee8 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentSequenceSerializer.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentSequenceSerializer.cs @@ -194,7 +194,7 @@ SerializablePropertyContext serializablePropertyContext propertyValue); - if (typeof(Type).IsInstanceOfType(propertyValue)) + if (propertyValue is Type) { int index = valueAsString.LastIndexOf('.'); valueAsString = string.Concat( diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentSequenceSerializerAsync.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentSequenceSerializerAsync.cs index 1f1225bbd6f..e0c04abbfc7 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentSequenceSerializerAsync.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachDocumentSequenceSerializerAsync.cs @@ -232,7 +232,7 @@ SerializablePropertyContext serializablePropertyContext propertyValue); - if (typeof(Type).IsInstanceOfType(propertyValue)) + if (propertyValue is Type) { int index = valueAsString.LastIndexOf('.'); valueAsString = string.Concat( diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedDocumentSerializer.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedDocumentSerializer.cs index a85bd29b31b..ed8cfff47de 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedDocumentSerializer.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedDocumentSerializer.cs @@ -277,7 +277,7 @@ SerializablePropertyContext serializablePropertyContext propertyValue); - if (typeof(Type).IsInstanceOfType(propertyValue)) + if (propertyValue is Type) { int index = valueAsString.LastIndexOf('.'); valueAsString = string.Concat( diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedDocumentSerializerAsync.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedDocumentSerializerAsync.cs index 477f4cc6198..249da14c521 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedDocumentSerializerAsync.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedDocumentSerializerAsync.cs @@ -317,7 +317,7 @@ SerializablePropertyContext serializablePropertyContext propertyValue); - if (typeof(Type).IsInstanceOfType(propertyValue)) + if (propertyValue is Type) { int index = valueAsString.LastIndexOf('.'); valueAsString = string.Concat( diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedPageSerializer.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedPageSerializer.cs index 76d6e3c1413..ff1899ab917 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedPageSerializer.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedPageSerializer.cs @@ -350,7 +350,7 @@ SerializablePropertyContext serializablePropertyContext propertyValue); - if (typeof(Type).IsInstanceOfType(propertyValue)) + if (propertyValue is Type) { int index = valueAsString.LastIndexOf('.'); valueAsString = string.Concat( diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedPageSerializerAsync.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedPageSerializerAsync.cs index 186f5d0bee0..8cd45d0fa58 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedPageSerializerAsync.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachFixedPageSerializerAsync.cs @@ -322,7 +322,7 @@ SerializablePropertyContext serializablePropertyContext propertyValue); - if (typeof(Type).IsInstanceOfType(propertyValue)) + if (propertyValue is Type) { int index = valueAsString.LastIndexOf('.'); valueAsString = string.Concat( diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializationUtils.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializationUtils.cs index 503a10b459a..748667b038a 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializationUtils.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/ReachSerializationUtils.cs @@ -1115,33 +1115,6 @@ private PackageSerializationManager SerializationManager }; - internal static class DoubleOperations - { - [StructLayout(LayoutKind.Explicit)] - private struct NanUnion - { - [FieldOffset(0)] internal double DoubleValue; - [FieldOffset(0)] internal UInt64 UintValue; - } - - internal - static - bool - IsNaN( - double value - ) - { - NanUnion t = new NanUnion(); - t.DoubleValue = value; - - UInt64 exp = t.UintValue & 0xfff0000000000000; - UInt64 man = t.UintValue & 0x000fffffffffffff; - - return (exp == 0x7ff0000000000000 || exp == 0xfff0000000000000) && (man != 0); - } - - } - internal static class Toolbox { internal static void EmitEvent(EventTrace.Event evt) @@ -1220,8 +1193,8 @@ PrintTicket printTicket { if (documentSize.Width == 0 || documentSize.Height == 0 || - DoubleOperations.IsNaN(documentSize.Width) || - DoubleOperations.IsNaN(documentSize.Height) || + double.IsNaN(documentSize.Width) || + double.IsNaN(documentSize.Height) || Double.IsPositiveInfinity(documentSize.Width) || Double.IsPositiveInfinity(documentSize.Height) || Double.IsNegativeInfinity(documentSize.Width) || diff --git a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMFixedPageSerializer.cs b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMFixedPageSerializer.cs index bf5204f9bfd..fd1b65885fc 100644 --- a/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMFixedPageSerializer.cs +++ b/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/manager/XpsOMFixedPageSerializer.cs @@ -308,7 +308,7 @@ SerializablePropertyContext serializablePropertyContext propertyValue); - if (typeof(Type).IsInstanceOfType(propertyValue)) + if (propertyValue is Type) { int index = valueAsString.LastIndexOf('.'); valueAsString = string.Concat( diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/DoubleUtil.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/DoubleUtil.cs index efd62ac6c4c..3f2499c14fb 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/DoubleUtil.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/DoubleUtil.cs @@ -275,41 +275,14 @@ public static int DoubleToInt(double val) /// returns whether the Rect has NaN public static bool RectHasNaN(Rect r) { - if ( DoubleUtil.IsNaN(r.X) - || DoubleUtil.IsNaN(r.Y) - || DoubleUtil.IsNaN(r.Height) - || DoubleUtil.IsNaN(r.Width) ) + if ( double.IsNaN(r.X) + || double.IsNaN(r.Y) + || double.IsNaN(r.Height) + || double.IsNaN(r.Width) ) { return true; } return false; } - - -#if !PBTCOMPILER - - [StructLayout(LayoutKind.Explicit)] - private struct NanUnion - { - [FieldOffset(0)] internal double DoubleValue; - [FieldOffset(0)] internal UInt64 UintValue; - } - - // The standard CLR double.IsNaN() function is approximately 100 times slower than our own wrapper, - // so please make sure to use DoubleUtil.IsNaN() in performance sensitive code. - // PS item that tracks the CLR improvement is DevDiv Schedule : 26916. - // IEEE 754 : If the argument is any value in the range 0x7ff0000000000001L through 0x7fffffffffffffffL - // or in the range 0xfff0000000000001L through 0xffffffffffffffffL, the result will be NaN. - public static bool IsNaN(double value) - { - NanUnion t = new NanUnion(); - t.DoubleValue = value; - - UInt64 exp = t.UintValue & 0xfff0000000000000; - UInt64 man = t.UintValue & 0x000fffffffffffff; - - return (exp == 0x7ff0000000000000 || exp == 0xfff0000000000000) && (man != 0); - } -#endif } } diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsTextServices.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsTextServices.cs index 4de87412c39..389a273ea5b 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsTextServices.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsTextServices.cs @@ -1630,7 +1630,7 @@ void SetText(SetTextFlags flags, int start, int end, //HRESULT QueryInsertEmbedded([in] const GUID *pguidService, // [in] const FORMATETC *pFormatEtc, // [out] BOOL *pfInsertable); - void QueryInsertEmbedded(ref Guid guidService, int /*ref Win32.FORMATETC*/ formatEtc, [MarshalAs(UnmanagedType.Bool)] out bool insertable); + void QueryInsertEmbedded(ref Guid guidService, IntPtr /*ref Win32.FORMATETC*/ formatEtc, [MarshalAs(UnmanagedType.Bool)] out bool insertable); /// //HRESULT InsertEmbedded([in] DWORD dwFlags, @@ -1972,14 +1972,14 @@ void SetText(int ec, /*SetTextFlags*/ int flags, // [out] LONG *pcch, // [in, unique] const TF_HALTCOND *pHalt); /// - void ShiftStart(int ec, int count, out int result, int ZeroForNow); // "ZeroForNow" should be a struct ptr if we ever use this + void ShiftStart(int ec, int count, out int result, IntPtr pHalt); //HRESULT ShiftEnd([in] TfEditCookie ec, // [in] LONG cchReq, // [out] LONG *pcch, // [in, unique] const TF_HALTCOND *pHalt); /// - void ShiftEnd(int ec, int count, out int result, int ZeroForNow); // "ZeroForNow" should be a struct ptr if we ever use this + void ShiftEnd(int ec, int count, out int result, IntPtr pHalt); //HRESULT ShiftStartToRange([in] TfEditCookie ec, // [in] ITfRange *pRange, @@ -2117,14 +2117,14 @@ void SetText(int ec, /*SetTextFlags*/ int flags, // [out] LONG *pcch, // [in, unique] const TF_HALTCOND *pHalt); /// - void ShiftStart(int ec, int count, out int result, int ZeroForNow); // "ZeroForNow" should be a struct ptr if we ever use this + void ShiftStart(int ec, int count, out int result, IntPtr pHalt); //HRESULT ShiftEnd([in] TfEditCookie ec, // [in] LONG cchReq, // [out] LONG *pcch, // [in, unique] const TF_HALTCOND *pHalt); /// - void ShiftEnd(int ec, int count, out int result, int ZeroForNow); // "ZeroForNow" should be a struct ptr if we ever use this + void ShiftEnd(int ec, int count, out int result, IntPtr pHalt); //HRESULT ShiftStartToRange([in] TfEditCookie ec, // [in] ITfRange *pRange, diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/Telemetry/Managed/TraceLoggingProvider.cs b/src/Microsoft.DotNet.Wpf/src/Shared/Telemetry/Managed/TraceLoggingProvider.cs index 53fce846c46..21aecbb81e8 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/Telemetry/Managed/TraceLoggingProvider.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/Telemetry/Managed/TraceLoggingProvider.cs @@ -51,7 +51,7 @@ internal static EventSource GetProvider() } private static EventSource _logger; - private static object _lockObject = new object(); + private static readonly object _lockObject = new object(); #if WINDOWS_BASE /// @@ -70,4 +70,4 @@ internal static EventSource GetProvider() private static readonly string ProviderName = "Microsoft.DOTNET.WPF.PresentationFramework"; #endif } -} \ No newline at end of file +} diff --git a/src/Microsoft.DotNet.Wpf/src/System.Printing/System.Printing.vcxproj b/src/Microsoft.DotNet.Wpf/src/System.Printing/System.Printing.vcxproj index 7ae51fde721..5183124e00d 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Printing/System.Printing.vcxproj +++ b/src/Microsoft.DotNet.Wpf/src/System.Printing/System.Printing.vcxproj @@ -238,4 +238,70 @@ unknownrev + + + + <_Temporary Remove="@(_Temporary)"/> + + + + + + + + + + + + + + + + + + + + + + + + <_Temporary Include ="@(EmbeddedResource)" Condition="'%(EmbeddedResource.ManifestResourceName)' != '' "/> + <_Temporary> + $(TargetPath) + $(ProjectPath) + + + + + + + + + <_Temporary Remove="@(_Temporary)"/> + <_OutOfDateEmbeddedResource Remove="@(_OutOfDateEmbeddedResource)" /> + + diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/MS/Internal/Generated/DoubleUtil.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/MS/Internal/Generated/DoubleUtil.cs index 4df2d58fbe5..540f2ec644c 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/MS/Internal/Generated/DoubleUtil.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/MS/Internal/Generated/DoubleUtil.cs @@ -194,30 +194,5 @@ public static int DoubleToInt(double val) { return (0 < val) ? (int)(val + 0.5) : (int)(val - 0.5); } - - // The standard CLR double.IsNaN() function is approximately 100 times slower than our own wrapper, - // so please make sure to use DoubleUtil.IsNaN() in performance sensitive code. - // PS item that tracks the CLR improvement is DevDiv Schedule : 26916. - // IEEE 754 : If the argument is any value in the range 0x7ff0000000000001L through 0x7fffffffffffffffL - // or in the range 0xfff0000000000001L through 0xffffffffffffffffL, the result will be NaN. - public static bool IsNaN(double value) - { - NanUnion t = new NanUnion(); - t.DoubleValue = value; - - ulong exp = t.UintValue & 0xfff0000000000000; - ulong man = t.UintValue & 0x000fffffffffffff; - - return (exp == 0x7ff0000000000000 || exp == 0xfff0000000000000) && (man != 0); - } - - [StructLayout(LayoutKind.Explicit)] - private struct NanUnion - { - [FieldOffset(0)] - internal double DoubleValue; - [FieldOffset(0)] - internal ulong UintValue; - } } } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/NativeMethods.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/NativeMethods.cs index b36ba06bd5c..88e5f57455f 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/NativeMethods.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/NativeMethods.cs @@ -441,7 +441,7 @@ internal static class HandleCollector private static HandleType[] handleTypes; private static int handleTypeCount = 0; - private static Object handleMutex = new Object(); + private static readonly Object handleMutex = new Object(); /// /// Adds the given handle to the handle collector. This keeps the diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControlLength.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControlLength.cs index 237e497f96e..37b8ae50e0c 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControlLength.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControlLength.cs @@ -48,7 +48,7 @@ public RibbonControlLength(double pixels) /// public RibbonControlLength(double value, RibbonControlLengthUnitType type) { - if (DoubleUtil.IsNaN(value)) + if (double.IsNaN(value)) { throw new ArgumentException(Microsoft.Windows.Controls.SR.Get(Microsoft.Windows.Controls.SRID.InvalidCtorParameterNoNaN, "value")); } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControlLengthConverter.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControlLengthConverter.cs index 8dcd365c336..1ccfece983b 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControlLengthConverter.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonControlLengthConverter.cs @@ -93,7 +93,7 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c doubleValue = Convert.ToDouble(value, culture); - if (DoubleUtil.IsNaN(doubleValue)) + if (double.IsNaN(doubleValue)) { // this allows for conversion from Width / Height = "Auto" doubleValue = 1.0; diff --git a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonMenuButton.cs b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonMenuButton.cs index ab9073cf231..8a90be767eb 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonMenuButton.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/Ribbon/RibbonMenuButton.cs @@ -1181,7 +1181,7 @@ void HandleIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) private static bool IsHeightValid(object value) { double v = (double)value; - return (DoubleUtil.IsNaN(v)) || (v >= 0.0d && !Double.IsPositiveInfinity(v)); + return (double.IsNaN(v)) || (v >= 0.0d && !Double.IsPositiveInfinity(v)); } private static void OnHasGalleryChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/ValueSerializer.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/ValueSerializer.cs index 75934717af3..61a4132f174 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/ValueSerializer.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/ValueSerializer.cs @@ -281,7 +281,7 @@ static ValueSerializer() { TypeDescriptor.Refreshed += TypeDescriptorRefreshed; } - private static object _valueSerializersLock = new object(); + private static readonly object _valueSerializersLock = new object(); private static Hashtable _valueSerializers = new Hashtable(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs index d87821796c2..f85ed029153 100644 --- a/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs +++ b/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs @@ -3001,41 +3001,6 @@ public override void FindNamespace(SerializerContext context) } } - // need to implement our own Set class to alleviate ties to System.Core.dll - // HashSet lives in System.Core.dll - class HashSet - { - Dictionary dictionary; - - public HashSet() - { - dictionary = new Dictionary(); - } - - public HashSet(IEqualityComparer comparer) - { - dictionary = new Dictionary(comparer); - } - - public bool Contains(T member) - { - return dictionary.ContainsKey(member); - } - - public bool Add(T member) - { - if (Contains(member)) - { - return false; - } - else - { - dictionary.Add(member, true); - return true; - } - } - } - private class PartiallyOrderedList : IEnumerable where TValue : class { diff --git a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Classic/Microsoft/Windows/Themes/ClassicBorderDecorator.cs b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Classic/Microsoft/Windows/Themes/ClassicBorderDecorator.cs index fae03f4b15d..fe6ced0762a 100644 --- a/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Classic/Microsoft/Windows/Themes/ClassicBorderDecorator.cs +++ b/src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Classic/Microsoft/Windows/Themes/ClassicBorderDecorator.cs @@ -505,7 +505,7 @@ private static bool IsValidBorderStyle(object o) /// If BorderBrush is not set to ClassicBorderBrush, a flat style is drawn /// private static Brush _classicBorderBrush; - private static object _brushLock = new object(); + private static readonly object _brushLock = new object(); public static Brush ClassicBorderBrush { diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/ClientEventManager.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/ClientEventManager.cs index 0c74f55953c..e04c1c9cabd 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/ClientEventManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/ClientEventManager.cs @@ -731,7 +731,7 @@ private enum Tracker private static QueueProcessor _callbackQueue; // callbacks are queued on this class to avoid deadlocks private static bool _isBkgrdThreadRunning = false; // is there a background thread for queueing and recieving WinEvents? private static ArrayList _listeners; // data representing events the client is listening for - private static object _classLock = new object(); // use lock object vs typeof(class) for perf reasons + private static readonly object _classLock = new object(); // use lock object vs typeof(class) for perf reasons #endregion Private Fields } diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/ProxyManager.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/ProxyManager.cs index 12b31341654..f9c018e8795 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/ProxyManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/MS/Internal/Automation/ProxyManager.cs @@ -828,7 +828,7 @@ private enum ProxyScoping FallbackHandlers, } - private static object _lockObj = new object(); + private static readonly object _lockObj = new object(); // contains ClientSideProviderDescription structs or an Arraylist of ClientSideProviderDescription structs private static Hashtable _classHandlers = new Hashtable(22, 1.0f); diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/CacheRequest.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/CacheRequest.cs index 36059584f37..801ce403291 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/CacheRequest.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClient/System/Windows/Automation/CacheRequest.cs @@ -512,7 +512,7 @@ void Invalidate() int _refCount = 0; // Used to lock on this instance... - object _instanceLock = null; + readonly object _instanceLock = null; //--- Per-Thread state --- diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/EventManager.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/EventManager.cs index 2718bacc0cf..a8c0a813505 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/EventManager.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/EventManager.cs @@ -582,7 +582,7 @@ private static void InitObjectIdMenu() private static Hashtable _objectIdScroll; private static Hashtable _objectIdCaret; private static Hashtable _objectIdMenu; - private static object _classLock = new object(); // use lock object vs typeof(class) for perf + private static readonly object _classLock = new object(); // use lock object vs typeof(class) for perf // The hwndLast and objLast is to allow limited filtering of events. private static IntPtr _hwndLast = IntPtr.Zero; diff --git a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WinEventTracker.cs b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WinEventTracker.cs index 5029bf5b0e0..7b2c4fa3108 100644 --- a/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WinEventTracker.cs +++ b/src/Microsoft.DotNet.Wpf/src/UIAutomation/UIAutomationClientSideProviders/MS/Internal/AutomationProxies/WinEventTracker.cs @@ -589,7 +589,7 @@ private enum EventFlag // WinEventHooks must be processed in the same thread that created them. // Use a seperate thread to manage the hooks private static QueueProcessor _callbackQueue = null; - private static object _queueLock = new object(); + private static readonly object _queueLock = new object(); // static: Array of Hashtables, one per WinEvent Id. // Each Hashtable contains EventHookParams classes the key is the process id. diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/Compoundfile/CompoundFileDeflateTransform.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/Compoundfile/CompoundFileDeflateTransform.cs index 397a0cdd96d..fddf844935b 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/Compoundfile/CompoundFileDeflateTransform.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/Compoundfile/CompoundFileDeflateTransform.cs @@ -23,7 +23,7 @@ using MS.Internal.IO.Packaging; // for PackagingUtilities using System.Security; // for SecurityCritical and SecurityTreatAsSafe using MS.Internal.WindowsBase; -using static Interop.zlib; // workaround namespace collision with MS.Internal.interop +using static Interop.Zlib; // workaround namespace collision with MS.Internal.interop namespace MS.Internal.IO.Packaging.CompoundFile { diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/BaseCompatibilityPreferences.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/BaseCompatibilityPreferences.cs index e595a5c8d2f..94bfd04d99d 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/BaseCompatibilityPreferences.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/BaseCompatibilityPreferences.cs @@ -385,6 +385,6 @@ private static void Seal() } private static bool _isSealed; - private static object _lockObject = new object(); + private static readonly object _lockObject = new object(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyObjectType.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyObjectType.cs index aa9482adec9..30be13eefa7 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyObjectType.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/DependencyObjectType.cs @@ -231,7 +231,7 @@ private DependencyObjectType() // Synchronized: Covered by DispatcherLock private static int DTypeCount = 0; - private static object _lock = new object(); + private static readonly object _lock = new object(); } } diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs index 90728a1022a..7e66776d49b 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs @@ -17,6 +17,8 @@ using MS.Internal.WindowsBase; // SecurityHelper using System.Threading; using System.ComponentModel; // EditorBrowsableAttribute, BrowsableAttribute +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; // Disabling 1634 and 1691: // In order to avoid generating warnings about unknown message numbers and @@ -222,10 +224,18 @@ public void VerifyAccess() { if(!CheckAccess()) { - throw new InvalidOperationException(SR.Get(SRID.VerifyAccess)); + ThrowVerifyAccess(); } } + // Used to inline VerifyAccess. + [DoesNotReturn] + [MethodImpl(MethodImplOptions.NoInlining)] + private static void ThrowVerifyAccess() + { + throw new InvalidOperationException(SR.Get(SRID.VerifyAccess)); + } + /// /// Begins the process of shutting down the dispatcher. /// @@ -2885,7 +2895,7 @@ private object[] CombineParameters(object arg, object[] args) private static List _dispatchers; private static WeakReference _possibleDispatcher; - private static object _globalLock; + private static readonly object _globalLock; [ThreadStatic] private static Dispatcher _tlsDispatcher; // use TLS for ownership only diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherHooks.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherHooks.cs index 27d4aa1cd17..95136e0f2bf 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherHooks.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherHooks.cs @@ -243,7 +243,7 @@ internal void RaiseOperationAborted(Dispatcher dispatcher, DispatcherOperation o } } - private object _instanceLock = new object(); + private readonly object _instanceLock = new object(); private EventHandler _dispatcherInactive; diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherOperation.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherOperation.cs index 766a619dc20..9ef8dfa13d2 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherOperation.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherOperation.cs @@ -425,7 +425,7 @@ internal void Invoke() EventHandler handler; // either completed or aborted lock(DispatcherLock) { - if(_exception != null && _exception is OperationCanceledException) + if(_exception is OperationCanceledException) { // A new way to abort/cancel an operation is to raise an // OperationCanceledException exception. This only works diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherTimer.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherTimer.cs index 35f50796fbd..978061c2255 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherTimer.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherTimer.cs @@ -319,7 +319,7 @@ private object FireTick() } // This is the object we use to synchronize access. - private object _instanceLock = new object(); + private readonly object _instanceLock = new object(); // Note: We cannot BE a dispatcher-affinity object because we can be // created by a worker thread. We are still associated with a diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/ApplicationInterop.cs b/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/ApplicationInterop.cs index feaff1f47fa..c06ac94025a 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/ApplicationInterop.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsFormsIntegration/System/Windows/Integration/ApplicationInterop.cs @@ -308,7 +308,7 @@ public bool PreFilterMessage(ref SWF.Message msg) internal class WeakReferenceList where T : class { List _internalList; - object _syncRoot = new object(); + readonly object _syncRoot = new object(); public WeakReferenceList() : base()