Error! Why?

General discussions related to using the C# Script Engine in APL+Win.

Moderators: Tech Support, phpbb_admin

Error! Why?

Postby Ajay Askoolum » November 17th, 2013, 3:57 pm

Given

Code: Select all
      ⎕cse 'GetProperties' 'ts'
 Date Day DayOfWeek DayOfYear Hour Kind Millisecond Minute Month
      Now UtcNow Second Ticks TimeOfDay Today Year
      ⎕cse 'GetValue' 'ts.Now'
CSE ERROR: (1,1): error CS0176: Member 'System.DateTime.Now' cannot be accessed with an instance reference; qualify it with a type name instead
      ⎕cse 'GetValue' 'ts.Now'
      ^
      ⎕cse 'GetLastError'
(1,1): error CS0176: Member 'System.DateTime.Now' cannot be acces
      sed with an instance reference; qualify it with a type name
       instead

Why can't I get the Now property?
What does the error report mean, exactly?
Ajay Askoolum
 
Posts: 884
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom

Re: Error! Why?

Postby joe_blaze » November 18th, 2013, 6:09 am

Hi Ajay,

Thanks for submitting this example. The CSE is correctly displaying the appropriate C# debugger/compiler error message. What the example attempts to do is not permitted in C#.

In this example an instance of the .Net DateTime class, called 'ts', has been created. The error returned by the CSE when attempting to obtain the value of 'ts.Now' comes directly from the C# debugger/compiler. The .Now property of the DateTime class cannot be obtained from an instance of the DateTime class, e.g. 'ts.Now' is not supported by C#. The .Now property can only be obtained from syntax: 'DateTime.Now'.

Attached is a pdf-format document which illustrates this example using APL+Win/[]CSE and Visual Studio 2012.
Because the CSE provides the C# error#, it is possible to find more information about this error condition: http://msdn.microsoft.com/en-us/library ... bd(v=vs.90).aspx

Although this is a syntactical error in the source code for this example, it is interesting to note that in Visual Studio 2012, the Intellisense for the properties of an instance of the DateTime class does not show the 'Now' property. We will attempt to identify how Visual Studio determines that the 'Now' property of the DateTime class does not apply to an instance of the DateTime class. As this example points out, the CSE shows 'Now' as a property of an instance of the DateTime class and it should not show that property in this case.

Joe
Attachments
Cannot access the Now property of the DateTime class from an instance of the DateTime class.pdf
APL+Win & []CSE give the same error as Visual Studio & C#
(371.46 KiB) Downloaded 526 times
joe_blaze
 
Posts: 384
Joined: February 11th, 2007, 3:09 am
Location: Box 361 Brielle, NJ 08730-0361

Re: Error! Why?

Postby Ajay Askoolum » November 20th, 2013, 2:22 am

Attached picture shows the properties that C# exposes. []cse needs to exclude Now, UtcNow, & Today from the list of properties. It is reassuring that []cse raises the same error when querying the Now property (as to be expected).

There are static properties - unavailable on instances of static classes but available on the classes, like Now, UtcNow & Today - and non static properties which are available on everything.
Attachments
apl.png
apl.png (52.68 KiB) Viewed 11038 times
Ajay Askoolum
 
Posts: 884
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom

Re: Error! Why?

Postby joe_blaze » November 20th, 2013, 3:32 pm

Hi Ajay,

Thanks for the additional follow-up. We are examining exactly how to exclude the method, properties and events which reflection finds, but should not be listed.

Joe
joe_blaze
 
Posts: 384
Joined: February 11th, 2007, 3:09 am
Location: Box 361 Brielle, NJ 08730-0361

Re: Error! Why?

Postby joe_blaze » May 22nd, 2014, 11:25 am

The CSE now excludes the names of non-applicable methods, properties and events of objects when the GetMethods, GetProperties and GetMethods CSE methods are used.
joe_blaze
 
Posts: 384
Joined: February 11th, 2007, 3:09 am
Location: Box 361 Brielle, NJ 08730-0361


Return to APL+Win & The C# Script Engine

Who is online

Users browsing this forum: No registered users and 13 guests

cron