如何将C#中的Dynamic转换为vb?

编程入门 行业动态 更新时间:2024-10-19 00:28:32
本文介绍了如何将C#中的Dynamic转换为vb?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

public dynamic GetPosts() { var ret = (from post in db.Posts.ToList() orderby post.PostedDate descending select new { Message = post.Message, PostedBy = post.PostedBy, PostedByName = post.UserProfile.UserName, PostedByAvatar =imgFolder +(String.IsNullOrEmpty(post.UserProfile.AvatarExt) ? defaultAvatar : post.PostedBy + "." + post.UserProfile.AvatarExt), PostedDate = post.PostedDate, PostId = post.PostId, PostComments = from comment in post.PostComments.ToList() orderby comment.CommentedDate select new { CommentedBy = comment.CommentedBy, CommentedByName = comment.UserProfile.UserName, CommentedByAvatar = imgFolder +(String.IsNullOrEmpty(comment.UserProfile.AvatarExt) ? defaultAvatar : comment.CommentedBy + "." + comment.UserProfile.AvatarExt), CommentedDate = comment.CommentedDate, CommentId = comment.CommentId, Message = comment.Message, PostId = comment.PostId } }).AsEnumerable(); return ret; }

我坚持使用动态类型不知道如何将其转换为vb 这是我的VB代码:

I stuck with the dynamic type don't know how to convert it into vb Here is my VB Code:

Public Function GetPosts() As IEnumerable(Of Post) Dim ret = (From post In db.Posts.ToList() Order By post.PostedDate Descending Select New With { _ Key .Message = post.Message, _ Key .PostedBy = post.PostedBy, _ Key .PostedByName = post.UserProfile.UserName, _ Key .PostedByAvatar = imgFolder & Convert.ToString((If([String].IsNullOrEmpty(post.UserProfile.AvatarExt), defaultAvatar, post.PostedBy + "." + post.UserProfile.AvatarExt))), _ Key .PostedDate = post.PostedDate, _ Key .PostId = post.PostId, _ Key .PostComments = From comment In post.PostComments.ToList() Order By comment.CommentedDate Select New With { _ Key .CommentedBy = comment.CommentedBy, _ Key .CommentedByName = comment.UserProfile.UserName, _ Key .CommentedByAvatar = imgFolder & Convert.ToString((If([String].IsNullOrEmpty(comment.UserProfile.AvatarExt), defaultAvatar, comment.CommentedBy + "." + comment.UserProfile.AvatarExt))), _ Key .CommentedDate = comment.CommentedDate, _ Key .CommentId = comment.CommentId, _ Key .Message = comment.Message, _ Key .PostId = comment.PostId _ } _ }).AsEnumerable() Return ret End Function

推荐答案

您可以进行自动翻译。首先,考虑使用开源ILSpy。请看我过去的答案: 代码解释,C#到VB.NET [ ^ ]。
-SA
You can do automatic translation. First of all, consider using open-source ILSpy. Please see my past answer: Code Interpretation, C# to VB.NET[^].
—SA

更多推荐

如何将C#中的Dynamic转换为vb?

本文发布于:2023-11-11 23:11:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579804.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   如何将   Dynamic   vb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!