mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-20 17:08:00 +02:00
collection item dispose mixins, string specific list
This commit is contained in:
parent
d7f0c6523d
commit
38f4b349f2
2 changed files with 73 additions and 0 deletions
|
@ -930,6 +930,59 @@ namespace System.Collections
|
|||
}
|
||||
}
|
||||
|
||||
extension List<T> where T : String
|
||||
{
|
||||
public bool Contains(T item, StringComparison comparison)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
for (int i = 0; i < mSize; i++)
|
||||
if (mItems[i] == null)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < mSize; i++)
|
||||
if (mItems[i].Equals(item, comparison))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public int IndexOf(T item, StringComparison comparison)
|
||||
{
|
||||
for (int i = 0; i < mSize; i++)
|
||||
if (mItems[i].Equals(item, comparison))
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int IndexOf(T item, int index, StringComparison comparison)
|
||||
{
|
||||
for (int i = index; i < mSize; i++)
|
||||
if (mItems[i].Equals(item, comparison))
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int IndexOf(T item, int index, int count, StringComparison comparison)
|
||||
{
|
||||
for (int i = index; i < index + count; i++)
|
||||
if (mItems[i].Equals(item, comparison))
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int LastIndexOf(T item, StringComparison comparison)
|
||||
{
|
||||
for (int i = mSize - 1; i >= 0; i--)
|
||||
if (mItems[i].Equals(item, comparison))
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
class ListWithAlloc<T> : List<T>
|
||||
{
|
||||
IRawAllocator mAlloc;
|
||||
|
|
|
@ -227,6 +227,26 @@ static
|
|||
}
|
||||
}
|
||||
|
||||
public static mixin DeleteContainerAndDisposeItems(var container)
|
||||
{
|
||||
if (container != null)
|
||||
{
|
||||
for (var value in container)
|
||||
value.Dispose();
|
||||
delete container;
|
||||
}
|
||||
}
|
||||
|
||||
public static mixin ClearAndDisposeItems(var container)
|
||||
{
|
||||
if (container != null)
|
||||
{
|
||||
for (var value in container)
|
||||
value.Dispose();
|
||||
container.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static mixin DeleteAndNullify(var val)
|
||||
{
|
||||
delete val;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue