|
Hi Clay,
AFAIK names of local variables are not available.
names of parameters (method arguments) are available, although I am not sure why that is.
the only thing that needs to be available (for reflection to work as intended) is the public
class members, nothing local.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Yeah, I was afraid of that. Thanks.
--Clay
|
|
|
|
|
Luc Pattyn wrote: names of parameters (method arguments) are available, although I am not sure why that is.
The names of parameters are available because they make using an API orders of magnitude easier. Otherwise Intellisense would not be able to provide you with the parameter names and you would just have to know which parameter is which. If the XML documentation is included, you could argue that Intellisense could determine the names from there, but libraries do not always have that documentation.
|
|
|
|
|
Clay Walnum wrote: LogLocalVariables(count, average)
Well, since you're passing the local variable in already, what's the point of going back to the method that called it to figure them out??
Really, you're not the first person to try this. There are easier methods of logging values. One major problem you'll run into attempting to do this is variable scope. For example, you can have a variable that only exists inside a loop in a method, but is out of scope in the rest of the method, either before or after the loop. You can't get the value of a variable that doesn't exist yet or is already dead.
Another problem is Reflection's performance. Reflection is notoriously slow. If you end up trying to log variable values inside of a loop, you'll find that your app's performance may be quite unacceptable.
And yet another issue is what happens when you go from a Debug build to a Release build?? All of this logging code will still be in the release build. How are you going to remove all this code so you don't take a performance hit in the final release? If you use the Debug class, these calls are automatically removed from the Release build. Trace method calls are converted to call equivilent Debug methods (weird!) and are NOT removed from the Release build.
So, pretty much, the best method to use with the least maintenance is directly calling Debug.WriteLine in your code where needed.
|
|
|
|
|
Thanks for the input. I'm doing this more to experiment with Reflection than actually creating a custom debugging system. It just seems that there ought be be a way to get the name of a variable, as well as the value, other than passing them both as arguments, like this:
LogVariable("VarName", VarName)
But I guess not.
--Clay
|
|
|
|
|
Yes, I fully agree, in C# that is the one thing I miss most from C's pre-processor,
where you could create a one-argument macro that uses it twice, once for the name, once
for the value.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
One major problem with that approach is that the LogLocalVariables method doesn't get references to the local variables at all. What it gets is references to two newly created objects on the heap, that contains copies of the values that the local variables had when calling the method. There is no association at all between those object and the local variables, so it's impossible to use the references to get any information at all about the actual variables.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
One major problem with that approach is that the LogLocalVariables method doesn't get references to the local variables at all.
Yes, I understand that the arguments should have at least been passed as ByRef, which would have given the called sub at least access to the same memory location. Just an oversight. But even if the args are ByRef, there's no way to get the names of the passed variables.
Thanks for your comments.
--Clay
|
|
|
|
|
If I Understand your request clearly, here is how I did this
Dim objDict
objDict = CreateObject("scripting.dictionary")
Dim Var1 As String = "ABC"
Dim Var2 As Integer = 1000
objDict.Add("var1", Var1.ToString)
objDict.Add("var2", Var2.ToString)
Dim I As Integer
For I = 1 To objDict.Count
Debug.WriteLine(objDict.Keys(I - 1) & "=" & objDict.Items(I - 1))
Next
hth
Samir R. Ibrahim
|
|
|
|
|
Hi, Samir.
Thanks for the code. You're still kind of doing what I was trying to get around, though, which is having to pass both a variable name and its value to a method. I'd like to be able to get the variable name from the variable itself, much as you can do using Reflection on a method's parameters.
Still, I appreciate your efforts. I'm amazed at the number of quick and intelligent responses I've gotten to my question. This has been my favorite site for sample code for a long time, and now I see that the forum is just as good.
Thank you all!
--Clay
|
|
|
|
|
Hi Clay,
You are very welcome.
I don't know if your question is being answered, I am still don't know how to consider a post is solved.
but any way, check this, which is being considered as a answer to a problem similar to yours. in C#
http://www.west-wind.com/Weblog/posts/256.aspx[^]
Samir R. Ibrahim
|
|
|
|
|
Hello friends,
In my MS Access, one of my form having a combobox whose row source is a query data. How can i delete all items from comboBox
Thanks and regards
Jishith
|
|
|
|
|
combobox1.DataSource=Nothing
|
|
|
|
|
ComboBox1.Datasource is not showing in my access.
In ComboBox1 properties, rowsource type is Query/table and row source is my query. its not value list
|
|
|
|
|
So your Combo box is in access not in VB.Net? Is this a VBA question or an Access question or...
perhaps you can be just slightly more specific??
|
|
|
|
|
Ya . Its in MS Access.
In properties
CmbFromDate.RowSource type = Table/Query
CmbFromDate.RowSource = "Query Created On"
The query is getting for the dates from Access Table
The combo box i used for the user to select the date.
After quitting the application the .mdb file showing huge size . The previous query data is still in the combo Box
|
|
|
|
|
|
how to shift the bit in hex?
|
|
|
|
|
A hexadecimal representation of a number is text, and you can't shift any bits in text.
Perhaps you actally mean bit shifting a number? You should specify what it is that you want to bit shift, and how. Perhaps even some background to what it is that you are trying to do, so it's possible to determine if bit shifting is actually what you should use.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Multiply or divide by a power of 2 as appropriate.
That's essentially what left and right shift do.
Of course this does not allow you to control fill bits inserted when you do a right shift.
|
|
|
|
|
Please, how to add controls to a layered window? I have create layered window by inheriting from System.Windows.Forms.Form, set it up from CreateParams using WS_EX_LAYERED
25160506848319
|
|
|
|
|
It's no different that any other window. Drag the controls onto the form and drop them...
Or did you not even try to do that??
|
|
|
|
|
Hi Alls,
I'm really need help from you all, actually i already make connection into the oracle database and it successful, i can display the item such as name , id in textbox. But my problem is the image cannot display into my picutrebox......how to do that?....the table is UMP and the column of image in byte array is PICTURE....anyone can help me?....
|
|
|
|
|
A byte array can't be displayed as an image. Create a MemoryStream from the byte array, and load the image from the stream.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Can u give me sample to do memorystream?...really2 need help
|
|
|
|