Welcome to the XSharp News Server and Forum

You are welcome to participate in the XSharp newsgroups and forum.

The XSharp News Server can be found at news.xsharp.info, port 119 (nntp). You can login with the user name XSharpUser and password X#Rulez!.
You can also post through the web interface. In that case you need to create a user account first.
The newsgroups and web interface are not synchronized yet. We are working on that.

When posting to the newsgroups and forums we ask you kindly to follow the rules that you can find here: https://www.xsharp.info/faq/39-xsharp-news-server-rules

HELP ! - with syntax and lines etc.

More
5 days 14 hours ago #1 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

Please Log in to join the conversation.

More
5 days 15 hours ago #2 by Wolfgang Riedmann
Hi all,

only to confirm: you can write full MVVM properties as one-liner:
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.
property datafile as string
  get
    return _datafile
  end get
  set 
    _datafile := value
    self:OnPropertyChanged( "datafile" )
  end set
end property

Wolfgang

Please Log in to join the conversation.

More
1 week 8 hours ago #3 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.

Please Log in to join the conversation.

More
1 week 11 hours ago #4 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

Please Log in to join the conversation.

More
1 week 1 day ago #5 by Wolfgang Riedmann
Hi Robert,

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

Wolfgang

Please Log in to join the conversation.

More
1 week 1 day ago #6 by Robert van der Hulst
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:
#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)
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:
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("\r\n{0} {1}", cProp, "has changed");
	}
}

Robert

Please Log in to join the conversation.

Time to create page: 0.419 seconds