Silverlight Lazy Load Children in VB.Net

Silverlight Lazy Load Children in VB.Net

Old forum URL: forums.lhotka.net/forums/t/7539.aspx


GregDobbs posted on Sunday, August 30, 2009

Hello all.

I am attempting to lazy load children in SL using CSLALight 3.7.0. using VB .Net.

The following C# code is from this forum:

private bool _loadingScore = false;

private static PropertyInfo ScoreInfoProperty =
RegisterProperty(new PropertyInfo("ScoreInfo", "ScoreInfo"));
public Score ScoreInfo
{
get
{
if (!_loadingScore && (!FieldManager.FieldExists(ScoreInfoProperty) || ReadProperty(ScoreInfoProperty) == null))
{
#if SILVERLIGHT
_loadingScore = true;
Score.GetScore(
ReadProperty(ProfileIDProperty),
ReadProperty(PersonNameProperty),
ReadProperty(NicknameProperty),
ReadProperty(TeamIDProperty),
((TeamMemberInfoList)this.Parent).ParentTeam.Name,
(o, e) =>
{
LoadProperty(ScoreInfoProperty, e.Object);
OnPropertyChanged(ScoreInfoProperty.Name);
_loadingScore = false;
}
);
#else
LoadProperty(ScoreInfoProperty, Score.GetScore(
ReadProperty(ProfileIDProperty),
ReadProperty(PersonNameProperty),
ReadProperty(NicknameProperty),
ReadProperty(TeamIDProperty),
((TeamMemberInfoList)this.Parent).ParentTeam.Name));
#endif
}
return GetProperty(ScoreInfoProperty);
}
}

As I am abysmal in C# (and also not familiar enough with lambdas yet), does anyone have a translation for this or a similar implementation written in VB.Net?

Thanks in advance!

RockfordLhotka replied on Monday, August 31, 2009

This is much harder in VB. There is no multi-line lambda in the current version of VB, so you have to create a different method and pass its address as the callback handler.

You might also need to create an entire new class to act as the "message" between the original code and the callback method.

The result is that you'll write 2-3x more code (and more complex code) to get the same result.

It is a serious PITA, and is the primary reason I stopped maintaining CSLA .NET itself in VB (because this occurs in many places inside the framework).

The good news (fwiw) is that VB 10 has multi-line lambdas, so sometime next year you'll be able to do this the easy way.

Copyright (c) Marimer LLC