473,395 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

MVP's: Determine Dimensioning Class or Assembly

If I declare a variable and set it = nothing then pass it byref into a
routine that accepts an optional argument of the same type with a
default of nothing, is there anyway to determine where the varable was
decalred? I know I could include another argument that specifies
whether i'm passing it in or not, but was looking for a more elegant
solution. If the dimensioning class cannot be determined, can the
dimensioning assembly?

i.e.

Dim sqlTran as SqlTransaction = Nothing
Dim objClass As New MyClass

objClass.SomeRoutine(sqlTran)

'*** Different Class ***
Class MyClass
Public Sub SomeRoutine(Optional ByRef sqlTran as SqlTransaction =
Nothing)

'was sqlTran passed in or is it the optional default?

End Sub
End Class

Thanks for your help,

-Keith

Feb 1 '07 #1
3 1202
<ke***@galaxies.comwrote:
If I declare a variable and set it = nothing then pass it byref into a
routine that accepts an optional argument of the same type with a
default of nothing, is there anyway to determine where the varable was
decalred? I know I could include another argument that specifies
whether i'm passing it in or not, but was looking for a more elegant
solution. If the dimensioning class cannot be determined, can the
dimensioning assembly?
I'd be very surprised if there were any way of determining it, but even
if such a way existed, I'd recommend against using it. Such an unusual
way of determining behaviour goes against the principle of least
surprise. If you want behaviour to differ in different situations,
create a parameter for that case.

You could always create three overloads - one with the transaction
parameter and the flag, one with neither (calling the first with
Nothing and False) and one with the transaction (calling the first with
Nothing and True).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 1 '07 #2
On Jan 31, 4:30 pm, Jon Skeet [C# MVP] <s...@pobox.comwrote:
<k...@galaxies.comwrote:
If I declare a variable and set it = nothing then pass it byref into a
routine that accepts an optional argument of the same type with a
default of nothing, is there anyway to determine where the varable was
decalred? I know I could include another argument that specifies
whether i'm passing it in or not, but was looking for a more elegant
solution. If the dimensioning class cannot be determined, can the
dimensioning assembly?

I'd be very surprised if there were any way of determining it, but even
if such a way existed, I'd recommend against using it. Such an unusual
way of determining behaviour goes against the principle of least
surprise. If you want behaviour to differ in different situations,
create a parameter for that case.

You could always create three overloads - one with the transaction
parameter and the flag, one with neither (calling the first with
Nothing and False) and one with the transaction (calling the first with
Nothing and True).

--
Jon Skeet - <s...@pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Thanks Jon,

I guess I have to agree with you. I was trying to avoid overloads as,
IMHO, they add clutter, but I have to agree that it is the right way
of doing things. I'm trying to create business layer routines in such
a way that they can be called with or without a transaction and can be
nest with other routines in the same transaction and only the creator
of the transaction will commit or rollback. There's an example below,
but it would be just as easy to do with two versions of each routine,
one that accepts the transaction and one that accepts nothing, creates
the transaction and calls the other. The latter of course would
handle the commit/rollback. This way would also support handling the
nesting from the UI layer allowing the UI layer to determine the fate
of the transaction.

Public Sub WCMstUpdate(Optional ByVal blnRecalc As Boolean =
False, _
Optional ByRef sqlTran As
SqlTransaction = Nothing)
Dim conn As New SqlConnection(m_strConnection)
Dim blnCommit As Boolean = sqlTran Is Nothing

Try
If sqlTran Is Nothing Then
conn.Open()
sqlTran = conn.BeginTransaction
End If

SqlHelper.ExecuteNonQuery(sqlTran, _
CommandType.StoredProcedure, _
SP_WC_MST_UPDATE)

If blnRecalc Then
Dim objOnlineDrop As New WIP.clsOnlineDrop
Call
objOnlineDrop.RecalculateWORScheduleDateByWC(sqlTr an)
Call objOnlineDrop.WORoutingUpdateWCGroupFl(sqlTran)
End If

If blnCommit Then sqlTran.Commit()
Catch ex As Exception
If Not sqlTran Is Nothing And blnCommit Then
sqlTran.Rollback()
Throw
Finally
If Not conn Is Nothing Then conn.Close()
End Try
End Sub
Thanks again.

Feb 1 '07 #3
Hello keith,
>MVP's: Determine Dimensioning Class or Assembly
^^^^^
Sorry, hit follow-up by accident.
Oliver Sturm
--
http://www.sturmnet.org/blog
Feb 1 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
4
by: Yasutaka Ito | last post by:
Hi, Is there a way to determine which version of .NET Framework any given assembly is built with? thanks! -Yasutaka
3
by: Chris Becker | last post by:
The following code works. My problem is that I don't want to have to hardcode the string that I set resourceName to in the code. Is there a way for me to determine the namespace of the assembly...
11
by: Z D | last post by:
Hello, If I have a .NET assembly, how do I determine what version of the .NET framework it.... 1) was compiled against 2) is supposed to use 3) is compatible with? Is there a utility that...
3
by: Guoqi Zheng | last post by:
Dear sir, On some of my pages, I used a <base href="http://www.meetholland.com/"> I need to dynamically determine the base href value to different URL based on user session. I am thinking...
2
by: Scott | last post by:
Does anyone know of a way to get the .NET Framework version that's required by a specified assembly. I have a program I've written that creates a Windows Installer setup for any application....
12
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
I am writing a web app to be widely distributed where I do not know the installed .NET Framework version. I want to take advantage of some .NET 3.0 classes if they are installed, but gracefully...
1
by: Verde | last post by:
Is there an easier way to determine if a specific assembly is loaded into the current AppDomain? I'm thinking that there has to be a way to do it without looping through all currently loaded...
7
by: Cramer | last post by:
I'm wondering if there is an easy way to programmatically determine if an assembly is installed in the GAC. This would be similar to our ability to easily determine if a file exists...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.