DotnetJs
.Net Framework support in javascript
Get DotnetJs
-
Nodejs
firstly, run
npm install dotnetjs --save
If you are using typescript:
;else just like the others:
var DotnetJs = ; -
Browser
run
npm install dotnetjs --save
or download the files in the dist directory.
or run
bower install dotnetjs
<!--if debug--><!--if release-->in your .ts file:
///
Work with DotnetJs
DotnetJs uses similiar interface as it is in .Net Framework.
Linq
If you are about to use complicated Linq Expressions, first make a instance of LinqIntermediate by using LinqStart:
;
the enumerable can be any type that implements IEnumerable, in addition, I implemented it for the Array. Then you can do like the following:
expression.Where....Select....ToArray;
Or use:
DotnetJs.Linq.Whereenumerable, ....Select....ToArray;
remember to use ToArray
or ToList
or ToDictionary
to end the expression(if the result is still IEnumerable). No matter how long your linq is, the time complexity is always O(n).
String Format
The match case: {index[,alignment][:format]}
, with 2 optional parameters (alignment and format).
-
index
Index indicate the index of the object in the following parameter args[].
-
alignment
Alignment will do PadLeft or PadRight with spaces, if it is positive then do PadLeft, else do PadRight.
-
format
With the magic char ':', you can control the format of your toString method. For number, there are specifiers ['D', 'E', 'F', 'G', 'N', 'P', 'X'] implemented, usage portal. Now, let's see the following example:
;;console.writeLine" {0,-22} {1:G}", specifier + ":", number;// output: G: 1.0437e+21;foo.bar = 65521;console.logString.Format'test Foo toString: {0:!}, {0:?}, {0,10}', foo;// output: test Foo toString: !65521, ?65521, 65521
Indexer for the collections
As there isn't have a way to implement indexer in typescript. You have to call the element of List or IDictionay, by using GetValue(index || key)
and SetValue(index || key, value)
, but not collection[index || key]
.
GetHashCode
Both object, string, boolean or number are supported for the GetHashCode Method, actually for the object, it is more likely to be called as a 'unique id'.
To get a new hashcode for an object, call the method with parameter 'ture'. But please becareful, this may due to unexpected errors (e.g.: when you are using Dictionary
).
Equals
If you inherit from typescript abstract class ValueType, remember to override Equals method, else it will compare the result of GetHashCode() to decide whether it equals to the other.
ContainsKey
; console.logobj.ContainsKey'name';// output: true
TODO
More extensions. If you have any idea, please feel free to contact me.
Test
Change directory to tests, then run tsc
to compile the typescript files, then run npm link ../
secondly, to set up the local dependence, finally run node index.js
to start the test.
Contributors
Master76 Author
AsherWang RegExp suport