├── README.md ├── ImplicitUsings.cs ├── OpenInternetExplorer.csproj ├── LICENSE ├── OpenInternetExplorer.sln ├── NotNullWhenAttribute.cs ├── Program.cs ├── .gitignore └── .editorconfig /README.md: -------------------------------------------------------------------------------- 1 | # OpenInternetExplorer 2 | Open Internet Explorer in Windows 11 3 | 4 | ``` 5 | OpenInternetExplorer.exe "https://github.com" 6 | ``` -------------------------------------------------------------------------------- /ImplicitUsings.cs: -------------------------------------------------------------------------------- 1 | global using System; 2 | global using System.IO; 3 | global using System.Diagnostics; 4 | global using System.Diagnostics.CodeAnalysis; 5 | global using System.Windows.Forms; 6 | global using Microsoft.Win32; 7 | global using SHDocVw; 8 | -------------------------------------------------------------------------------- /OpenInternetExplorer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | WinExe 5 | net40 6 | enable 7 | latest 8 | x86 9 | 1.3.0 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | tlbimp 19 | 1 20 | 1 21 | eab22ac0-30c1-11cf-a7eb-0000c05bae0b 22 | 0 23 | false 24 | true 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Aigio L 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /OpenInternetExplorer.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.32002.185 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenInternetExplorer", "OpenInternetExplorer.csproj", "{3FB00883-16A7-4EFD-906C-BCAC09425CD4}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {3FB00883-16A7-4EFD-906C-BCAC09425CD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {3FB00883-16A7-4EFD-906C-BCAC09425CD4}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {3FB00883-16A7-4EFD-906C-BCAC09425CD4}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {3FB00883-16A7-4EFD-906C-BCAC09425CD4}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {AAC64831-AF4E-431A-A4B8-0EAFF06B0C14} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /NotNullWhenAttribute.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | // https://github.com/CommunityToolkit/dotnet/blob/v8.0.0-preview3/CommunityToolkit.Mvvm.SourceGenerators/Attributes/NotNullWhenAttribute.cs 5 | // https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.notnullwhenattribute?view=net-6.0 6 | 7 | #if NETFRAMEWORK 8 | namespace System.Diagnostics.CodeAnalysis; 9 | 10 | /// Specifies that when a method returns , the parameter will not be null even if the corresponding type allows it. 11 | [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] 12 | internal sealed class NotNullWhenAttribute : Attribute 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | /// The return value condition. If the method returns this value, the associated parameter will not be null. 18 | public NotNullWhenAttribute(bool returnValue) 19 | { 20 | ReturnValue = returnValue; 21 | } 22 | 23 | /// 24 | /// Gets a value indicating whether the annotated parameter will be null depending on the return value. 25 | /// 26 | public bool ReturnValue { get; } 27 | } 28 | #endif -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | const string ProductName = "OpenInternetExplorer"; 2 | const string Prefix_HTTPS = "https://"; 3 | const string Prefix_HTTP = "http://"; 4 | 5 | try 6 | { 7 | var url = GetStartPage(args); 8 | try 9 | { 10 | OpenInternetExplorer(url); 11 | } 12 | catch 13 | { 14 | // https://stackoverflow.com/questions/56044878/how-to-fix-an-hresult-0x8150002e-exception 15 | TryKillInternetExplorer(); 16 | OpenInternetExplorer(url); 17 | } 18 | } 19 | catch (Exception ex) 20 | { 21 | MessageBox.Show(ex.ToString(), ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); 22 | } 23 | 24 | static bool IsHttpUrl([NotNullWhen(true)] string? url, bool httpsOnly = false) => url != null && 25 | (url.StartsWith(Prefix_HTTPS, StringComparison.OrdinalIgnoreCase) || 26 | (!httpsOnly && url.StartsWith(Prefix_HTTP, StringComparison.OrdinalIgnoreCase))); 27 | 28 | static bool IsFileUrl([NotNullWhen(true)] string? url) 29 | { 30 | try 31 | { 32 | return File.Exists(url!); 33 | } 34 | catch 35 | { 36 | 37 | } 38 | return false; 39 | } 40 | 41 | static string GetStartPage(string[] args) 42 | { 43 | var url = GetArgument(args, 0); 44 | var httpsOnly = GetArgumentB(args, 1); 45 | if (IsHttpUrl(url, httpsOnly) || IsFileUrl(url)) return url; 46 | try 47 | { 48 | if (Environment.Is64BitOperatingSystem) 49 | { 50 | url = GetStartPageByRegistry(RegistryView.Registry64); 51 | if (IsHttpUrl(url, httpsOnly)) return url; 52 | } 53 | url = GetStartPageByRegistry(RegistryView.Registry32); 54 | if (IsHttpUrl(url, httpsOnly)) return url; 55 | } 56 | catch 57 | { 58 | 59 | } 60 | return "https://www.bing.com"; 61 | } 62 | 63 | static string? GetStartPageByRegistry(RegistryView registryView) 64 | { 65 | using var registryKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, registryView) 66 | .OpenSubKey(@"Software\Microsoft\Internet Explorer\Main"); 67 | return registryKey.GetValue("Start Page")?.ToString(); 68 | } 69 | 70 | static string? GetArgument(string[] args, int index) 71 | { 72 | try 73 | { 74 | return args[index]; 75 | } 76 | catch 77 | { 78 | return null; 79 | } 80 | } 81 | 82 | static bool GetArgumentB(string[] args, int index, bool defaultValue = false) 83 | { 84 | try 85 | { 86 | return bool.Parse(args[index]); 87 | } 88 | catch 89 | { 90 | } 91 | return defaultValue; 92 | } 93 | 94 | static void OpenInternetExplorer(string url) 95 | { 96 | // https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa752084(v=vs.85) 97 | var IE = new InternetExplorer 98 | { 99 | Visible = true 100 | }; 101 | IE.Navigate(url); 102 | } 103 | 104 | static void TryKillInternetExplorer() 105 | { 106 | var processes = Process.GetProcessesByName("iexplore"); 107 | foreach (var process in processes) 108 | { 109 | try 110 | { 111 | process.Kill(); 112 | } 113 | catch 114 | { 115 | 116 | } 117 | } 118 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*.{sh}] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | 11 | # Matches multiple files with brace expansion notation 12 | # Set default charset 13 | [*] 14 | charset = utf-8 15 | 16 | # Tab indentation (no size specified) 17 | [Makefile] 18 | indent_style = tab 19 | 20 | [*.{js,json,xaml,axaml,xml,resx,resw,csproj,wapproj,appxmanifest,props}] 21 | indent_style = space 22 | indent_size = 2 23 | 24 | # c# 文件 25 | [*.cs] 26 | 27 | #### Core EditorConfig 选项 #### 28 | 29 | # 缩进和间距 30 | indent_size = 4 31 | indent_style = space 32 | tab_width = 4 33 | 34 | # 新行首选项 35 | end_of_line = crlf 36 | insert_final_newline = false 37 | 38 | #### .NET 编码约定 #### 39 | 40 | # 组织 Using 41 | dotnet_separate_import_directive_groups = false 42 | dotnet_sort_system_directives_first = false 43 | file_header_template = unset 44 | 45 | # this. 和 Me. 首选项 46 | dotnet_style_qualification_for_event = false:suggestion 47 | dotnet_style_qualification_for_field = false 48 | dotnet_style_qualification_for_method = false:suggestion 49 | dotnet_style_qualification_for_property = false:suggestion 50 | 51 | # 语言关键字与 bcl 类型首选项 52 | dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion 53 | dotnet_style_predefined_type_for_member_access = true:suggestion 54 | 55 | # 括号首选项 56 | dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity 57 | dotnet_style_parentheses_in_other_binary_operators = always_for_clarity 58 | dotnet_style_parentheses_in_other_operators = never_if_unnecessary 59 | dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity 60 | 61 | # 修饰符首选项 62 | dotnet_style_require_accessibility_modifiers = never 63 | 64 | # 表达式级首选项 65 | dotnet_style_coalesce_expression = true 66 | dotnet_style_collection_initializer = true 67 | dotnet_style_explicit_tuple_names = true 68 | dotnet_style_null_propagation = true 69 | dotnet_style_object_initializer = true 70 | dotnet_style_operator_placement_when_wrapping = beginning_of_line 71 | dotnet_style_prefer_auto_properties = true 72 | dotnet_style_prefer_compound_assignment = true 73 | dotnet_style_prefer_conditional_expression_over_assignment = true 74 | dotnet_style_prefer_conditional_expression_over_return = true 75 | dotnet_style_prefer_inferred_anonymous_type_member_names = true 76 | dotnet_style_prefer_inferred_tuple_names = true 77 | dotnet_style_prefer_is_null_check_over_reference_equality_method = true 78 | dotnet_style_prefer_simplified_boolean_expressions = true 79 | dotnet_style_prefer_simplified_interpolation = true 80 | 81 | # 字段首选项 82 | dotnet_style_readonly_field = true 83 | 84 | # 参数首选项 85 | dotnet_code_quality_unused_parameters = all 86 | 87 | # 禁止显示首选项 88 | dotnet_remove_unnecessary_suppression_exclusions = none 89 | 90 | #### c# 编码约定 #### 91 | 92 | # var 首选项 93 | csharp_style_var_elsewhere = true 94 | csharp_style_var_for_built_in_types = true 95 | csharp_style_var_when_type_is_apparent = true 96 | 97 | # Expression-bodied 成员 98 | csharp_style_expression_bodied_accessors = true 99 | csharp_style_expression_bodied_constructors = false 100 | csharp_style_expression_bodied_indexers = true 101 | csharp_style_expression_bodied_lambdas = true 102 | csharp_style_expression_bodied_local_functions = false 103 | csharp_style_expression_bodied_methods = false 104 | csharp_style_expression_bodied_operators = false 105 | csharp_style_expression_bodied_properties = true 106 | 107 | # 模式匹配首选项 108 | csharp_style_pattern_matching_over_as_with_null_check = true 109 | csharp_style_pattern_matching_over_is_with_cast_check = true 110 | csharp_style_prefer_not_pattern = true 111 | csharp_style_prefer_pattern_matching = true 112 | csharp_style_prefer_switch_expression = true 113 | 114 | # Null 检查首选项 115 | csharp_style_conditional_delegate_call = true 116 | 117 | # 修饰符首选项 118 | csharp_prefer_static_local_function = true 119 | csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async 120 | 121 | # 代码块首选项 122 | csharp_prefer_braces = false 123 | csharp_prefer_simple_using_statement = true 124 | 125 | # 表达式级首选项 126 | csharp_prefer_simple_default_expression = true 127 | csharp_style_deconstructed_variable_declaration = true 128 | csharp_style_implicit_object_creation_when_type_is_apparent = true 129 | csharp_style_inlined_variable_declaration = true 130 | csharp_style_pattern_local_over_anonymous_function = true 131 | csharp_style_prefer_index_operator = true 132 | csharp_style_prefer_range_operator = true 133 | csharp_style_throw_expression = true 134 | csharp_style_unused_value_assignment_preference = discard_variable 135 | csharp_style_unused_value_expression_statement_preference = discard_variable 136 | 137 | # "using" 指令首选项 138 | csharp_using_directive_placement = outside_namespace 139 | 140 | #### C# 格式规则 #### 141 | 142 | # 新行首选项 143 | csharp_new_line_before_catch = true 144 | csharp_new_line_before_else = true 145 | csharp_new_line_before_finally = true 146 | csharp_new_line_before_members_in_anonymous_types = true 147 | csharp_new_line_before_members_in_object_initializers = true 148 | csharp_new_line_before_open_brace = all 149 | csharp_new_line_between_query_expression_clauses = true 150 | 151 | # 缩进首选项 152 | csharp_indent_block_contents = true 153 | csharp_indent_braces = false 154 | csharp_indent_case_contents = true 155 | csharp_indent_case_contents_when_block = true 156 | csharp_indent_labels = one_less_than_current 157 | csharp_indent_switch_labels = true 158 | 159 | # 空格键首选项 160 | csharp_space_after_cast = false 161 | csharp_space_after_colon_in_inheritance_clause = true 162 | csharp_space_after_comma = true 163 | csharp_space_after_dot = false 164 | csharp_space_after_keywords_in_control_flow_statements = true 165 | csharp_space_after_semicolon_in_for_statement = true 166 | csharp_space_around_binary_operators = before_and_after 167 | csharp_space_around_declaration_statements = false 168 | csharp_space_before_colon_in_inheritance_clause = true 169 | csharp_space_before_comma = false 170 | csharp_space_before_dot = false 171 | csharp_space_before_open_square_brackets = false 172 | csharp_space_before_semicolon_in_for_statement = false 173 | csharp_space_between_empty_square_brackets = false 174 | csharp_space_between_method_call_empty_parameter_list_parentheses = false 175 | csharp_space_between_method_call_name_and_opening_parenthesis = false 176 | csharp_space_between_method_call_parameter_list_parentheses = false 177 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false 178 | csharp_space_between_method_declaration_name_and_open_parenthesis = false 179 | csharp_space_between_method_declaration_parameter_list_parentheses = false 180 | csharp_space_between_parentheses = false 181 | csharp_space_between_square_brackets = false 182 | 183 | # 包装首选项 184 | csharp_preserve_single_line_blocks = true 185 | csharp_preserve_single_line_statements = true 186 | 187 | #### 命名样式 #### 188 | 189 | # 命名规则 190 | 191 | dotnet_naming_rule.interface_should_be_以_i_开始.severity = suggestion 192 | dotnet_naming_rule.interface_should_be_以_i_开始.symbols = interface 193 | dotnet_naming_rule.interface_should_be_以_i_开始.style = 以_i_开始 194 | 195 | dotnet_naming_rule.类型_should_be_帕斯卡拼写法.severity = suggestion 196 | dotnet_naming_rule.类型_should_be_帕斯卡拼写法.symbols = 类型 197 | dotnet_naming_rule.类型_should_be_帕斯卡拼写法.style = 帕斯卡拼写法 198 | 199 | dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.severity = suggestion 200 | dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.symbols = 非字段成员 201 | dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.style = 帕斯卡拼写法 202 | 203 | # 符号规范 204 | 205 | dotnet_naming_symbols.interface.applicable_kinds = interface 206 | dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected 207 | dotnet_naming_symbols.interface.required_modifiers = 208 | 209 | dotnet_naming_symbols.类型.applicable_kinds = class, struct, interface, enum 210 | dotnet_naming_symbols.类型.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected 211 | dotnet_naming_symbols.类型.required_modifiers = 212 | 213 | dotnet_naming_symbols.非字段成员.applicable_kinds = property, event, method 214 | dotnet_naming_symbols.非字段成员.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected 215 | dotnet_naming_symbols.非字段成员.required_modifiers = 216 | 217 | # 命名样式 218 | 219 | dotnet_naming_style.帕斯卡拼写法.required_prefix = 220 | dotnet_naming_style.帕斯卡拼写法.required_suffix = 221 | dotnet_naming_style.帕斯卡拼写法.word_separator = 222 | dotnet_naming_style.帕斯卡拼写法.capitalization = pascal_case 223 | 224 | dotnet_naming_style.以_i_开始.required_prefix = I 225 | dotnet_naming_style.以_i_开始.required_suffix = 226 | dotnet_naming_style.以_i_开始.word_separator = 227 | dotnet_naming_style.以_i_开始.capitalization = pascal_case 228 | 229 | # IDE0010: 添加缺失的事例 230 | dotnet_diagnostic.IDE0010.severity = none 231 | 232 | # IDE0011: 添加大括号 233 | dotnet_diagnostic.IDE0011.severity = none 234 | 235 | # IDE0040: 添加可访问性修饰符 236 | dotnet_diagnostic.IDE0040.severity = none 237 | 238 | # IDE0130: 命名空间与文件夹结构不匹配 239 | dotnet_style_namespace_match_folder = false 240 | 241 | # IDE0130: 命名空间与文件夹结构不匹配 242 | dotnet_diagnostic.IDE0130.severity = none 243 | 244 | # IDE0055: 修正格式 245 | dotnet_diagnostic.IDE0055.severity = error 246 | 247 | # IDE1006: 命名样式 248 | dotnet_diagnostic.IDE1006.severity = error 249 | 250 | # SA1600: Elements should be documented 251 | dotnet_diagnostic.SA1600.severity = none 252 | 253 | # SA1629: Documentation text should end with a period 254 | dotnet_diagnostic.SA1629.severity = silent 255 | 256 | # SA1101: Prefix local calls with this 257 | dotnet_diagnostic.SA1101.severity = silent 258 | 259 | # SA1623: Property summary documentation should match accessors 260 | dotnet_diagnostic.SA1623.severity = none 261 | 262 | # SA1200: Using directives should be placed correctly 263 | dotnet_diagnostic.SA1200.severity = none 264 | 265 | # SA1208: System using directives should be placed before other using directives 266 | dotnet_diagnostic.SA1208.severity = silent 267 | 268 | # Default severity for analyzer diagnostics with category 'StyleCop.CSharp.LayoutRules' 269 | dotnet_analyzer_diagnostic.category-StyleCop.CSharp.LayoutRules.severity = error 270 | 271 | # SA1400: Access modifier should be declared 272 | dotnet_diagnostic.SA1400.severity = silent 273 | 274 | # SA1633: File should have header 275 | dotnet_diagnostic.SA1633.severity = silent 276 | 277 | # SA1128: Put constructor initializers on their own line 278 | dotnet_diagnostic.SA1128.severity = silent 279 | 280 | # SA1413: Use trailing comma in multi-line initializers 281 | dotnet_diagnostic.SA1413.severity = suggestion 282 | 283 | # SA1005: Single line comments should begin with single space 284 | dotnet_diagnostic.SA1005.severity = none 285 | 286 | # SA1515: Single-line comment should be preceded by blank line 287 | dotnet_diagnostic.SA1515.severity = silent 288 | 289 | # SA1512: Single-line comments should not be followed by blank line 290 | dotnet_diagnostic.SA1512.severity = silent 291 | 292 | # SA1122: Use string.Empty for empty strings 293 | dotnet_diagnostic.SA1122.severity = silent 294 | 295 | # SA1616: Element return value documentation should have text 296 | dotnet_diagnostic.SA1616.severity = silent 297 | 298 | # SA1310: Field names should not contain underscore 299 | dotnet_diagnostic.SA1310.severity = silent 300 | 301 | # SA1137: Elements should have the same indentation 302 | dotnet_diagnostic.SA1137.severity = error 303 | 304 | # SA1503: Braces should not be omitted 305 | dotnet_diagnostic.SA1503.severity = silent 306 | 307 | # SA1513: Closing brace should be followed by blank line 308 | dotnet_diagnostic.SA1513.severity = silent 309 | 310 | # SA1402: File may only contain a single type 311 | dotnet_diagnostic.SA1402.severity = silent 312 | 313 | # SA1133: Do not combine attributes 314 | dotnet_diagnostic.SA1133.severity = silent 315 | 316 | # SA1011: Closing square brackets should be spaced correctly 317 | dotnet_diagnostic.SA1011.severity = silent 318 | 319 | # SA1502: Element should not be on a single line 320 | dotnet_diagnostic.SA1502.severity = silent 321 | 322 | # SA1201: Elements should appear in the correct order 323 | dotnet_diagnostic.SA1201.severity = silent 324 | 325 | # SA1505: Opening braces should not be followed by blank line 326 | dotnet_diagnostic.SA1505.severity = silent 327 | 328 | # SA1508: Closing braces should not be preceded by blank line 329 | dotnet_diagnostic.SA1508.severity = silent 330 | 331 | # SA1614: Element parameter documentation should have text 332 | dotnet_diagnostic.SA1614.severity = silent 333 | 334 | # SA1116: Split parameters should start on line after declaration 335 | dotnet_diagnostic.SA1116.severity = silent 336 | 337 | # SA1601: Partial elements should be documented 338 | dotnet_diagnostic.SA1601.severity = silent 339 | 340 | # SA1009: Closing parenthesis should be spaced correctly 341 | dotnet_diagnostic.SA1009.severity = silent 342 | 343 | # SA1202: Elements should be ordered by access 344 | dotnet_diagnostic.SA1202.severity = silent 345 | 346 | # SA1311: Static readonly fields should begin with upper-case letter 347 | dotnet_diagnostic.SA1311.severity = silent 348 | 349 | # SA1127: Generic type constraints should be on their own line 350 | dotnet_diagnostic.SA1127.severity = silent 351 | 352 | # SA1503: Braces should not be omitted 353 | dotnet_diagnostic.SA1503.severity = silent 354 | 355 | # SA1649: File name should match first type name 356 | dotnet_diagnostic.SA1649.severity = silent 357 | 358 | # SA1210: Using directives should be ordered alphabetically by namespace 359 | dotnet_diagnostic.SA1210.severity = silent 360 | 361 | # SA1028: Code should not contain trailing whitespace 362 | dotnet_diagnostic.SA1028.severity = silent 363 | 364 | # SA1204: Static elements should appear before instance elements 365 | dotnet_diagnostic.SA1204.severity = silent 366 | 367 | # SA1203: Constants should appear before fields 368 | dotnet_diagnostic.SA1203.severity = silent 369 | 370 | # SA1123: Do not place regions within elements 371 | dotnet_diagnostic.SA1123.severity = silent 372 | 373 | # SA1615: Element return value should be documented 374 | dotnet_diagnostic.SA1615.severity = silent 375 | 376 | # SA1611: Element parameters should be documented 377 | dotnet_diagnostic.SA1611.severity = silent 378 | 379 | # SA1124: Do not use regions 380 | dotnet_diagnostic.SA1124.severity = silent 381 | 382 | # SA1520: Use braces consistently 383 | dotnet_diagnostic.SA1520.severity = silent 384 | 385 | # SA1107: Code should not contain multiple statements on one line 386 | dotnet_diagnostic.SA1107.severity = silent 387 | 388 | # SA1312: Variable names should begin with lower-case letter 389 | dotnet_diagnostic.SA1312.severity = error 390 | 391 | # SA1519: Braces should not be omitted from multi-line child statement 392 | dotnet_diagnostic.SA1519.severity = silent 393 | 394 | # SA1000: Keywords should be spaced correctly 395 | dotnet_diagnostic.SA1000.severity = silent 396 | 397 | # SA1205: Partial elements should declare access 398 | dotnet_diagnostic.SA1205.severity = silent 399 | 400 | # SA1401: Fields should be private 401 | dotnet_diagnostic.SA1401.severity = silent 402 | 403 | # SA1622: Generic type parameter documentation should have text 404 | dotnet_diagnostic.SA1622.severity = silent 405 | 406 | # SA1627: Documentation text should not be empty 407 | dotnet_diagnostic.SA1627.severity = silent 408 | 409 | # SA1403: File may only contain a single namespace 410 | dotnet_diagnostic.SA1403.severity = silent 411 | 412 | # SA1602: Enumeration items should be documented 413 | dotnet_diagnostic.SA1602.severity = silent 414 | 415 | # SA1108: Block statements should not contain embedded comments 416 | dotnet_diagnostic.SA1108.severity = silent 417 | 418 | # SA1642: Constructor summary documentation should begin with standard text 419 | dotnet_diagnostic.SA1642.severity = silent 420 | 421 | # SA1117: Parameters should be on same line or separate lines 422 | dotnet_diagnostic.SA1117.severity = silent 423 | 424 | # SA1501: Statement should not be on a single line 425 | dotnet_diagnostic.SA1501.severity = silent 426 | 427 | # SA1500: Braces for multi-line statements should not share line 428 | dotnet_diagnostic.SA1500.severity = silent 429 | 430 | # SA1518: Use line endings correctly at end of file 431 | dotnet_diagnostic.SA1518.severity = silent 432 | 433 | # SA1118: Parameter should not span multiple lines 434 | dotnet_diagnostic.SA1118.severity = silent 435 | 436 | # SA1214: Readonly fields should appear before non-readonly fields 437 | dotnet_diagnostic.SA1214.severity = silent 438 | 439 | # SA1309: Field names should not begin with underscore 440 | dotnet_diagnostic.SA1309.severity = silent 441 | 442 | # SA1027: Use tabs correctly 443 | dotnet_diagnostic.SA1027.severity = silent 444 | 445 | # SA1306: Field names should begin with lower-case letter 446 | dotnet_diagnostic.SA1306.severity = silent 447 | 448 | # SA1643: Destructor summary documentation should begin with standard text 449 | dotnet_diagnostic.SA1643.severity = silent 450 | 451 | # SA1303: Const field names should begin with upper-case letter 452 | dotnet_diagnostic.SA1303.severity = silent 453 | 454 | # SA1300: Element should begin with upper-case letter 455 | dotnet_diagnostic.SA1300.severity = silent 456 | 457 | # SA1316: Tuple element names should use correct casing 458 | dotnet_diagnostic.SA1316.severity = silent 459 | --------------------------------------------------------------------------------