User1860262783 posted
I have created a class containing a few string extensions, as follows:
Imports Microsoft.VisualBasic
Namespace Extensions
<HideModuleName()> _
Public Module Extensions
<System.Runtime.CompilerServices.Extension()> _
Public Function Replace(ByVal s As String, ByVal charPosition As Integer, ByVal replaceWith As Char) As String
Return s.Substring(0, charPosition) + replaceWith + s.Substring(charPosition + 1)
End Function
<System.Runtime.CompilerServices.Extension()> _
Public Function Replace(ByVal s As String, ByVal start As Integer, ByVal length As Integer, ByVal replaceWith As String) As String
Return s.Substring(0, start) + replaceWith + s.Substring(start + length)
End Function
<System.Runtime.CompilerServices.Extension()> _
Public Function ToProperCase(ByVal s As String) As String
Dim ret As String = s.ToLower()
Dim regEx As New Regex("^(.)|\s(.)|\.\s*(.)|\/(.)", RegexOptions.Compiled)
For Each m As RegularExpressions.Match In regEx.Matches(s)
ret = ret.Replace(m.Index, m.Length, m.Value.ToUpper())
Next
Return ret
End Function
End Module
End Namespace
This works fine when I call the new methods (str.ToProperCase) within an aspx.vb file, but when I try and use 'String.ToProperCase(Eval("blah"))' or 'Eval("blah").ToString().ToProperCase()' I get an error telling me that "'ToProperCase' is not a member of 'String'".
Oh, just in case it's relevant to this, I'm using .Net Framework 2.0.
Would I need to register something within the aspx page in order to use extensions? If not, is there another way to enable them?
Thanks