HELP ! - with syntax and lines etc.

This forum is meant for anything you would like to share with other visitors
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

HELP ! - with syntax and lines etc.

Post by wriedmann »

Hi Frank, hi Phil,

really my ViewModel properties look different:

Code: Select all

property Value1 as string
  get
    return super:_Get<string>()
  end get
  set
    super:_Set<string>( value )
  end set
end property


because I have a base class with the following code from which all ViewModel classes inherit:

Code: Select all

public abstract class BindableBase implements INotifyPropertyChanged              
  protect _properties := Dictionary<string, object>{} as Dictionary<string, object> 
  public event PropertyChanged as PropertyChangedEventHandler

protected method _Get<T>( [CallerMemberName] name := null as string ) as T
  local value := null as object

  if _properties.TryGetValue( name, out value )
    if value == null
      return Default(T)
    else
      return (T) value
    endif
  endif

  return Default(T)

protected method _Set<T>( value as T, [CallerMemberName] name := null as string ) as void

  if ( Equals( value, _Get<T>(name) ) )
    return    
  endif
  _properties[name] := value
  OnPropertyChanged( name )
        
return

protected virtual method OnPropertyChanged([CallerMemberName] propertyName := null as string ) as void
  local handler as PropertyChangedEventHandler
    	
  handler := self:PropertyChanged
  if handler != null
    handler( self, PropertyChangedEventArgs{ propertyName } )
  endif
        
  return
            
end class
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

HELP ! - with syntax and lines etc.

Post by Phil Hepburn »

Hi Frank, and all,

Does the changed code in the attached small image meet with your full approval ?
LinesSave_11.jpg
LinesSave_11.jpg (38.24 KiB) Viewed 509 times
Before the pre-processor we can probably do a lot with this !?

Any comments or further ideas ?

Regards,
Phil.
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

HELP ! - with syntax and lines etc.

Post by Phil Hepburn »

Jack,

Can you explain in a little more detail please?

Because I have always been creating new and .NET apps / code, I have done little to nothing with the compiler and its switches ;-0((

TIA,
Phil.
Frank Maraite
Posts: 178
Joined: Sat Dec 05, 2015 10:44 am
Location: Germany

HELP ! - with syntax and lines etc.

Post by Frank Maraite »

Hi Phil,

I would omit the Self in front of _firstname. Too much to read. I think with the underscore you show us: this is a private var.

Later this day I may publish my XIDE snippet for that.
See my following reply to Jack.

Frank
Frank Maraite
Posts: 178
Joined: Sat Dec 05, 2015 10:44 am
Location: Germany

HELP ! - with syntax and lines etc.

Post by Frank Maraite »

Jack,

I know the power of #command and I like you showed this.
I commented in the context of Phil's question where.

I still don't like a #command solution or an auto solution. Whenever we code something we should answer the question: what is the cost of change. When doing like me or Phil now, we only add some lines of code if we want.

In case of a command: What if we need special behavior that cannot be resolved in a general manner. The same with the auto. I think it is too much work later. A snippet would do it at first place with a few key strokes. And then it's right.
Frank Maraite
Posts: 178
Joined: Sat Dec 05, 2015 10:44 am
Location: Germany

HELP ! - with syntax and lines etc.

Post by Frank Maraite »

Wolfgang,

this code is what is - not exactly - in MVVMlight. And it's ok to avoid being undepended from this library. But I stongly recommend to return a logic instead of a void showing changed or not. In you calling code you can ignore it if you like.

Frank
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

HELP ! - with syntax and lines etc.

Post by Phil Hepburn »

Okay Frank,

I like your suggestion AND I have tried to show the new format without the 'self:' before the 'NotifyPropertyChanged'.
LinesSave_21.jpg
LinesSave_21.jpg (29.17 KiB) Viewed 509 times
I like what I now have in my code, and think that a snippet solution to my problem is probably best, and what I want.

Now then, how do I make / write / enter, and then use such a snippet in Visual Studio ?

Any ideas anyone ?
Here we go a Googling .....
Cheers,
Phil.
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

HELP ! - with syntax and lines etc. - /ppo

Post by lumberjack »

Phil,
The /ppo compiler switch just write the <source>.prg into a file <source>.ppo. If you don't set the switch the pre-processor output will only be available in memory. In essence if you don't have any defines/#command/#translate etc the .prg and the .ppo will have exactly the same content.

I in principle always have the /ppo switch set in debug mode. If you work with #command/#translate a lot then the .ppo is where you look at debugging your #command errors.

Hope this was the explanation you wanted.

Jack
______________________
Johan Nel
Boshof, South Africa
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

HELP ! - with syntax and lines etc.

Post by lumberjack »

Frank,

If we look back at Clipper and to a large extend VO/Vulcan, all commands were actually #command pre-processor driven.

I agree there are some cases where it might just be too much for the pre-processor to handle, but in your case of the auto, we can easily have an optional "auto" in the command if required. There are so many possibilities, my motto will be that when you see repetition investigate the possibility to create a #command to ease the amount of typing.

Jack
______________________
Johan Nel
Boshof, South Africa
User avatar
lumberjack
Posts: 727
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

HELP ! - with syntax and lines etc.

Post by lumberjack »

Hi Wolfgang,

Thanks. Credit to Johan for putting me on track with the #command. Not too far in the future hopefully we will have it available in X# too.

Jack
______________________
Johan Nel
Boshof, South Africa
Post Reply