zoukankan      html  css  js  c++  java
  • (.NET) IntelliSense difference of Extension Method name in Statement Completion for VB and C#.

    Recently, I noticed a strange behavior for looking up name of Extension Method in VB and C#.

    That is, if you overwrite a method or a property by using extension, your extension will not displayed for IDE IntelliSense.

    But if you declared a new generic method, you will notice a small difference.

    1. Overwrite the existed property via VB. ( Actually, C# is the same. )

    a) Create a VB Console Application.

    b) Paste below code at the end of editor.

    Public Class Lucas
        Private n_test As String
    
        Public Property Test() As String
            Get
                Return n_test
            End Get
            Set(ByVal value As String)
                n_test = value
            End Set
        End Property
    End Class
    
    Module LucasExtension
        <Extension()> _
        Public Function Test(Of T)(ByVal aParam As Lucas) As String
            Return "Hello, Lucas Luo!"
        End Function
    End Module
    

    c) Type below code inside Main in Module1.

            Dim olucas = New Lucas()
            olucas.
    

    d) Notice the IntelliSense.

    2. Verify the Extension Method in IntelliSense between C# and VB via generic type.

    a) Create a C# Console Application.

    b) Type below code under class Program.

    public class Lucas
        {
            public string Test { get; set; }
        }
    
        public static class LucasExtension
        {
            public static string TestExtension<T>(this Lucas aParam)
            {
                return "Hello, Lucas Luo!";
            }
        }
    

    c) Type below code inside in Pragram class and notice the IntelliSense.

        class Program
        {
            static void Main(string[] args)
            {
                Lucas olucas = new Lucas();
                olucas.
            }
        }
    
    

    d) See below picture, you'll see the "<>" for the generic type of extension method.

    e) Now, let's see what's the behavior in VB.

    f) Create a vb console application and add the extension method based on above steps.

    g) Slit change on the generic type of extension method. We use "Of" to represent the generic type that you want to pass. See below code.

    Module LucasExtension
        <Extension()> _
        Public Function TestExtension(Of T)(ByVal aParam As Lucas) As String
            Return "Hello, Lucas Luo!"
        End Function
    End Module
    

    h) Type the same VB code as in the first sample inside Main in Module1.

    i) See the IntelliSense of VB extension method. You'll find that there isn't any "<>" string, or "Of" string displayed in VB intellisense.

  • 相关阅读:
    Exchange 2013与 Office Web Apps 整合
    SharePoint2013 以其他用户登录和修改AD域用户密码 功能
    sharepoint 2010 自定义页面布局
    sharepoint 2010 记录管理 对象模型
    SharePoint2010 对象模型 关联列表
    在SharePoint Server 2010中更改“我的网站”
    xenapp 6.5 客户端插件第一次安装总是跳到官网
    如何解决在Windows Server 2008 R2 上安装证书服务重启后出现 CertificationAuthority 91错误事件
    在Win7 Hyper-v虚拟机中挂接真实机的声卡
    win8 中如何删除 共享文件夹 用户名和密码
  • 原文地址:https://www.cnblogs.com/lucasluo/p/1898446.html
Copyright © 2011-2022 走看看