Can You Convert This VB Snippet?

C

clintonG

This code has to go into the global.asax Application_Start code block.
I'm just not getting this one right and the web-based code converters choke
on it. Can somebody rewrite this VB snippet to C# for me?

Sub Profile_MigrateAnonymous(ByVal sender As Object, ByVal e As
ProfileMigrateEventArgs)

Dim anonymousProfile As ASP.HttpProfile =
Profile.GetProfile(e.AnonymousId)

If anonymousProfile.Cart IsNot Nothing Then
Profile.Cart = anonymousProfile.Cart
End If

End Sub
 
T

Tom Shelton

This code has to go into the global.asax Application_Start code block.
I'm just not getting this one right and the web-based code converters choke
on it. Can somebody rewrite this VB snippet to C# for me?

Sub Profile_MigrateAnonymous(ByVal sender As Object, ByVal e As
ProfileMigrateEventArgs)

Dim anonymousProfile As ASP.HttpProfile =
Profile.GetProfile(e.AnonymousId)

If anonymousProfile.Cart IsNot Nothing Then
Profile.Cart = anonymousProfile.Cart
End If

End Sub

void Profile_MigrateAnonymous (object sender, ProfileMigrateEventArgs e)
{
ASP.HttpProfile anonymousProfile =
Profile.GetProfile (e.AnonymousId);

if (anonymousProfile.Cart != null)
{
Profile.Cart = anonymousProfile.Cart;
}
}

HTH
 
W

W.G. Ryan eMVP

private void Profile_MigrateAnonymous(object sender, ProfileMigrateEventArgs
e){
Profile.GetProfile(e.AnoynmousId);
if(anoynmousProfile.Cart != null){
Profile.Cart == anonymoustProfile.Cart;
}
}
 
W

W.G. Ryan eMVP

Ooops, I forogt one line:
Dim anonymousProfile As ASP.HttpProfile =
Profile.GetProfile(e.AnonymousId)

===
ASP.HttpProfile anonymousProfile = Profile.GetProfile(e.AnoynmousId);
 
C

clintonG

Thank you. That's what I tried but I'm still getting mismatched brace
exceptions on the first brace of the Application_Start code block when the
converted code is used in the global.asax as follows...

void Application_Start(Object sender, EventArgs e)
{
void Profile_MigrateAnonymous(object sender, ProfileMigrateEventArgs e)
{
ASP.HttpProfile anonymousProfile = Profile.GetProfile
(e.AnonymousId);
if (anonymousProfile.Cart != null)
{
Profile.Cart = anonymousProfile.Cart;
}
}
}

It seems to be the presence of the Profile_MigrateAnonymous code block. I've
commented that code block out while leaving the statements within the
Profile_MigrateAnonymous code block uncommented and vice-versa. When the
Profile_MigrateAnonymous code block (and its braces) are commented the
squiggly underlined Application_Start code block brace mismatch dissappears.

<%= Clinton Gallagher




 
C

clintonG

Thank you. Please see my response above...

<%= Clinton Gallagher

W.G. Ryan eMVP said:
Ooops, I forogt one line:
Dim anonymousProfile As ASP.HttpProfile =
Profile.GetProfile(e.AnonymousId)

===
ASP.HttpProfile anonymousProfile = Profile.GetProfile(e.AnoynmousId);
 
N

Nick Malik

Clinton...
You are declaring a method within a method. Of course the compiler is
complaining.
Declare your method seperately... then call it from within Application_Start

--- Nick

void Profile_MigrateAnonymous(object sender, ProfileMigrateEventArgs
e)
{
ASP.HttpProfile anonymousProfile = Profile.GetProfile
(e.AnonymousId);
if (anonymousProfile.Cart != null)
{
Profile.Cart = anonymousProfile.Cart;
}
}

void Application_Start(Object sender, EventArgs e)
{
Profile_MigrateAnonymous(sender, e);
}

clintonG said:
Thank you. That's what I tried but I'm still getting mismatched brace
exceptions on the first brace of the Application_Start code block when the
converted code is used in the global.asax as follows...

void Application_Start(Object sender, EventArgs e)
{
void Profile_MigrateAnonymous(object sender, ProfileMigrateEventArgs e)
{
ASP.HttpProfile anonymousProfile = Profile.GetProfile
(e.AnonymousId);
if (anonymousProfile.Cart != null)
{
Profile.Cart = anonymousProfile.Cart;
}
}
}

It seems to be the presence of the Profile_MigrateAnonymous code block. I've
commented that code block out while leaving the statements within the
Profile_MigrateAnonymous code block uncommented and vice-versa. When the
Profile_MigrateAnonymous code block (and its braces) are commented the
squiggly underlined Application_Start code block brace mismatch dissappears.

<%= Clinton Gallagher
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top