xsharp.eu • HELP ! - with syntax and lines etc. - Page 3
Page 3 of 3

HELP ! - with syntax and lines etc.

Posted: Tue Feb 14, 2017 3:31 pm
by robert
Jack,
Jack wrote: Not sure it is possible in X# yet, but Robert said he is working on the pre-processor.
If the #command was supported, you can use something that Johan posted a while ago, e.g.:

PROPERTY Abc AS STRING GETSET _abc

Which would correctly translate with the following #command as he shared:
Although the preprocessor is not finished (and not included in the current build) I am pleased to say that with my current development build this is already working.
I added Johans code to my test program and this:

Code: Select all

#command PROPERTY <n> AS <t> GETSET <v> =>;
PROPERTY <n> AS <t>;;
	GET;;
		RETURN SELF:<v>;;
	END GET;;
	SET;;
		SELF:<v> := VALUE;;
		SELF:NotifyPropertyChanged(<"n">);;
	END SET;;
END PROPERTY

CLASS Foo
protected _abc as STRING
PROPERTY Abc AS STRING GETSET _abc
METHOD NotifyPropertyChanged(cProp as STRING) AS VOID
? cProp, "has changed"
RETURN
END CLASS
is translated to (I am showing the PPO output)

Code: Select all

CLASS Foo 
protected   _abc   as   STRING 
PROPERTY Abc AS STRING ; GET ; RETURN SELF : _abc ; END GET ; SET ; SELF : _abc := VALUE ; SELF : NotifyPropertyChanged ( "Abc" ) ; END SET ; END PROPERTY 
METHOD   NotifyPropertyChanged ( cProp   as   STRING )   AS   VOID 
?   cProp ,   "has changed" 
RETURN 
END CLASS 
The PPO output still needs some cleaning (some unnecessary spaces are in there) but you can see that it works.
And of course the code generation works as well. This is the (C#) output from IL Spy:

Code: Select all

public class Foo
{
	protected string _abc;
	public string Abc
	{
		get
		{
			return this._abc;
		}
		set
		{
			this._abc = value;
			this.NotifyPropertyChanged("Abc");
		}
	}
	public void NotifyPropertyChanged(string cProp)
	{
		Console.Write("rn{0} {1}", cProp, "has changed");
	}
}
Robert

HELP ! - with syntax and lines etc.

Posted: Wed Feb 15, 2017 4:56 am
by wriedmann
Hi Robert,

this is great - many thanks! It will save us a LOT of code writing and make code easier to maintain.

Wolfgang

HELP ! - with syntax and lines etc.

Posted: Wed Feb 15, 2017 7:30 pm
by Frank Maraite
Hi Phil,

try XIDE for this example. Copy the following into the header.cfg.

[Bindable-Property General]
/// <summary>
/// Gets or sets $TEMPLATEOPTION:Property Name$ .</summary>
/// <value>$TEMPLATEOPTION:Property Name$ is ...</value>
// Created by %user% : %DATE% %TIME%
PROPERTY $TEMPLATEOPTION:Property Name$ AS $TEMPLATEOPTION:Property Type$
GET ; RETURN _$TEMPLATEOPTION:Property Name$ ; END GET
SET ; IF SELF:@@Set<$TEMPLATEOPTION:Property Type$>( REF _$TEMPLATEOPTION:Property Name$, VALUE ) ; NOP ; ENDIF ; END SET
END PROPERTY
PRIVATE _$TEMPLATEOPTION:Property Name$ AS $TEMPLATEOPTION:Property Type$


Then do ctrl-h. A dialog opens. Enter Hello <tab> and Phil. The result is:

/// <summary>
/// Gets or sets Hello .</summary>
/// <value>Hello is ...</value>
// Created by Frank Maraite : 15.02.2017 20:12
PROPERTY Hello AS Phil
GET ; RETURN _Hello ; END GET
SET ; IF SELF:@@Set<Phil>( REF _Hello, VALUE ) ; NOP ; ENDIF ; END SET
END PROPERTY
PRIVATE _Hello AS Phil

This is how it should be: It checks for real value change, and it reminds you to do the code documenting comments. Of course it will fill your name on your machine as the author.

You cannot do this with #command, and #command is not there to do something like this.
I do not know how to do in VS. I'm pretty sure you will find out and tell us how.

On existing properties I have some standard snippets. For example

[Bindable-Property String]
/// <summary>
/// Gets or sets %entity% .</summary>
/// <value>%entity% is ...</value>
// Created by %user% : %DATE% %TIME%
PROPERTY %entity% AS STRING
GET ; RETURN _%entity% ; END GET
SET ; IF SELF:@@Set<DATE>( REF _%entity%, VALUE ) ; NOP ; ENDIF ; END SET
END PROPERTY
PRIVATE _%entity% AS STRING

I have this for the standard data types like INT, REAL8, LOGIC.

If you have code like

PROPERTY Wolfgang AS STRING AUTO

put the mouse over this line ctrl-<h> and select 'Bindable-Property String'. The result will be

/// <summary>
/// Gets or sets Wolfgang .</summary>
/// <value>Wolfgang is ...</value>
// Created by Frank Maraite : 15.02.2017 20:20
PROPERTY Wolfgang AS STRING
GET ; RETURN _Wolfgang ; END GET
SET ; IF SELF:@@Set<DATE>( REF _Wolfgang, VALUE ) ; NOP ; ENDIF ; END SET
END PROPERTY
PRIVATE _Wolfgang AS STRING

I have many of this kind to recode something.

It's only a few clicks and key strokes but it makes it right and extendable. In my opinion all other solutions require many more typing and are less flexible and make more work to extend.

Once it is coded you can forget the code. Collapse it, do it in a partial file of it's own or whatever. It does'nt care is it readable or not. But it is complete.

Frank

HELP ! - with syntax and lines etc.

Posted: Wed Feb 15, 2017 10:30 pm
by Phil Hepburn
Hi Frank,

Thanks a bunch for all these ideas, I will have a go in the morning with VS.

Oh! - for any guys interested there is a new RC version (4) out for VS 2017 - it will last about 3 weeks till the public release. Just installed my copy.

I may have to wait until the next version of the compiler as the X# integration into VS 2017 RC is far from complete. Still, we will get there between us I feel - one and all ;-0)

Cheers,
Phil.

HELP ! - with syntax and lines etc.

Posted: Fri Feb 17, 2017 3:59 pm
by wriedmann
Hi all,

only to confirm: you can write full MVVM properties as one-liner:

Code: Select all

property datafile as string get _datafile set _datafile := value, self:OnPropertyChanged( "datafile" )
and works as expected.

I have to adjust my samples, and I like this (short) syntax much more than the extended version.

Code: Select all

property datafile as string
  get
    return _datafile
  end get
  set 
    _datafile := value
    self:OnPropertyChanged( "datafile" )
  end set
end property
Wolfgang

HELP ! - with syntax and lines etc.

Posted: Fri Feb 17, 2017 4:26 pm
by Frank Maraite
Wolfgang,

- your solution is wrong, because it sends out a PropertChanged message/event even if the property was'nt changed. Software should not tell lies.
- your solution is error prone, because you have to have the property name and the string var in sync. That's why the CallerMemberName attribute is there.
- the cost of change is relative high.

Frank