mirror of
https://github.com/GoodOlClint/PSProxmoxVE.git
synced 2026-08-18 17:06:18 +00:00
fix: resolve net48-only nullable warnings (CS8601, CS8602, CS8604)
- CS8601: Add null-forgiving operator on guarded dictionary assignments in cmdlets where IsNullOrEmpty check precedes the assignment - CS8602: Add Assert.NotNull after JObject["data"] in xUnit model tests (JToken indexer returns nullable on net48) - CS8604: Add null-forgiving on guarded arguments in NodeService, WaitPveTaskCmdlet, GetPveTemplateCmdlet, and auth test parameters Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -52,7 +52,7 @@ namespace PSProxmoxVE.Core.Services
|
||||
var versionStr = data?["version"]?.ToString();
|
||||
if (string.IsNullOrEmpty(versionStr))
|
||||
throw new InvalidOperationException("Failed to retrieve PVE version from API response.");
|
||||
return PveVersion.Parse(versionStr);
|
||||
return PveVersion.Parse(versionStr!);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,11 +73,11 @@ namespace PSProxmoxVE.Cmdlets.CloudInit
|
||||
|
||||
var config = new Dictionary<string, object>();
|
||||
|
||||
if (!string.IsNullOrEmpty(CiUser)) config["ciuser"] = CiUser;
|
||||
if (!string.IsNullOrEmpty(Hostname)) config["name"] = Hostname;
|
||||
if (!string.IsNullOrEmpty(IpConfig0)) config["ipconfig0"] = IpConfig0;
|
||||
if (!string.IsNullOrEmpty(Nameserver)) config["nameserver"] = Nameserver;
|
||||
if (!string.IsNullOrEmpty(Searchdomain)) config["searchdomain"] = Searchdomain;
|
||||
if (!string.IsNullOrEmpty(CiUser)) config["ciuser"] = CiUser!;
|
||||
if (!string.IsNullOrEmpty(Hostname)) config["name"] = Hostname!;
|
||||
if (!string.IsNullOrEmpty(IpConfig0)) config["ipconfig0"] = IpConfig0!;
|
||||
if (!string.IsNullOrEmpty(Nameserver)) config["nameserver"] = Nameserver!;
|
||||
if (!string.IsNullOrEmpty(Searchdomain)) config["searchdomain"] = Searchdomain!;
|
||||
|
||||
if (Password != null)
|
||||
{
|
||||
|
||||
@@ -78,15 +78,15 @@ namespace PSProxmoxVE.Cmdlets.Network
|
||||
["type"] = Type
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(Address)) data["address"] = Address;
|
||||
if (!string.IsNullOrEmpty(Netmask)) data["netmask"] = Netmask;
|
||||
if (!string.IsNullOrEmpty(Gateway)) data["gateway"] = Gateway;
|
||||
if (!string.IsNullOrEmpty(BridgePorts)) data["bridge_ports"] = BridgePorts;
|
||||
if (!string.IsNullOrEmpty(BondSlaves)) data["slaves"] = BondSlaves;
|
||||
if (!string.IsNullOrEmpty(Address)) data["address"] = Address!;
|
||||
if (!string.IsNullOrEmpty(Netmask)) data["netmask"] = Netmask!;
|
||||
if (!string.IsNullOrEmpty(Gateway)) data["gateway"] = Gateway!;
|
||||
if (!string.IsNullOrEmpty(BridgePorts)) data["bridge_ports"] = BridgePorts!;
|
||||
if (!string.IsNullOrEmpty(BondSlaves)) data["slaves"] = BondSlaves!;
|
||||
if (VlanId.HasValue) data["vlan-id"] = VlanId.Value.ToString();
|
||||
if (Mtu.HasValue) data["mtu"] = Mtu.Value.ToString();
|
||||
if (Autostart.IsPresent) data["autostart"] = "1";
|
||||
if (!string.IsNullOrEmpty(Comments)) data["comments"] = Comments;
|
||||
if (!string.IsNullOrEmpty(Comments)) data["comments"] = Comments!;
|
||||
|
||||
client.PostAsync($"nodes/{Node}/network", data).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace PSProxmoxVE.Cmdlets.Network
|
||||
};
|
||||
|
||||
if (Tag.HasValue) data["tag"] = Tag.Value.ToString();
|
||||
if (!string.IsNullOrEmpty(Alias)) data["alias"] = Alias;
|
||||
if (!string.IsNullOrEmpty(Alias)) data["alias"] = Alias!;
|
||||
if (VlanAware.IsPresent) data["vlanaware"] = "1";
|
||||
|
||||
client.PostAsync("cluster/sdn/vnets", data).GetAwaiter().GetResult();
|
||||
|
||||
@@ -64,13 +64,13 @@ namespace PSProxmoxVE.Cmdlets.Network
|
||||
["type"] = Type
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(Peers)) data["peers"] = Peers;
|
||||
if (!string.IsNullOrEmpty(Bridge)) data["bridge"] = Bridge;
|
||||
if (!string.IsNullOrEmpty(Peers)) data["peers"] = Peers!;
|
||||
if (!string.IsNullOrEmpty(Bridge)) data["bridge"] = Bridge!;
|
||||
if (Mtu.HasValue) data["mtu"] = Mtu.Value.ToString();
|
||||
if (!string.IsNullOrEmpty(Dns)) data["dns"] = Dns;
|
||||
if (!string.IsNullOrEmpty(ReverseDns)) data["reversedns"] = ReverseDns;
|
||||
if (!string.IsNullOrEmpty(DnsZone)) data["dnszone"] = DnsZone;
|
||||
if (!string.IsNullOrEmpty(Ipam)) data["ipam"] = Ipam;
|
||||
if (!string.IsNullOrEmpty(Dns)) data["dns"] = Dns!;
|
||||
if (!string.IsNullOrEmpty(ReverseDns)) data["reversedns"] = ReverseDns!;
|
||||
if (!string.IsNullOrEmpty(DnsZone)) data["dnszone"] = DnsZone!;
|
||||
if (!string.IsNullOrEmpty(Ipam)) data["ipam"] = Ipam!;
|
||||
|
||||
client.PostAsync("cluster/sdn/zones", data).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
@@ -76,17 +76,17 @@ namespace PSProxmoxVE.Cmdlets.Network
|
||||
|
||||
var data = new Dictionary<string, string>();
|
||||
|
||||
if (!string.IsNullOrEmpty(Address)) data["address"] = Address;
|
||||
if (!string.IsNullOrEmpty(Netmask)) data["netmask"] = Netmask;
|
||||
if (!string.IsNullOrEmpty(Gateway)) data["gateway"] = Gateway;
|
||||
if (!string.IsNullOrEmpty(Address6)) data["address6"] = Address6;
|
||||
if (!string.IsNullOrEmpty(Address)) data["address"] = Address!;
|
||||
if (!string.IsNullOrEmpty(Netmask)) data["netmask"] = Netmask!;
|
||||
if (!string.IsNullOrEmpty(Gateway)) data["gateway"] = Gateway!;
|
||||
if (!string.IsNullOrEmpty(Address6)) data["address6"] = Address6!;
|
||||
if (Netmask6.HasValue) data["netmask6"] = Netmask6.Value.ToString();
|
||||
if (!string.IsNullOrEmpty(Gateway6)) data["gateway6"] = Gateway6;
|
||||
if (!string.IsNullOrEmpty(BridgePorts)) data["bridge_ports"] = BridgePorts;
|
||||
if (!string.IsNullOrEmpty(BondSlaves)) data["slaves"] = BondSlaves;
|
||||
if (!string.IsNullOrEmpty(Gateway6)) data["gateway6"] = Gateway6!;
|
||||
if (!string.IsNullOrEmpty(BridgePorts)) data["bridge_ports"] = BridgePorts!;
|
||||
if (!string.IsNullOrEmpty(BondSlaves)) data["slaves"] = BondSlaves!;
|
||||
if (Mtu.HasValue) data["mtu"] = Mtu.Value.ToString();
|
||||
if (Autostart.IsPresent) data["autostart"] = "1";
|
||||
if (!string.IsNullOrEmpty(Comments)) data["comments"] = Comments;
|
||||
if (!string.IsNullOrEmpty(Comments)) data["comments"] = Comments!;
|
||||
|
||||
client.PutAsync($"nodes/{Node}/network/{Iface}", data).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace PSProxmoxVE.Cmdlets.Snapshots
|
||||
{
|
||||
["snapname"] = Name
|
||||
};
|
||||
if (!string.IsNullOrEmpty(Description)) data["description"] = Description;
|
||||
if (!string.IsNullOrEmpty(Description)) data["description"] = Description!;
|
||||
if (IncludeVmState.IsPresent) data["vmstate"] = "1";
|
||||
|
||||
var json = client.PostAsync($"nodes/{Node}/qemu/{VmId}/snapshot", data).GetAwaiter().GetResult();
|
||||
|
||||
@@ -89,16 +89,16 @@ namespace PSProxmoxVE.Cmdlets.Storage
|
||||
["type"] = Type
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(Content)) data["content"] = Content;
|
||||
if (!string.IsNullOrEmpty(Path)) data["path"] = Path;
|
||||
if (!string.IsNullOrEmpty(Server)) data["server"] = Server;
|
||||
if (!string.IsNullOrEmpty(Export)) data["export"] = Export;
|
||||
if (!string.IsNullOrEmpty(VgName)) data["vgname"] = VgName;
|
||||
if (!string.IsNullOrEmpty(ThinPool)) data["thinpool"] = ThinPool;
|
||||
if (!string.IsNullOrEmpty(Pool)) data["pool"] = Pool;
|
||||
if (!string.IsNullOrEmpty(CephPool)) data["pool"] = CephPool;
|
||||
if (!string.IsNullOrEmpty(MonHost)) data["monhost"] = MonHost;
|
||||
if (!string.IsNullOrEmpty(Nodes)) data["nodes"] = Nodes;
|
||||
if (!string.IsNullOrEmpty(Content)) data["content"] = Content!;
|
||||
if (!string.IsNullOrEmpty(Path)) data["path"] = Path!;
|
||||
if (!string.IsNullOrEmpty(Server)) data["server"] = Server!;
|
||||
if (!string.IsNullOrEmpty(Export)) data["export"] = Export!;
|
||||
if (!string.IsNullOrEmpty(VgName)) data["vgname"] = VgName!;
|
||||
if (!string.IsNullOrEmpty(ThinPool)) data["thinpool"] = ThinPool!;
|
||||
if (!string.IsNullOrEmpty(Pool)) data["pool"] = Pool!;
|
||||
if (!string.IsNullOrEmpty(CephPool)) data["pool"] = CephPool!;
|
||||
if (!string.IsNullOrEmpty(MonHost)) data["monhost"] = MonHost!;
|
||||
if (!string.IsNullOrEmpty(Nodes)) data["nodes"] = Nodes!;
|
||||
if (Shared.IsPresent) data["shared"] = "1";
|
||||
if (Disable.IsPresent) data["disable"] = "1";
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace PSProxmoxVE.Cmdlets.Tasks
|
||||
};
|
||||
|
||||
if (!task.IsSuccessful && !string.IsNullOrEmpty(exitStatus) && exitStatus != "OK")
|
||||
throw new PveTaskFailedException(Upid, exitStatus);
|
||||
throw new PveTaskFailedException(Upid, exitStatus!);
|
||||
|
||||
WriteObject(task);
|
||||
return;
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace PSProxmoxVE.Cmdlets.Templates
|
||||
|
||||
if (!string.IsNullOrEmpty(Node))
|
||||
{
|
||||
nodesToQuery.Add(Node);
|
||||
nodesToQuery.Add(Node!);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -62,7 +62,7 @@ namespace PSProxmoxVE.Cmdlets.Templates
|
||||
|
||||
if (!string.IsNullOrEmpty(Name) && vm.Name != null)
|
||||
{
|
||||
var pattern = Name.Replace("*", "");
|
||||
var pattern = Name!.Replace("*", "");
|
||||
if (Name.Contains("*"))
|
||||
{
|
||||
if (vm.Name.IndexOf(pattern, System.StringComparison.OrdinalIgnoreCase) < 0)
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace PSProxmoxVE.Cmdlets.Users
|
||||
if (string.IsNullOrEmpty(UserId))
|
||||
return true;
|
||||
|
||||
if (UserId.Contains("*"))
|
||||
if (UserId!.Contains("*"))
|
||||
{
|
||||
var pattern = UserId.Replace("*", "");
|
||||
return user.UserId.IndexOf(pattern, System.StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace PSProxmoxVE.Cmdlets.Users
|
||||
{
|
||||
["roleid"] = RoleId
|
||||
};
|
||||
if (!string.IsNullOrEmpty(Privileges)) data["privs"] = Privileges;
|
||||
if (!string.IsNullOrEmpty(Privileges)) data["privs"] = Privileges!;
|
||||
|
||||
client.PostAsync("access/roles", data).GetAwaiter().GetResult();
|
||||
|
||||
|
||||
@@ -63,11 +63,11 @@ namespace PSProxmoxVE.Cmdlets.Users
|
||||
finally { Marshal.ZeroFreeGlobalAllocUnicode(ptr); }
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(FirstName)) config["firstname"] = FirstName;
|
||||
if (!string.IsNullOrEmpty(LastName)) config["lastname"] = LastName;
|
||||
if (!string.IsNullOrEmpty(Email)) config["email"] = Email;
|
||||
if (!string.IsNullOrEmpty(Groups)) config["groups"] = Groups;
|
||||
if (!string.IsNullOrEmpty(Comment)) config["comment"] = Comment;
|
||||
if (!string.IsNullOrEmpty(FirstName)) config["firstname"] = FirstName!;
|
||||
if (!string.IsNullOrEmpty(LastName)) config["lastname"] = LastName!;
|
||||
if (!string.IsNullOrEmpty(Email)) config["email"] = Email!;
|
||||
if (!string.IsNullOrEmpty(Groups)) config["groups"] = Groups!;
|
||||
if (!string.IsNullOrEmpty(Comment)) config["comment"] = Comment!;
|
||||
if (Expire.HasValue) config["expire"] = Expire.Value;
|
||||
|
||||
var session = GetSession();
|
||||
|
||||
@@ -65,11 +65,11 @@ namespace PSProxmoxVE.Cmdlets.Users
|
||||
finally { Marshal.ZeroFreeGlobalAllocUnicode(ptr); }
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(FirstName)) config["firstname"] = FirstName;
|
||||
if (!string.IsNullOrEmpty(LastName)) config["lastname"] = LastName;
|
||||
if (!string.IsNullOrEmpty(Email)) config["email"] = Email;
|
||||
if (!string.IsNullOrEmpty(Groups)) config["groups"] = Groups;
|
||||
if (!string.IsNullOrEmpty(Comment)) config["comment"] = Comment;
|
||||
if (!string.IsNullOrEmpty(FirstName)) config["firstname"] = FirstName!;
|
||||
if (!string.IsNullOrEmpty(LastName)) config["lastname"] = LastName!;
|
||||
if (!string.IsNullOrEmpty(Email)) config["email"] = Email!;
|
||||
if (!string.IsNullOrEmpty(Groups)) config["groups"] = Groups!;
|
||||
if (!string.IsNullOrEmpty(Comment)) config["comment"] = Comment!;
|
||||
if (Expire.HasValue) config["expire"] = Expire.Value;
|
||||
if (Enable.HasValue) config["enable"] = Enable.Value ? "1" : "0";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user