【问题标题】:Create a module of Extensions methods for all the new projects为所有新项目创建一个扩展方法模块
【发布时间】:2015-08-06 11:05:47
【问题描述】:

我想知道是否有办法为 Visual Studio 2013 中的所有新项目创建扩展方法模块。

例如,这是我的模块:

Imports System.Runtime.CompilerServices
Imports System.IO

Module Extensions

    <Extension> Public Function ReplaceFirst(value As String, oldValue As String, newValue As String) As String
        Dim position As Integer = value.IndexOf(oldValue)
        If position = -1 Then
            Return value
        Else
            Return value.Substring(0, position) + newValue + value.Substring(position + oldValue.Length)
        End If
    End Function

    <Extension> Public Function ReadAllLines(value As String) As List(Of String)
        If value Is Nothing Then
            Return Nothing
        End If

        Dim lines As New List(Of String)
        Using StringRdr As New StringReader(value)
            While StringRdr.Peek() <> -1
                Dim line As String = StringRdr.ReadLine
                If Not String.IsNullOrWhiteSpace(line) Then
                    lines.Add(line)
                End If
            End While
        End Using

        Return lines
    End Function

    <Extension> Public Function UppercaseFirstLetter(value As String) As String
        If String.IsNullOrEmpty(value) Then
            Return value
        End If

        Dim Chars() As Char = value.ToCharArray
        Chars(0) = Char.ToUpper(Chars(0))

        Return New String(Chars)
    End Function

    <Extension> Public Function ZeroBased(value) As Integer
        Return value - 1
    End Function

End Module

如何在我的所有项目中使用此扩展方法而不在所有项目中添加模块?

问候,Drarig29。

【问题讨论】:

    标签: vb.net visual-studio-2013 extension-methods projects


    【解决方案1】:

    将其设为库 (DLL),并在每个项目中添加对该库的引用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-25
      • 2013-12-23
      • 1970-01-01
      • 1970-01-01
      • 2021-02-06
      • 1970-01-01
      相关资源
      最近更新 更多