So, we were sitting around in the lunchroom talking, and came up with something that we think could be a really valuable change to a key method in the .NET framework (as well as in just about every other language). The name IsNumeric is misleading, because you would expect it to return true only if the value was truly a number, but as many know this is not really the case. As such, I have created a couple of other methods that may be suitable to replace it.
Public Function MostLikelyNumeric(ByVal Expression As Object) As Boolean
Return IsNumeric(Expression)
End FunctionPublic Function PossiblyNumeric(ByVal Expression As Object) As Boolean
Return IsNumeric(Expression)
End Function
Either of those seem like they are more descriptive….
Have you ever had the situation where you needed to return a Method’s name? An example of this might be in an error routine, or for logging. The following function will do just that, with no need to hard code the method’s name.
‘Returns a methods name, based on the current stacktrace
Friend Shared Function ReturnSource() As String
Dim aStack As New System.Diagnostics.StackTrace
Dim aMethod As System.Reflection.MethodBase
‘Use Frame 1, as Frame 0 is this Method
aMethod = System.Reflection.MethodInfo.GetMethodFromHandle(aStack.GetFrame(1).GetMethod.MethodHandle)
Return aMethod.ReflectedType.FullName + “.” + aMethod.Name
End Function
Here’s a useful little re-build and run macro the 4Guys came up with for the .NET IDE.
If you’ve been developing any ASP.NET applications, you may have run into the same frustration that we have with the Application cache. We’ve discovered that the Application cache is not cleared until you rebuild your application (which when you think about it is kind of what you should expect) so often when you are expecting the cache to be empty, it isn’t, leaving you scratching your head until you once again remember, Oh, that’s right I have to rebuild before I run to make sure the Application cache has been cleared.
So since no button exists to rebuild a solution and run in just one single click and we could not find anyone else out there who had already done this work, we created our own Macro in VB.NET and assigned it to a button on our toolbar.
Just add this code to a Macro Module and then add it to a button on the toolbar in .NET and enjoy the one button click to re-build and run a project!
Imports EnvDTE
Imports System.Diagnostics
Public Module UserCreated
Public Sub ReBuildAndRun()
‘Add an event so that we can detect when the solution has completed the rebuild process
AddHandler DTE.Events.BuildEvents.OnBuildDone, AddressOf AfterBuild
‘Rebuild the entire Solution
DTE.ExecuteCommand(”Build.RebuildSolution”)
End Sub
‘This sub is called once the solution has completed the rebuild process
Public Sub AfterBuild(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction)
‘The Event Handler must be removed to prevent eternal looping since
‘the Debugger.Go call causes another build which would then raise the event again and again and again….
RemoveHandler DTE.Events.BuildEvents.OnBuildDone, AddressOf MyMacros.UserCreated.AfterBuild
‘Run the project
DTE.Debugger.Go(True)
End Sub
End Module
So, in developing the architecture for a new Portal project that the 4 Guys are working on, we decided to be as nice to the future developers on the project as possible (aren’t we such sweethearts?) And part of being nice to a developer is giving him as much intellisense as possible in the code. Well, in trying to deliver this very nice feature to the developers, we decided that function parameters should have intellisense as well, whenever possible. And here is the method we came up with for providing this. Our question becomes, is there a better method out there?
‘An enumeration of the names of the various User Controls
Friend Enum UCName As Integer
UCHeader = 1
UCFooter = 2
UCLogin = 3
Temp = -99
End Enum
Friend Function GetUserControl(ByVal Name As UCName) As UserControl
‘Returns a UserControl based on the Name passed in to the function.
Try
Return CType(LoadControl(GetUCPath(Name)), UserControl)
Catch ex As Exception
Throw
End Try
End Function
Friend Function GetUCPath(ByVal Name As UCName) As String
Try
Select Case Name
Case UCName.Temp
Return “~Temp.ascx”
Case UCName.UCFooter
Return“~BaseUserControlsUCFooter.ascx”
Case UCName.UCHeader
Return“~BaseUserControlsUCHeader.ascx”
Case UCName.UCLogin
Return “~BaseUserControlsUCLogin.ascx”
End Select
Catch ex As Exception
Throw
End Try
End Function
So, if a developer wishes to load a particular UserControl from anywhere else in the project, the can just call the function GetUserControl like this.
Dim lnkFooter As New UCFooter
lnkError = CType(GetUserControl(UCName.UCFooter), UCFooter)
No need for the developer to remember the path for every user control, (no need for the developer to even remember what user controls are available since they can just scroll thru the Enum to see what exists). So what do you think? Is this a good practice and worth the extra overhead and work to provide this intellisense or is there a better method out there?
[powered by WordPress.]
22 queries. 0.160 seconds