@@ -124,21 +124,21 @@ public static async Task<List<FirewallRule>> GetRulesAsync()
124124
125125 var rule = new FirewallRule
126126 {
127- Id = result . Properties [ "Id" ] ? . Value ? . ToString ( ) ?? string . Empty ,
128- IsEnabled = result . Properties [ "Enabled" ] ? . Value as bool ? == true ,
129- Name = displayName . StartsWith ( RuleIdentifier , StringComparison . Ordinal )
127+ Id = result . Properties [ "Id" ] ? . Value ? . ToString ( ) ?? string . Empty ,
128+ IsEnabled = result . Properties [ "Enabled" ] ? . Value as bool ? == true ,
129+ Name = displayName . StartsWith ( RuleIdentifier , StringComparison . Ordinal )
130130 ? displayName [ RuleIdentifier . Length .. ]
131131 : displayName ,
132- Description = result . Properties [ "Description" ] ? . Value ? . ToString ( ) ?? string . Empty ,
133- Direction = ParseDirection ( result . Properties [ "Direction" ] ? . Value ? . ToString ( ) ) ,
134- Action = ParseAction ( result . Properties [ "Action" ] ? . Value ? . ToString ( ) ) ,
135- Protocol = ParseProtocol ( result . Properties [ "Protocol" ] ? . Value ? . ToString ( ) ) ,
136- LocalPorts = ParsePorts ( result . Properties [ "LocalPort" ] ? . Value ? . ToString ( ) ) ,
137- RemotePorts = ParsePorts ( result . Properties [ "RemotePort" ] ? . Value ? . ToString ( ) ) ,
138- LocalAddresses = ParseAddresses ( result . Properties [ "LocalAddress" ] ? . Value ? . ToString ( ) ) ,
132+ Description = result . Properties [ "Description" ] ? . Value ? . ToString ( ) ?? string . Empty ,
133+ Direction = ParseDirection ( result . Properties [ "Direction" ] ? . Value ? . ToString ( ) ) ,
134+ Action = ParseAction ( result . Properties [ "Action" ] ? . Value ? . ToString ( ) ) ,
135+ Protocol = ParseProtocol ( result . Properties [ "Protocol" ] ? . Value ? . ToString ( ) ) ,
136+ LocalPorts = ParsePorts ( result . Properties [ "LocalPort" ] ? . Value ? . ToString ( ) ) ,
137+ RemotePorts = ParsePorts ( result . Properties [ "RemotePort" ] ? . Value ? . ToString ( ) ) ,
138+ LocalAddresses = ParseAddresses ( result . Properties [ "LocalAddress" ] ? . Value ? . ToString ( ) ) ,
139139 RemoteAddresses = ParseAddresses ( result . Properties [ "RemoteAddress" ] ? . Value ? . ToString ( ) ) ,
140140 NetworkProfiles = ParseProfile ( result . Properties [ "Profile" ] ? . Value ? . ToString ( ) ) ,
141- InterfaceType = ParseInterfaceType ( result . Properties [ "InterfaceType" ] ? . Value ? . ToString ( ) ) ,
141+ InterfaceType = ParseInterfaceType ( result . Properties [ "InterfaceType" ] ? . Value ? . ToString ( ) ) ,
142142 } ;
143143
144144 var program = result . Properties [ "Program" ] ? . Value as string ;
@@ -327,14 +327,14 @@ private static string BuildAddScript(FirewallRule rule)
327327 /// <param name="protocol">The protocol to convert.</param>
328328 private static string GetProtocolString ( FirewallProtocol protocol ) => protocol switch
329329 {
330- FirewallProtocol . Any => "Any" ,
331- FirewallProtocol . TCP => "TCP" ,
332- FirewallProtocol . UDP => "UDP" ,
330+ FirewallProtocol . Any => "Any" ,
331+ FirewallProtocol . TCP => "TCP" ,
332+ FirewallProtocol . UDP => "UDP" ,
333333 FirewallProtocol . ICMPv4 => "ICMPv4" ,
334334 FirewallProtocol . ICMPv6 => "ICMPv6" ,
335- FirewallProtocol . GRE => "GRE" ,
336- FirewallProtocol . L2TP => "L2TP" ,
337- _ => ( ( int ) protocol ) . ToString ( )
335+ FirewallProtocol . GRE => "GRE" ,
336+ FirewallProtocol . L2TP => "L2TP" ,
337+ _ => ( ( int ) protocol ) . ToString ( )
338338 } ;
339339
340340 /// <summary>
@@ -344,10 +344,10 @@ private static string BuildAddScript(FirewallRule rule)
344344 /// <param name="interfaceType">The interface type to convert.</param>
345345 private static string GetInterfaceTypeString ( FirewallInterfaceType interfaceType ) => interfaceType switch
346346 {
347- FirewallInterfaceType . Wired => "Wired" ,
348- FirewallInterfaceType . Wireless => "Wireless" ,
347+ FirewallInterfaceType . Wired => "Wired" ,
348+ FirewallInterfaceType . Wireless => "Wireless" ,
349349 FirewallInterfaceType . RemoteAccess => "RemoteAccess" ,
350- _ => "Any"
350+ _ => "Any"
351351 } ;
352352
353353 /// <summary>
@@ -381,7 +381,7 @@ private static FirewallRuleDirection ParseDirection(string value)
381381 return value switch
382382 {
383383 "Outbound" => FirewallRuleDirection . Outbound ,
384- _ => FirewallRuleDirection . Inbound ,
384+ _ => FirewallRuleDirection . Inbound ,
385385 } ;
386386 }
387387
@@ -397,7 +397,7 @@ private static FirewallRuleAction ParseAction(string value)
397397 return value switch
398398 {
399399 "Allow" => FirewallRuleAction . Allow ,
400- _ => FirewallRuleAction . Block ,
400+ _ => FirewallRuleAction . Block ,
401401 } ;
402402 }
403403
@@ -416,12 +416,12 @@ private static FirewallProtocol ParseProtocol(string value)
416416
417417 return value . ToUpperInvariant ( ) switch
418418 {
419- "TCP" => FirewallProtocol . TCP ,
420- "UDP" => FirewallProtocol . UDP ,
421- "ICMPV4" => FirewallProtocol . ICMPv4 ,
422- "ICMPV6" => FirewallProtocol . ICMPv6 ,
423- "GRE" => FirewallProtocol . GRE ,
424- "L2TP" => FirewallProtocol . L2TP ,
419+ "TCP" => FirewallProtocol . TCP ,
420+ "UDP" => FirewallProtocol . UDP ,
421+ "ICMPV4" => FirewallProtocol . ICMPv4 ,
422+ "ICMPV6" => FirewallProtocol . ICMPv6 ,
423+ "GRE" => FirewallProtocol . GRE ,
424+ "L2TP" => FirewallProtocol . L2TP ,
425425 _ => int . TryParse ( value , out var proto ) ? ( FirewallProtocol ) proto : FirewallProtocol . Any ,
426426 } ;
427427 }
@@ -486,9 +486,9 @@ private static bool[] ParseProfile(string value)
486486 {
487487 switch ( token )
488488 {
489- case "Domain" : profiles [ 0 ] = true ; break ;
489+ case "Domain" : profiles [ 0 ] = true ; break ;
490490 case "Private" : profiles [ 1 ] = true ; break ;
491- case "Public" : profiles [ 2 ] = true ; break ;
491+ case "Public" : profiles [ 2 ] = true ; break ;
492492 }
493493 }
494494
@@ -522,10 +522,10 @@ private static FirewallInterfaceType ParseInterfaceType(string value)
522522 {
523523 return value switch
524524 {
525- "Wired" => FirewallInterfaceType . Wired ,
526- "Wireless" => FirewallInterfaceType . Wireless ,
525+ "Wired" => FirewallInterfaceType . Wired ,
526+ "Wireless" => FirewallInterfaceType . Wireless ,
527527 "RemoteAccess" => FirewallInterfaceType . RemoteAccess ,
528- _ => FirewallInterfaceType . Any ,
528+ _ => FirewallInterfaceType . Any ,
529529 } ;
530530 }
531531
0 commit comments