Sabe
Legacy Member
Hi,
Volgende C# heb ik omgezet naar VB.NET maar ik blijf de error 'Cast' is not a member of 'System.Collections.ArrayList' krijgen.
Kan iemand mij helpen?
C#
--------------------------------
VB.NET
Thanks
Volgende C# heb ik omgezet naar VB.NET maar ik blijf de error 'Cast' is not a member of 'System.Collections.ArrayList' krijgen.
Kan iemand mij helpen?
C#
Code:
protected override void OnLoad(EventArgs e)
{
var queryString = Request.QueryString["ProdID"];
int prodId;
if (queryString == null || !int.TryParse(Request.QueryString["ProdID"], out prodId))
{
return;
}
var product = new ProductController().GetProduct(prodId, PortalSettings.CultureCode);
var productUrl = SharedFunctions.GetProductUrlByProductID(PortalSettings.PortalId, TabController.CurrentPage.TabID, product.ProductID, 0, product.SEOName, true, PortalSettings.CultureCode);
var productImgs = new ProductController().GetProductImageList(prodId, PortalSettings.CultureCode).Cast<NB_Store_ProductImageInfo>().ToList();
var socialMeta = new List<HtmlMeta>();
var htmlMeta = new HtmlMeta { Content = product.ProductName };
htmlMeta.Attributes.Add("property", "og:title");
socialMeta.Add(htmlMeta);
if(!string.IsNullOrEmpty(product.Summary))
{
htmlMeta = new HtmlMeta { Content = product.Summary };
htmlMeta.Attributes.Add("property", "og:description");
socialMeta.Add(htmlMeta);
}
htmlMeta = new HtmlMeta { Content = "product" };
htmlMeta.Attributes.Add("property", "og:type");
socialMeta.Add(htmlMeta);
htmlMeta = new HtmlMeta { Content = productUrl };
htmlMeta.Attributes.Add("property", "og:url");
socialMeta.Add(htmlMeta);
htmlMeta = new HtmlMeta { Content = PortalSettings.PortalName };
htmlMeta.Attributes.Add("property", "og:site_name");
socialMeta.Add(htmlMeta);
foreach (var img in productImgs)
{
htmlMeta = new HtmlMeta { Content = Request.Url.Scheme + "://" + Request.Url.Authority + img.ImageURL };
htmlMeta.Attributes.Add("property", "og:image");
socialMeta.Add(htmlMeta);
}
foreach (var meta in socialMeta)
{
this.Page.Header.Controls.Add(meta);
}
}
--------------------------------
VB.NET
Code:
Protected Overrides Sub OnLoad(e As EventArgs)
Dim queryString = Request.QueryString("ProdID")
Dim prodId As Integer
If queryString Is Nothing OrElse Not Integer.TryParse(Request.QueryString("ProdID"), prodId) Then
Return
End If
Dim product = New ProductController().GetProduct(prodId, PortalSettings.CultureCode)
Dim productUrl = SharedFunctions.GetProductUrlByProductID(PortalSettings.PortalId, TabController.CurrentPage.TabID, product.ProductID, 0, product.SEOName, True, _
PortalSettings.CultureCode)
Dim productImgs = New ProductController().GetProductImageList(prodId, PortalSettings.CultureCode).Cast(Of NB_Store_ProductImageInfo)().ToList()
Dim socialMeta = New List(Of HtmlMeta)()
Dim htmlMeta = New HtmlMeta() With { _
Key .Content = product.ProductName _
}
htmlMeta.Attributes.Add("property", "og:title")
socialMeta.Add(htmlMeta)
If Not String.IsNullOrEmpty(product.Summary) Then
htmlMeta = New HtmlMeta() With { _
Key .Content = product.Summary _
}
htmlMeta.Attributes.Add("property", "og:description")
socialMeta.Add(htmlMeta)
End If
htmlMeta = New HtmlMeta() With { _
Key .Content = "product" _
}
htmlMeta.Attributes.Add("property", "og:type")
socialMeta.Add(htmlMeta)
htmlMeta = New HtmlMeta() With { _
Key .Content = productUrl _
}
htmlMeta.Attributes.Add("property", "og:url")
socialMeta.Add(htmlMeta)
htmlMeta = New HtmlMeta() With { _
Key .Content = PortalSettings.PortalName _
}
htmlMeta.Attributes.Add("property", "og:site_name")
socialMeta.Add(htmlMeta)
For Each img As var In productImgs
htmlMeta = New HtmlMeta() With { _
Key .Content = Request.Url.Scheme + "://" + Request.Url.Authority & Convert.ToString(img.ImageURL) _
}
htmlMeta.Attributes.Add("property", "og:image")
socialMeta.Add(htmlMeta)
Next
For Each meta As var In socialMeta
Me.Page.Header.Controls.Add(meta)
Next
End Sub
Thanks
