Page 1 of 1

Error! Why?

PostPosted: November 17th, 2013, 3:57 pm
by Ajay Askoolum
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?

Re: Error! Why?

PostPosted: November 18th, 2013, 6:09 am
by joe_blaze
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

Re: Error! Why?

PostPosted: November 20th, 2013, 2:22 am
by Ajay Askoolum
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.

Re: Error! Why?

PostPosted: November 20th, 2013, 3:32 pm
by joe_blaze
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

Re: Error! Why?

PostPosted: May 22nd, 2014, 11:25 am
by joe_blaze
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.