-
Notifications
You must be signed in to change notification settings - Fork 5
/
Extensions.cs
67 lines (59 loc) · 1.44 KB
/
Extensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using BrightIdeasSoftware;
namespace AIEdit
{
public static class Extensions
{
public static string GetOrDefault(this IOrderedDictionary dict, string key, string def)
{
return dict.Contains(key) ? (dict[key] as string) : def;
}
public static string GetString(this IOrderedDictionary dict, string key)
{
return dict[key] as string;
}
public static int GetInt(this IOrderedDictionary dict, string key)
{
return int.Parse(dict[key] as string);
}
public static uint GetUint(this IOrderedDictionary dict, string key)
{
try
{
return uint.Parse(dict[key] as string);
}
catch(OverflowException)
{
return 0;
}
}
public static bool GetBool(this IOrderedDictionary dict, string key)
{
return GetString(dict, key).CompareTo("yes") == 0;
}
public static AITypeListEntry GetAITypeListEntryByIndex(this IList list, int index)
{
foreach(AITypeListEntry entry in list)
{
if (entry.Index == index) return entry;
}
return null;
}
public static uint SwapEndianness(this uint x)
{
return ((x & 0x000000ff) << 24) |
((x & 0x0000ff00) << 8) |
((x & 0x00ff0000) >> 8) |
((x & 0xff000000) >> 24);
}
public static void EnsureVisible(this ObjectListView olv)
{
olv.EnsureVisible(olv.SelectedIndex);
}
}
}