转换C#(有类型的事件)到VB.NET [英] Convert C# (with typed events) to VB.NET

查看:200
本文介绍了转换C#(有类型的事件)到VB.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASPX页面(用VB代码隐藏)。我想延长在GridView类显示的时候没有行返回页眉/页脚



我发现了一个C#示例在线(的链接)(的来源)。但是,我不能将它转换为VB,因为它使用类型的事件(这是不合法的VB)。



我曾尝试一些免费的C#到VB.NET转换器上网,但都没有奏效。



请的例子转换为VB.NET或提供扩展GridView控件类的替代方法。



备注/难点:




  1. 如果你得到一个错误数据视图对象,指定类型为 System.Data.DataView 和类型比较可能是以下内容:如果数据。[的GetType()是的GetType(System.Data.DataView)然后


  2. 由于事件MustAddARow不能有型在VB(和事件的RaiseEvent 没有返回值),我该怎么把它比作没有在功能 OnMustAddARow()




修改?



以下是(希望)相关的代码,以帮助回答这个问题的样本。

 命名空间AlwaysShowHeaderFooter {
公共委托的IEnumerable MustAddARowHandler(IEnumerable的数据);

公共类GridViewAlwaysShow:GridView控件{
//各成员函数省略//
保护的IEnumerable OnMustAddARow(IEnumerable的数据){
如果(MustAddARow == NULL){
抛出新的NullReferenceException(数据源中没有行必须处理\。MustAddARow\事件);
}
返回MustAddARow(数据);
}

公共事件MustAddARowHandler MustAddARow;
}
}


解决方案

由于我在评论说,代码将无法转换为VB.Net神奇。这将需要工作THRU它来得到正常的编译。



最简单的将是编译的C#代码库。




  1. 创建一个新的项目(C#类
    库),并命名为AlwaysShowHeaderFooter

  2. 从App_Code文件在移动文件至
    新项目

  3. 添加一个参考的System.Web和System.Configuration

  4. 在您的Web项目中添加引用要么编译后的dllAlwaysShowHeaderFooter的,或添加项目本身作为一个参考,如果你在同一个解决方案有它

  5. 切换出<%@注册的TagPrefix =自定义命名空间=AlwaysShowHeaderFooter%> <%@注册大会=AlwaysShowHeaderFooter命名空间=AlwaysShowHeaderFooter的TagPrefix =自定义%>



现在你已经走出分割控制,以它自己的项目,该项目可以在任何.NET项目引用。


I have an ASPX page (with VB Codebehind). I would like to extend the GridView class to show the header / footer when no rows are returned.

I found a C# example online (link) (source). However, I cannot convert it to VB because it uses typed events (which are not legal in VB).

I have tried several free C# to VB.NET converters online, but none have worked.

Please convert the example to VB.NET or provide an alternate method of extending the GridView class.

Notes / Difficulties:

  1. If you get an error with DataView objects, specify the type as System.Data.DataView and the type comparison could be the following: If data.[GetType]() Is GetType(System.Data.DataView) Then

  2. Since the event MustAddARow cannot have a type in VB (and RaiseEvent event doesn't have a return value), how can I compare it to Nothing in the function OnMustAddARow()?

EDIT:

The following is a sample with (hopefully) relevant code to help answer the question.

namespace AlwaysShowHeaderFooter {
    public delegate IEnumerable MustAddARowHandler(IEnumerable data);

    public class GridViewAlwaysShow : GridView {
           // Various member functions omitted //
           protected IEnumerable OnMustAddARow(IEnumerable data) {
            if (MustAddARow == null) {
                throw new NullReferenceException("The datasource has no rows. You must handle the \"MustAddARow\" Event.");
            }
            return MustAddARow(data);
        }

        public event MustAddARowHandler MustAddARow;
    }
}

解决方案

As I said in my comment the code will not convert to VB.Net "magically". It will require working thru it to get it to compile properly.

The easiest would be to compile the the C# code as a library.

  1. Create a new project (C# Class Library) and name it "AlwaysShowHeaderFooter"
  2. Move the files from App_Code over to the new project
  3. Add a reference to System.Web and System.Configuration
  4. Add a reference in your web project to either the compiled dll's of "AlwaysShowHeaderFooter", or add the project itself as a reference if you have it in the same solution.
  5. Switch out <%@ Register TagPrefix="Custom" Namespace="AlwaysShowHeaderFooter" %> with <%@ Register Assembly="AlwaysShowHeaderFooter" Namespace="AlwaysShowHeaderFooter" TagPrefix="Custom" %>

Now you have split the control out to it's own project which can be referenced in any .Net project.

这篇关于转换C#(有类型的事件)到VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆