-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.html
133 lines (112 loc) · 5.8 KB
/
README.html
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<h1>dotNeTS</h1>
<p>.NET library-syntax for typescript/javascript</p>
<p>This library aims to implement the good parts of .Net-syntax in typescript/javascript.<br />
If you're new to javascript you'll have a hard time dealing with the functional style<br />
of programming often implemented in ex. lodash for dealing with data-operations.<br />
dotNeTS gives you lambda expressions and full implementation (soon) of System.Collection.Generics.</p>
<p>dotNeTS also aims to NOT reinvent the wheel and uses javascript 'best-choices' for data-mainpulation<br />
and functionality. e.g the List-implementation relies on lodash.</p>
<p>And <strong>YES</strong> right now, this library uses uppercase for methods, something that is frowned upon in javascript-world.<br />
I know about the dangers with the new-operator and binding this to global-object. But my defence is that dotNeTS soon<br />
will compile to two seperate libraries one with uppercase(.NET-ish) and one that passes jslint. And also,<br />
if you use typescript, it helps you avoid the new and this-pitfalls (some atleast). At the end of the day, you still need<br />
to know what you�re doing.</p>
<p>And <strong>YES</strong> I know all about <a href="http://linqjs.codeplex.com/">Linq.js</a>, but this library is much, much smaller<br />
and sits ontop of lodash. I built it to avoid having to pull in lodash and Linq.js in one of my latest projects.</p>
<p>dependencies:<br />
* lodash</p>
<p>Install:</p>
<pre><code>bower install dotNeTS
</code></pre>
<p>IMPORTANT NOTE FOR Visual Studio! This library includes typescript definition AND source.<br />
You have to exclude one of them in VS to avoid duplicate definitions.</p>
<p>Example 1:</p>
<pre><code> module app {
interface User {
id: number
username: string;
}
export class UserManager {
constructor() {
//Import namespace
var List = dotNeTS.List;
//Random Data
var user1: User = {
id: 1,
username: "olofd",
};
var user2: User = {
id: 2,
username: "ludde",
};
//Regular javascript array;
var arrayOfUsers = [user1, user2];
//Create List<User>
var myList = new List<User>(arrayOfUsers);
var userNameArray = myList.Where(b=> b.id === 1).Select(b=> b.username).ToArray();
console.log(userNameArray);
//=> ['olofd']
}
}
}
var userMgr = new app.UserManager();
</code></pre>
<p>Example 2 (Actual code from project) </p>
<pre><code>var languagesAvailable = allLanguages.Where(s => !languagesAlreadyAdded.Where(es => es.LangCode === s.value).Any())
.Where(b => b.language && b.language !== "")
.OrderBy(b => b.language)
.ThenBy(b => b.country);
return languagesAvailable.ToArray();
</code></pre>
<p>Example 3 (Actual code from project) </p>
<pre><code>var languagesAvailable = allLanguages.Where(s => !languagesAlreadyAdded.Where(es => es.LangCode === s.value).Any())
.GroupBy(b => b.country)
return languagesAvailable.Where(b => b.Key === 'Sweden').ToList();
</code></pre>
<p>Interfaces with underlying implementations:<br />
(* all implementations have tests.)</p>
<pre><code>module dotNeTS {
export interface IEnumerable<TSource> extends IDisposable {
ForEach(callback: dotNeTS.IFunc<TSource, void>): void
Contains(item: TSource): boolean;
GroupBy<TResult>(callback: IFunc<TSource, TResult>): IEnumerable<IGrouping<TResult, TSource>>;
OrderBy<TKey>(keySelector: dotNeTS.IFunc<TSource, TKey>): IOrderedEnumerable<TSource>;
OrderByDecending<TKey>(callback: IFunc<TSource, TKey>): IOrderedEnumerable<TSource>;
First(predicate?: IFunc<TSource, boolean>): TSource;
FirstOrDefault(predicate?: IFunc<TSource, boolean>): TSource;
Single(predicate?: IFunc<TSource, boolean>): TSource;
SingleOrDefault(predicate?: IFunc<TSource, boolean>): TSource;
Any(predicate?: IFunc<TSource, boolean>): boolean;
Count(predicate?: IFunc<TSource, boolean>): number;
Select<TResult>(callback: IFunc<TSource, TResult>): IEnumerable<TResult>;
Where(predicate?: IFunc<TSource, boolean>): IEnumerable<TSource>;
ToArray(): TSource[];
ToList(): IList<TSource>;
}
}
module dotNeTS {
export interface IOrderedEnumerable<TSource> extends IEnumerable<TSource> {
OrderBy<TKey>(keySelector: IFunc<TSource, TKey>): IOrderedEnumerable<TSource>;
OrderByDecending<TSort>(callback: IFunc<TSource, TSort>): IOrderedEnumerable<TSource>;
ThenBy<TSort>(callback: IFunc<TSource, TSort>): IOrderedEnumerable<TSource>;
ThenByDecending<TSort>(callback: IFunc<TSource, TSort>): IOrderedEnumerable<TSource>;
}
}
module dotNeTS {
export interface IList<TSource> extends IEnumerable<TSource>{
Add(item: TSource): void;
AddRange(collection: IEnumerable<TSource>): void;
Remove(item: TSource): void;
RemoveAt(index: number);
Clear():void;
Contains(item : TSource) : boolean;
IndexOf(item: TSource) : number;
Insert(index: number, item: TSource) : void;
}
}
module dotNeTS {
export interface IGrouping<TKey, TElement> extends IEnumerable<TElement>{
Key: TKey;
}
}
</code></pre>