mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
Removal of ToArray()
This commit is contained in:
parent
9eb22da9e7
commit
9f5cf132f0
41 changed files with 184 additions and 189 deletions
|
|
@ -173,13 +173,13 @@ namespace ServerManagerTool.Common.Model
|
|||
|
||||
if (property.GetValue(this) is IIniValuesCollection collection)
|
||||
{
|
||||
var values = SplitCollectionValues(kvPropertyValue, DELIMITER);
|
||||
values = values.Where(v => !string.IsNullOrWhiteSpace(v)).ToArray();
|
||||
var values = SplitCollectionValues(kvPropertyValue, DELIMITER)
|
||||
.Where(v => !string.IsNullOrWhiteSpace(v));
|
||||
|
||||
if (attr?.ListValueWithinBrackets ?? false)
|
||||
{
|
||||
values = values.Select(v => v.Substring(1)).ToArray();
|
||||
values = values.Select(v => v.Substring(0, v.Length - 1)).ToArray();
|
||||
values = values.Select(v => v.Substring(1));
|
||||
values = values.Select(v => v.Substring(0, v.Length - 1));
|
||||
}
|
||||
collection.FromIniValues(values);
|
||||
}
|
||||
|
|
@ -266,7 +266,7 @@ namespace ServerManagerTool.Common.Model
|
|||
return result.ToString();
|
||||
}
|
||||
|
||||
protected string[] SplitCollectionValues(string valueString, char delimiter)
|
||||
protected IEnumerable<string> SplitCollectionValues(string valueString, char delimiter)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(valueString))
|
||||
return new string[0];
|
||||
|
|
@ -306,7 +306,7 @@ namespace ServerManagerTool.Common.Model
|
|||
|
||||
result.Add(tempString.Substring(startIndex));
|
||||
|
||||
return result.ToArray();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Update(AggregateIniValue other)
|
||||
|
|
|
|||
|
|
@ -59,17 +59,16 @@ namespace ServerManagerTool.Common.Model
|
|||
|
||||
public virtual void FromIniValues(IEnumerable<string> iniValues)
|
||||
{
|
||||
var items = iniValues?.Select(AggregateIniValue.FromINIValue<T>).ToArray();
|
||||
var items = iniValues?.Select(AggregateIniValue.FromINIValue<T>);
|
||||
|
||||
Clear();
|
||||
AddRange(items);
|
||||
IsEnabled = (Count != 0);
|
||||
IsEnabled = (Count > 0);
|
||||
|
||||
// Add any default values which were missing
|
||||
if (_resetFunc != null)
|
||||
{
|
||||
var defaultItemsToAdd = _resetFunc().Where(r => !this.Any(v => v.IsEquivalent(r))).ToArray();
|
||||
AddRange(defaultItemsToAdd);
|
||||
AddRange(_resetFunc().Where(r => !this.Any(v => v.IsEquivalent(r))));
|
||||
}
|
||||
|
||||
Sort(AggregateIniValue.SortKeySelector);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using ServerManagerTool.Common.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ServerManagerTool.Common.Model
|
||||
|
|
@ -14,12 +15,12 @@ namespace ServerManagerTool.Common.Model
|
|||
}
|
||||
}
|
||||
|
||||
public void Add(string sectionName, string[] values)
|
||||
public void Add(string sectionName, IEnumerable<string> values)
|
||||
{
|
||||
Add(sectionName, values, true);
|
||||
}
|
||||
|
||||
public void Add(string sectionName, string[] values, bool clearExisting)
|
||||
public void Add(string sectionName, IEnumerable<string> values, bool clearExisting)
|
||||
{
|
||||
var section = this.Items.FirstOrDefault(s => s.SectionName.Equals(sectionName, StringComparison.OrdinalIgnoreCase) && !s.IsDeleted);
|
||||
if (section == null)
|
||||
|
|
|
|||
|
|
@ -98,8 +98,7 @@ namespace ServerManagerTool.Common.Model
|
|||
// Add any default values which were missing
|
||||
if (this.ResetFunc != null)
|
||||
{
|
||||
var defaultItemsToAdd = this.ResetFunc().Where(r => !this.Any(v => this.EquivalencyFunc(v, r))).ToArray();
|
||||
this.AddRange(defaultItemsToAdd);
|
||||
this.AddRange(this.ResetFunc().Where(r => !this.Any(v => this.EquivalencyFunc(v, r))));
|
||||
this.Sort(this.SortKeySelectorFunc);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
|
|
@ -68,16 +69,15 @@ namespace ServerManagerTool.Common.Model
|
|||
|
||||
public void Remove(string steamId)
|
||||
{
|
||||
var items = this.Where(i => i.PlayerId.Equals(steamId, System.StringComparison.OrdinalIgnoreCase)).ToArray();
|
||||
foreach (var item in items)
|
||||
foreach (var item in this.Where(i => i.PlayerId.Equals(steamId, System.StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
this.Remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
public string[] ToArray()
|
||||
public IEnumerable<string> ToEnumerable()
|
||||
{
|
||||
return this.Select(i => i.PlayerId).ToArray();
|
||||
return this.Select(i => i.PlayerId);
|
||||
}
|
||||
|
||||
public string ToDelimitedString(string delimiter)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace ServerManagerTool.Common.Model
|
|||
var tableValue = value as VdfTable;
|
||||
if (tableValue != null && tableValue.Count > 0)
|
||||
{
|
||||
var betaKeyItems = tableValue.Where(v => v.Name.Equals("betakey", StringComparison.OrdinalIgnoreCase)).ToArray();
|
||||
var betaKeyItems = tableValue.Where(v => v.Name.Equals("betakey", StringComparison.OrdinalIgnoreCase));
|
||||
foreach (var item in betaKeyItems)
|
||||
{
|
||||
tableValue.Remove(item);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue