DYNAMIC in XIDE

This forum is meant for questions and discussions about the X# language and tools
User avatar
Otto
Posts: 174
Joined: Wed Sep 30, 2015 6:22 pm

DYNAMIC in XIDE

Post by Otto »

I tried in XIDE to use Dynamic, but couldn't get it going.

The error I get is:
error XS1980: Cannot define a class or member that utilizes 'dynamic' because the compiler required type 'System.Runtime.CompilerServices.DynamicAttribute' cannot be found. Are you missing a reference?

This might be due to the bug Microsoft introduced that the target must be set to 4.5.1 at first, after which you can switch back to e.g. 4.6.2. In VS2015 this did the trick.

Note: after this, a reference to Microsoft.CSharp.dll is needed, to fix the compiler error Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'.

However, in Xide I can't find where I can set the target location, other to v2.0 and v4.0

Am I looking in the wrong places?

Regards,
Otto
User avatar
Chris
Posts: 4986
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

DYNAMIC in XIDE

Post by Chris »

Hi Otto!

I tried this also in c# and I got the same error! By trial and error, realized that you need to also add a reference to System.Core (in addition to Microsoft.CSharp). After doing that, it should work ok also in x#. Guess we should trap this situation and make the compiler report a better error message.

In XIDE, you don't need to set target .Net framework etc. Only time you might need to worry about this is if you must compile against .Net 2.0 only, but I think probably nobody needs to do this anymore..

Chris
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
FFF
Posts: 1593
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

DYNAMIC in XIDE

Post by FFF »

Chris wrote:you need to also add a reference to System.Core (in addition to Microsoft.CSharp). After doing that, it should work ok also in x#.Chris
pmfji, just had a look with a "Basic x# app" and i get "Core does not exist in Namespace System" - after realizing for the x-th time, that reference is not using <g>, peeked into references, added reference to System.Core and Microsoft.CSharp. Trying to run MS sample:
static void Main(string[] args)
{
dynamic dyn = 1;
object obj = 1;

// Rest the mouse pointer over dyn and obj to see their
// types at compile time.
System.Console.WriteLine(dyn.GetType());
System.Console.WriteLine(obj.GetType());
}

i fail at the first line, how to define the "dyn" var. Unfortunately the "Dynamic" page of the help still has a "enter topic text", so i'm a bit at a loss..

BTW, "Dynamic" - and that after so many years of "you are dead meat, man, not using strong typed bla bla...." ;-)
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
Chris
Posts: 4986
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

DYNAMIC in XIDE

Post by Chris »

Hi Karl,

Probably you are (accidentally) using an older version of the c# compiler. Please go to Preferences/Compiler and set the c# option to the latest c# compiler executable. I think it should be

C:WindowsMicrosoft.NETFrameworkv4.0.30319csc.exe

But why testing this with c#, instead of x#?

Chris
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
FFF
Posts: 1593
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

DYNAMIC in XIDE

Post by FFF »

Chris,
indeed, pointed to net2.0 version, changed that.
But didn't want to test with c#, took only the sample from MS site, translated to:
USING Microsoft.CSharp
USING System.Dynamic
FUNCTION Start( ) AS VOID
System.Console.WriteLine("Hello x#!")

// dyn := 1 AS DynamicObject ??? How to "declare" the var?
// should i "var dyn := 1"
LOCAL obj :=1 AS OBJECT

// Rest the mouse pointer over dyn and obj to see their
// types at compile time.
System.Console.WriteLine(dyn.GetType())
System.Console.WriteLine(obj.GetType())

dyn := dyn + 3
obj := obj + 3
RETURN

Sorry for confusion ;)
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
Chris
Posts: 4986
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

DYNAMIC in XIDE

Post by Chris »

Hi Karl,

That should be just

LOCAL dyn AS Dynamic // or System.Dynamic

It's very similar to having

LOCAL dyn AS USUAL

and you use it more or less the same way as you would with a USUAL.

And yes of course I hear your comment about strong typing and I mostly agree, although there are cases where the dynamic type can be very handy, same as USUAL can be handy in some cases in VO.

Chris
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 3784
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

DYNAMIC in XIDE

Post by wriedmann »

Hi Karl, hi Chris,

I have a base class for MVVM like this

public abstract class ExpandoBase inherit DynamicObject implements INotifyPropertyChanged

and that works very well.

I can publish this class in the Pearls group.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1593
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

DYNAMIC in XIDE

Post by FFF »

Chris wrote:Hi Karl,

That should be just

LOCAL dyn AS Dynamic // or System.Dynamic
It's very similar to having
LOCAL dyn AS USUAL

and you use it more or less the same way as you would with a USUAL.

And yes of course I hear your comment about strong typing and I mostly agree, although there are cases where the dynamic type can be very handy, same as USUAL can be handy in some cases in VO.

Chris
Dynamic works, System.Dynamic does NOT - "error XS0118: 'System . Dynamic' is a namespace but is used like a type".
My Dyn (or usual) remark was more aimed at the evangelists of progress ;-)
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
Chris
Posts: 4986
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

DYNAMIC in XIDE

Post by Chris »

Hi Karl,

Oops, sorry!! Yes, there's no "Dynamic" type really, under the hood it's actually declared as System.Object and the rest is done by compiler trickery. I think I should make xide treat "dynamic" as a keyword, will do that for the next ver.

Chris
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Chris
Posts: 4986
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

DYNAMIC in XIDE

Post by Chris »

Hi Wolfgang,

Yes of course!! It's exactly for stuff like that that the pearls section was introduced.

Chris
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply