Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2006

Tip: Looking for answers? Try searching our database.

How to access C# indexer in Jscript?????

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sunilce10@gmail.com - 25 Aug 2006 08:29 GMT
Hi,

I have one Pages collection class, in which i have defined inexer.
My collection class is COM enabled, and i am using its object in my
scripting engine.

Now, when i using Jscript in my scripting engine, i think the C#
objects indexer is not supported in JScript.

I can't make access as follows in JScript:

Pages[0].PageID = 100;

Any help will be appreciated....

Thanx in advance.

Regards,
SUNIL RUPAVATIYA
Oleg Sych - 01 Sep 2006 21:54 GMT
JScript supports indexers with () instead of []. You should be able to access
your collection using the following syntax:

Pages(0).PageID = 100;

There is one pitfall though. This syntax will only work if Pages is a
variable and not a property of another object. So this code works:

var pages = new ActiveXControl("MyNamespace.MyDotNetCollection");
pages.Add(newPage);
pages(0).PageID = 100;

but this code, where collection is returned by a property of another .NET
object,  will report a "Wrong number of arguments or invalid property
assignment" error:

var myObject = new ActiveXControl("MyNamespace.MyDotNetObject");
myObject.Pages(0).PageID = 100;

You would have to use the following syntax as a workaround:

myObject.Pages.Item(0).PageID = 100;
// or
var pages = myObject.Pages;
pages(0).PageID = 100;

Does anyone know why object.Collection(x) syntax doesn't work in JScript and
VBScript with .NET collections? Having to resort to object.Collection.Item(x)
syntax is a significant usability problem for an object hierarchy with
multiple levels of objects nested in collections. Compare

company.Customers("Smith, John").Orders("555").Items(0)
// and
company.Customers.Item("Smith, John").Orders.Item("555").Items.Item(0)

I tried to use both AutoDispatch, explicit IList and explicit custom class
interfaces with my collections. I can only get indexers to work using
collectionVariable(index) syntax but not with
object.CollectionProperty(index). There are differences in the IDL generated
for my .NET collections and classic collections, such as
IHTMLElementCollection in mshtml.tlb, where I know the right syntax works.
There must be something in the .NET/COM interop that makes them different and
prevents .NET collections from working correctly.

Any help would be very appreciated.

Thanks,

Oleg

> Hi,
>
[quoted text clipped - 15 lines]
> Regards,
> SUNIL RUPAVATIYA

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.