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 / Languages / JScript / September 2003

Tip: Looking for answers? Try searching our database.

Naming properties the same as objects in ASP

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Agendum - 23 Sep 2003 06:19 GMT
Take the following example:

public class Test1 { }
public class Test2
{
   public function get Test1() : Test1
   {
       return null;
   }
}

This will result in the compiler error:
JS1110: Expression must be a compile time constant

When looking at the compiled source, I can see the full context of the Test1
object and indicate it explicitly:

public class Test1 { }
public class Test2
{
   public function get Test1() : ASP.default_aspx.Test1
   {
       return null;
   }
}

This works fine.  However, is there a supported way to accomplish this with
future compatibility?

Thanks
MSFT - 24 Sep 2003 04:01 GMT
Hi Agendum,

It seems that the compiler didn't recognize Test1() : Test1 correctly. You
may change it to:

public class Test1 { }

public class Test2
{
   public function get MyTest1() : Test1
   {
       return null;
   }
}

After rename the function to "MyTest1", the compiler can work with it.

Luke
Microsoft Online Partner Support

Signature

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Peter Torr \(MS\) - 24 Sep 2003 17:23 GMT
> Take the following example:
>
[quoted text clipped - 9 lines]
> This will result in the compiler error:
> JS1110: Expression must be a compile time constant

Hi,

A limitation of the compiler means that you can't have members with the same
name as types. This is a side-effect of the other question you posted (which
I just replied to) about how to get the type of a type in JScript -- you
don't need to do anything, because a typename by itself in code represents
that type object:

   class foo {}
   print(foo)

this will print "foo" because foo is a Type and so JScript calls ToString on
the type, which of course prints its name.

This if you have:

   class Test {}

   class foo {}
   {
       function get Test() : Test {}
   }

The compiler gets confused when compiling the Test property because you are
trying to make "Test" both a property and a type. You must fully-qualify all
references to the Test type in order to make it work

> public class Test1 { }
> public class Test2
[quoted text clipped - 7 lines]
> This works fine.  However, is there a supported way to accomplish this with
> future compatibility?

You can put Test1 in its own namespace (by creating a DLL with a 'package')
and then use the fully-qualified name of Test1.

Peter

Signature

Please post questions to the newsgroup - everyone benefits.
This post is provided "AS IS" with no warranties, and confers no rights
Sample code subject to http://www.microsoft.com/info/cpyright.htm
Bore yourself to tears -- http://blogs.gotdotnet.com/ptorr


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.