WinJS acquisition of an Enumerable from Collection for use by linq.js

Sep 8, 2012 at 12:55 AM

I have a object that exposes a Claims property which has type ClaimCollection : IList<Claim>, ICollection<Claim>, IEnumerable<Claim>, IEnumerable.

Within my WinJS code I’m trying to carry out linq.js processing against that property but I’m finding its having an issue with the linq.js expression, Enumerable.From(), that extracts the Enumerable from that property as it returns a null. 

Question – any suggestions on a WinJS call I can make to pull the enumerable out of this property so that I can execute linq.js expressions against its contents?

var nameClaim = Enumerable.From( (c) { return c.ClaimType == }).Any() ? Enumerable.From( (c) { return c.ClaimType == }) .Select(function (x) { return x.Value }).First() : "";

Sep 8, 2012 at 2:55 AM

What library is ClaimCollection ?
Microsoft Windows Identity Foundation? 
Can it import to WinJS?

Sorry, please explain it to me more.

And, the code which I can reproduce.

Sep 8, 2012 at 3:58 AM

ClaimCollection is a winrt component library type that implements the interfaces IList<Claim>, ICollection<Claim>, IEnumerable<Claim>, IEnumerable.

The Microsoft windows identity foundation is and SDK that provides federated identity security related services.

The code excerpt above is executing in a modern html/js win8 application environment so yes WinJS types and service are available.

Sep 8, 2012 at 4:22 AM
Edited Sep 8, 2012 at 4:22 AM

i'm testing now but it looks like linq.js using Enumerable.From( is going to work

Sep 8, 2012 at 12:50 PM

System.IdentityModel ?

I can't find api reference page.

Where is library download page?

Sep 8, 2012 at 6:46 PM
Edited Sep 8, 2012 at 6:49 PM

The wif sdk 4.0 is found at and only works in the context of nfx40 projects.

The wif identity and access tool 1.0.1 [ aka wif 4.5 ] is found at and only works in the context of nfx45 projects

So the wif 4.0 Microsoft.IdentityModel.dll and nfx45 System.IdentityModel.dllthose sdk don't have any role in the context of winrt component library and modern winrt project environments.   The winrt component library provided ClaimsCollection in this case was hand crafted using the interface list noted.

Using the winrt component library ClaimsCollection.getView() method I was able to produce linq.js Enumerable.From() result that allowed carrying out WinJS linq expressions as shown in the following working excerpt.

var claimsArray =;
var nameClaim = Enumerable.From(claimsArray).Where(function (c) { return c.claimType == }).Any() ?
   Enumerable.From(claimsArray).Where(function (c) { return c.claimType == })
   .Select(function (c) { return c.value }).First() : "";

var isInMemberRole = Enumerable.From(claimsArray).Where(function (c) { return c.claimType == ClaimTypes.role && c.Value == "My Members Role" }).Any();
var roleClaims = Enumerable.From(claimsArray).Where(function (c) { return c.claimType == ClaimTypes.role }).Select(function (c) { return c.value }).ToArray();
var roleClaimsCount = roleClaims.length;


Sep 10, 2012 at 8:24 AM

Thanks for many information.

But I don't understand how refer Identity Foundation to WinJS project, yet.

By the way, WinMD language projection is convert to
IList<T> -> Array(T)
IEnumerable<T> -> IIterable<T>

and Enumerable.From is detect length property and enumerate.
If the collection is IList<T> then collection has length property.
So, ClaimCollection should just work.
(I don't understand why it doesn't work and what is getView().)

I understand Enumerable.from has to apply for IIterable<T>.
I implement it immediately. (I'm working linq.js ver.3,

Sep 10, 2012 at 7:35 PM
Edited Sep 10, 2012 at 8:00 PM

You can't use windows identity foundation directly in winjs project.   The ClaimsCollection instance is being created using my winrt component library routine that processes a federated identity signin acquired simple web token.

If you are working on linq.js v3 and want to determine why .getView() was necessary for Enumerable.From to work on the instance of ClaimsCollection you can download this example solution and step thru a repro of this issue in the App1 & App2 | js/default.js script processing.   You'll have to remove the .getView() call currently in place to repro the unexpected result I was initially getting.

I guess we should execute a package manager console "Install-Package link.js -Pre" so as to pull in the 3.0.1-beta2 version and see if it is able to execute Enumerable.From(ClaimsCollection) and return the expected result versus having to include .getView() that is necessary with my tests using linq.js version package install.

Sep 11, 2012 at 3:56 AM


I have opened solution but Visual Studio 2012 has been freezed.
So I can't check your project.

But, I imported packages\FedId.WinRT.Project.Scaffolding.\Lib\winrt45 to new projectand checked ClaimCollection using debugger.
ClaimCollection is Array it has length and getView is convert to ReadOnlyCollection.

I wrote simple sample.

var cc = Microsoft.IdentityModel.Claims.ClaimCollection();
cc.append(new Microsoft.IdentityModel.Claims.Claim("a", "v1", "t", "i"));
cc.append(new Microsoft.IdentityModel.Claims.Claim("b", "v2", "t", "i"));
cc.append(new Microsoft.IdentityModel.Claims.Claim("c", "v3", "t", "i"));

// it works, result of console windows is ["a", "b", "c"]
Enumerable.From(cc).ForEach(function (x) { console.log(x.claimType) });
// same
Enumerable.From(cc.getView()).ForEach(function (x) { console.log(x.claimType) });

I want to check you does have length?
ex: console.log(

Is the getView same size?
ex: console.log(

Sep 11, 2012 at 4:04 AM

You need to be running win8 rtm and vs12 rtm for those solution sources to open, compile and run.

The doesn't have a .length but does have a .size

It appears that .getView() is what returns an array.

Sep 11, 2012 at 4:27 AM

Yes, I'm running Windows 8 RTM and Visual Studio 2012 RTM.

see the Visual Studio debugger, ClaimCollection is [Object, Microsoft.IdentityModel.Claims.ClaimCollection]
and expand object, only has size.
but language projection is working, in the watch windows and type ".legnth" maybe it is number(not undefined).

getView returns [Object, Windows.Foundation.Collections.IVector`1<Microsoft.IdentityModel.Claims.Claim>]