qol: simplify default

This commit is contained in:
Gary Sharp
2025-07-20 15:31:35 +10:00
parent 9656c15c4b
commit 58546ed16d
13 changed files with 22 additions and 26 deletions
@@ -282,7 +282,7 @@ namespace Disco.Data.Configuration
Type valueType = typeof(T);
string stringValue;
if (comparer.Equals(Value, default(T)))
if (comparer.Equals(Value, default))
{
stringValue = null;
}
+3 -3
View File
@@ -86,12 +86,12 @@ namespace Disco.Services
// Batch
DeviceBatch db = default(DeviceBatch);
var db = default(DeviceBatch);
if (d.DeviceBatchId.HasValue)
db = Database.DeviceBatches.Find(d.DeviceBatchId.Value);
// Default Device Model
DeviceModel dm = default(DeviceModel);
var dm = default(DeviceModel);
if (db != null && db.DefaultDeviceModelId.HasValue)
dm = Database.DeviceModels.Find(db.DefaultDeviceModelId); // From Batch
else
@@ -158,7 +158,7 @@ namespace Disco.Services
public static DeviceUserAssignment AssignDevice(this Device d, DiscoDataContext Database, User u)
{
DeviceUserAssignment newDua = default(DeviceUserAssignment);
DeviceUserAssignment newDua = default;
// Mark existing assignments as Unassigned
foreach (var dua in Database.DeviceUserAssignments.Where(m => m.DeviceSerialNumber == d.SerialNumber && !m.UnassignedDate.HasValue))
+1 -1
View File
@@ -45,7 +45,7 @@ namespace Disco.Services.Expressions
public T EvaluateFirst<T>(object ExpressionContext, IDictionary Variables)
{
T result = default(T);
T result = default;
if (Count > 0)
{
try
@@ -28,7 +28,7 @@ namespace Disco.Services.Expressions.Extensions
{
var objectValue = GetActiveDirectoryObjectValue(Device, PropertyName, Index);
if (objectValue == null)
return default(int);
return default;
else
{
int intValue;
@@ -32,7 +32,7 @@ namespace Disco.Services.Expressions.Extensions
{
var objectValue = GetActiveDirectoryObjectValue(User, PropertyName, Index);
if (objectValue == null)
return default(int);
return default;
else
{
int intValue;
@@ -76,13 +76,10 @@ namespace Disco.Services.Interop.ActiveDirectory
if (result != null)
{
long lastLogonValue = default(long);
long lastLogonTimestampValue = default(long);
var lastLogonValue = result.Value<long>("lastLogon");
var lastLogonTimestampValue = result.Value<long>("lastLogonTimestamp");
lastLogonValue = result.Value<long>("lastLogon");
lastLogonTimestampValue = result.Value<long>("lastLogonTimestamp");
long highedValue = Math.Max(lastLogonValue, lastLogonTimestampValue);
var highedValue = Math.Max(lastLogonValue, lastLogonTimestampValue);
if (highedValue > 0)
return (DateTime?)new DateTime((DateTime.FromFileTime(highedValue).Ticks / 10000000L) * 10000000L);
@@ -151,8 +148,8 @@ namespace Disco.Services.Interop.ActiveDirectory
{
var samAccountName = result.Value<string>("sAMAccountName");
long lastLogonValue = default(long);
long lastLogonTimestampValue = default(long);
long lastLogonValue = default;
long lastLogonTimestampValue = default;
lastLogonValue = result.Value<long>("lastLogon");
lastLogonTimestampValue = result.Value<long>("lastLogonTimestamp");
+3 -4
View File
@@ -17,15 +17,14 @@ namespace Disco.Services.Searching
#region Jobs
public static List<JobSearchResultItem> SearchJobs(DiscoDataContext Database, string Term, int? LimitCount = ActiveDirectory.DefaultSearchResultLimit)
{
IQueryable<Job> query = default(IQueryable<Job>);
var query = (IQueryable<Job>)Database.Jobs;
string userIdTerm = Term.Contains('\\') ? Term : ActiveDirectory.ParseDomainAccountId(Term);
if (int.TryParse(Term, out var termInt))
{
// Term is a Number (int)
query = Database.Jobs.Where(j =>
query = query.Where(j =>
j.Id == termInt ||
j.Device.SerialNumber.Contains(Term) ||
j.Device.AssetNumber.Contains(Term) ||
@@ -34,7 +33,7 @@ namespace Disco.Services.Searching
}
else
{
query = Database.Jobs.Where(j =>
query = query.Where(j =>
j.Device.SerialNumber.Contains(Term) ||
j.Device.AssetNumber.Contains(Term) ||
j.User.UserId == userIdTerm ||
@@ -10,7 +10,7 @@ namespace Disco.Web.Extensions
{
public static List<SelectListItem> ToSelectListItems(this IEnumerable<OrganisationAddress> organisationAddressess, OrganisationAddress SelectedItem)
{
int? selectedId = default(int?);
var selectedId = default(int?);
if (SelectedItem != null)
selectedId = SelectedItem.Id;
@@ -59,7 +59,7 @@ namespace Disco.Web.Extensions
public static List<SelectListItem> ToSelectListItems(this IEnumerable<PluginManifest> PluginFeatureDefinitions, PluginManifest SelectedItem)
{
string selectedId = default(string);
var selectedId = default(string);
if (SelectedItem != null)
selectedId = SelectedItem.Id;
@@ -9,7 +9,7 @@ namespace Disco.Web.Extensions
{
public static List<SelectListItem> ToSelectListItems(this IEnumerable<JobSubType> jobSubTypes, IEnumerable<JobSubType> SelectedItems, bool IncludeQueueIcons = false)
{
List<string> selectedIds = default(List<string>);
var selectedIds = default(List<string>);
if (SelectedItems != null)
selectedIds = SelectedItems.Select(i => $"{i.JobTypeId}_{i.Id}").ToList();
@@ -9,7 +9,7 @@ namespace Disco.Web.Extensions
{
public static List<SelectListItem> ToSelectListItems(this IEnumerable<JobType> jobTypes, JobType SelectedItem)
{
string selectedId = default(string);
var selectedId = default(string);
if (SelectedItem != null)
selectedId = SelectedItem.Id;
@@ -27,7 +27,7 @@ namespace Disco.Web.Extensions
public static List<SelectListItem> ToSelectListItems(this IEnumerable<JobType> jobTypes, IEnumerable<JobType> SelectedItems)
{
List<string> selectedIds = default(List<string>);
var selectedIds = default(List<string>);
if (SelectedItems != null)
selectedIds = SelectedItems.Select(i => i.Id).ToList();
+1 -1
View File
@@ -49,7 +49,7 @@ namespace Disco.Web.Models.Job
public string ProviderPropertiesJson { get; set; }
public Dictionary<string, string> ProviderProperties()
{
Dictionary<string, string> p = default(Dictionary<string, string>);
var p = default(Dictionary<string, string>);
if (!string.IsNullOrEmpty(ProviderPropertiesJson))
{
try
+1 -1
View File
@@ -50,7 +50,7 @@ namespace Disco.Web.Models.Job
public string ProviderPropertiesJson { get; set; }
public Dictionary<string, string> ProviderProperties()
{
Dictionary<string, string> p = default(Dictionary<string, string>);
var p = default(Dictionary<string, string>);
if (!string.IsNullOrEmpty(ProviderPropertiesJson))
{
try