我想知道是否有办法为Visual Studio 2013中的所有新项目创建Extensions方法模块。
例如,这是我的模块:
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
如何在所有项目中使用此Extensions方法而不在所有项目中添加模块?
问候,Drarig29。
答案 0 :(得分:1)
将其设为库(DLL)并在每个项目中添加对库的引用。