Skip to content

Commit 6e505ce

Browse files
authored
Merge pull request #234 from Boddlnagg/projectsystem
New project system & Cargo based build system
2 parents 17d0eac + a41e41a commit 6e505ce

File tree

569 files changed

+9795
-57401
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

569 files changed

+9795
-57401
lines changed

.editorconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
; Top-most EditorConfig file
2+
root = true
3+
4+
; 4-column space indentation
5+
[*.cs]
6+
indent_style = space
7+
indent_size = 4

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*.suo
66
*.user
77
*.sln.docstates
8+
.vs
89

910
# Build results
1011

@@ -98,6 +99,9 @@ publish/
9899
# NuGet Packages Directory
99100
packages/
100101

102+
# NuGet lock files
103+
project.lock.json
104+
101105
# Windows Azure Build Output
102106
csx
103107
*.build.csdef
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Reflection;
8+
9+
namespace Microsoft.Common.Core {
10+
public static class DictionaryExtension {
11+
public static IDictionary<string, object> FromAnonymousObject(object data) {
12+
IDictionary<string, object> dict;
13+
if (data != null) {
14+
dict = data as IDictionary<string, object>;
15+
if (dict == null) {
16+
var attr = BindingFlags.Public | BindingFlags.Instance;
17+
dict = new Dictionary<string, object>();
18+
foreach (var property in data.GetType().GetProperties(attr)) {
19+
if (property.CanRead) {
20+
dict.Add(property.Name, property.GetValue(data, null));
21+
}
22+
}
23+
}
24+
}
25+
else {
26+
dict = new Dictionary<string, object>();
27+
}
28+
return dict;
29+
}
30+
31+
public static void RemoveWhere<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, Func<KeyValuePair<TKey, TValue>, bool> predicate) {
32+
var toRemove = dictionary.Where(predicate).ToList();
33+
foreach (var item in toRemove) {
34+
dictionary.Remove(item.Key);
35+
}
36+
}
37+
}
38+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
8+
namespace Microsoft.Common.Core {
9+
public static class EnumerableExtensions {
10+
public static List<T> AsList<T>(this IEnumerable<T> source) {
11+
return source as List<T> ?? source.ToList();
12+
}
13+
14+
public static T[] AsArray<T>(this IEnumerable<T> source) {
15+
return source as T[] ?? source.ToArray();
16+
}
17+
18+
public static IEnumerable<T> Append<T>(this IEnumerable<T> source, T item) {
19+
foreach (T sourceItem in source) {
20+
yield return sourceItem;
21+
}
22+
23+
yield return item;
24+
}
25+
26+
public static void Split<T>(this IEnumerable<T> source, Func<T, bool> predicate, out IList<T> first, out IList<T> second) {
27+
first = new List<T>();
28+
second = new List<T>();
29+
foreach (var item in source) {
30+
if (predicate(item)) {
31+
first.Add(item);
32+
} else {
33+
second.Add(item);
34+
}
35+
}
36+
}
37+
38+
public static void Split<TIn, TOut>(this IEnumerable<TIn> source, Func<TIn, bool> predicate, Func<TIn, TOut> converter, out IList<TOut> first, out IList<TOut> second) {
39+
first = new List<TOut>();
40+
second = new List<TOut>();
41+
foreach (var item in source) {
42+
if (predicate(item)) {
43+
first.Add(converter(item));
44+
} else {
45+
second.Add(converter(item));
46+
}
47+
}
48+
}
49+
50+
public static IEnumerable<IReadOnlyCollection<T>> Split<T>(this IEnumerable<T> source, int chunkSize) {
51+
var index = 0;
52+
var items = new T[chunkSize];
53+
foreach (var item in source) {
54+
items[index] = item;
55+
index++;
56+
57+
if (index == chunkSize) {
58+
index = 0;
59+
yield return items;
60+
items = new T[chunkSize];
61+
}
62+
}
63+
64+
if (index > 0) {
65+
T[] lastItems = new T[index];
66+
Array.Copy(items, 0, lastItems, 0, lastItems.Length);
67+
yield return lastItems;
68+
}
69+
}
70+
71+
public static IEnumerable<int> IndexWhere<T>(this IEnumerable<T> source, Func<T, bool> predicate) {
72+
var i = 0;
73+
foreach (var item in source) {
74+
if (predicate(item)) {
75+
yield return i;
76+
}
77+
78+
i++;
79+
}
80+
}
81+
82+
public static IEnumerable<T> TraverseBreadthFirst<T>(this T root, Func<T, IEnumerable<T>> selectChildren) {
83+
Queue<T> items = new Queue<T>();
84+
items.Enqueue(root);
85+
while (items.Count > 0) {
86+
var item = items.Dequeue();
87+
yield return item;
88+
89+
IEnumerable<T> childen = selectChildren(item);
90+
if (childen == null) {
91+
continue;
92+
}
93+
94+
foreach (var child in childen) {
95+
items.Enqueue(child);
96+
}
97+
}
98+
}
99+
100+
public static IEnumerable<T> TraverseDepthFirst<T>(this T root, Func<T, IEnumerable<T>> selectChildren) {
101+
yield return root;
102+
103+
var children = selectChildren(root);
104+
if (children != null) {
105+
foreach (T child in children) {
106+
foreach (T t in TraverseDepthFirst(child, selectChildren)) {
107+
yield return t;
108+
}
109+
}
110+
}
111+
}
112+
}
113+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
8+
namespace Microsoft.Common.Core.Collections {
9+
public static class ListExtensions {
10+
public static IList<T> AddIf<T>(this IList<T> list, bool condition, T value) {
11+
if (condition) {
12+
list.Add(value);
13+
}
14+
15+
return list;
16+
}
17+
18+
public static void RemoveWhere<T>(this IList<T> list, Func<T, bool> predicate) {
19+
for (var i = list.Count - 1; i >= 0; i--) {
20+
if (predicate(list[i])) {
21+
list.RemoveAt(i);
22+
}
23+
}
24+
}
25+
26+
public static bool AddSorted<T>(this IList<T> list, T value, IComparer<T> comparer = null) {
27+
var index = list.BinarySearch(value, comparer);
28+
if (index >= 0) {
29+
return false;
30+
}
31+
32+
list.Insert(~index, value);
33+
return true;
34+
}
35+
36+
public static bool RemoveSorted<T>(this IList<T> list, T value, IComparer<T> comparer = null) {
37+
var index = list.BinarySearch(value, comparer);
38+
if (index < 0) {
39+
return false;
40+
}
41+
42+
list.RemoveAt(index);
43+
return true;
44+
}
45+
46+
public static int BinarySearch<T>(this IList<T> list, T value, IComparer<T> comparer = null) {
47+
if (list == null) {
48+
throw new ArgumentNullException(nameof(list));
49+
}
50+
51+
comparer = comparer ?? Comparer<T>.Default;
52+
53+
int low = 0;
54+
int high = list.Count - 1;
55+
56+
while (low <= high) {
57+
int mid = low + (high - low) / 2;
58+
int comparisonResult = comparer.Compare(list[mid], value);
59+
60+
if (comparisonResult < 0) {
61+
low = mid + 1;
62+
} else if (comparisonResult > 0) {
63+
high = mid - 1;
64+
} else {
65+
return mid;
66+
}
67+
}
68+
69+
return ~low;
70+
}
71+
72+
public static bool Equals<T, TOther>(this IList<T> source, IList<TOther> other, Func<T, TOther, bool> predicate) {
73+
return source.Count == other.Count && !source.Where((t, i) => !predicate(t, other[i])).Any();
74+
}
75+
}
76+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
namespace Microsoft.Common.Core.Composition {
5+
public interface INamedExport {
6+
string Name { get; }
7+
}
8+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.ComponentModel.Composition;
7+
using System.Linq;
8+
9+
namespace Microsoft.Common.Core.Composition {
10+
public sealed class NamedExportLocator<TExport> {
11+
[ImportMany]
12+
private IEnumerable<Lazy<TExport, INamedExport>> Exports { get; set; }
13+
14+
public NamedExportLocator(ICompositionService cs) {
15+
cs.SatisfyImportsOnce(this);
16+
}
17+
18+
public TExport GetExport(string name) {
19+
return Exports.FirstOrDefault(e => e.Metadata.Name.EqualsOrdinal(name)).Value;
20+
}
21+
}
22+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using System;
5+
6+
namespace Microsoft.Common.Core.Diagnostics {
7+
public static class Check {
8+
public static void ArgumentNull(string argumentName, object argument) {
9+
if (argument == null) {
10+
throw new ArgumentNullException(argumentName);
11+
}
12+
}
13+
14+
public static void ArgumentStringNullOrEmpty(string argumentName, string argument) {
15+
Check.ArgumentNull(argumentName, argument);
16+
17+
if (string.IsNullOrEmpty(argument)) {
18+
throw new ArgumentException(argumentName);
19+
}
20+
}
21+
22+
public static void ArgumentOutOfRange(string argumentName, Func<bool> predicate) {
23+
if (predicate()) {
24+
throw new ArgumentOutOfRangeException(argumentName);
25+
}
26+
}
27+
28+
public static void InvalidOperation(Func<bool> predicate) {
29+
if (predicate()) {
30+
throw new InvalidOperationException();
31+
}
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)