| 357 | } |
| 358 | |
| 359 | public static string[] ToKeyValueCollection(string collectionName, Type keyType, Type valueType) |
| 360 | { |
| 361 | string keyRtType = TX.ToWinRT(keyType); |
| 362 | string[] keyTypeToJs = ToJS(keyType, TX.MainModel.Types.ContainsKey(keyType)); |
| 363 | string keyCheckType = TypeCheck(keyType, TX.MainModel.Types.ContainsKey(keyType)); |
| 364 | string[] jsToKeyElementType = ToWinRT(keyType, TX.MainModel.Types.ContainsKey(keyType)); |
| 365 | |
| 366 | string valueRtType = TX.ToWinRT(valueType); |
| 367 | string[] valueTypeToJs = ToJS(valueType, TX.MainModel.Types.ContainsKey(valueType)); |
| 368 | string valueCheckType = TypeCheck(valueType, TX.MainModel.Types.ContainsKey(valueType)); |
| 369 | string[] jsToValueElementType = ToWinRT(valueType, TX.MainModel.Types.ContainsKey(valueType)); |
| 370 | |
| 371 | // note that double curl braces here are used because String.Format will |
| 372 | string creatorFunction = "NodeRT::Collections::" + collectionName + "Wrapper<" + keyRtType + "," + valueRtType + ">::Create" + collectionName + "Wrapper({0}, \r\n" + |
| 373 | " [](" + keyRtType + " val) -> Local<Value> {{\r\n" + |
| 374 | " return " + ReplaceBracketsWithDoubleBrackets(String.Format(keyTypeToJs[1], "val")) + ";\r\n" + |
| 375 | " }},\r\n" + |
| 376 | " [](Local<Value> value) -> bool {{\r\n" + |
| 377 | " return " + ReplaceBracketsWithDoubleBrackets(String.Format(keyCheckType, "value")) + ";\r\n" + |
| 378 | " }},\r\n" + |
| 379 | " [](Local<Value> value) -> " + keyRtType + " {{\r\n" + |
| 380 | " return " + ReplaceBracketsWithDoubleBrackets(String.Format(jsToKeyElementType[1], "value")) + ";\r\n" + |
| 381 | " }},\r\n" + |
| 382 | " [](" + valueRtType + " val) -> Local<Value> {{\r\n" + |
| 383 | " return " + ReplaceBracketsWithDoubleBrackets(String.Format(valueTypeToJs[1], "val")) + ";\r\n" + |
| 384 | " }},\r\n" + |
| 385 | " [](Local<Value> value) -> bool {{\r\n" + |
| 386 | " return " + ReplaceBracketsWithDoubleBrackets(String.Format(valueCheckType, "value")) + ";\r\n" + |
| 387 | " }},\r\n" + |
| 388 | " [](Local<Value> value) -> " + valueRtType + " {{\r\n" + |
| 389 | " return " + ReplaceBracketsWithDoubleBrackets(String.Format(jsToValueElementType[1], "value")) + ";\r\n" + |
| 390 | " }}\r\n" + |
| 391 | " )"; |
| 392 | |
| 393 | return new[] { "NodeRT::Collections::Create" + collectionName + "<" + keyRtType + "," + valueRtType + ">", creatorFunction }; |
| 394 | } |
| 395 | |
| 396 | |
| 397 | private static string GetTypeCheckerAndConverterLambdas(Type type) |