Reflection On Local Variables?

Feb 13, 2009

Is it possible to get the name of a local variable from a reference to the variable? For example, I can get the names and values of a calling function's parameters like this:

Dim frame As New StackFrame(1)
Dim pInfos() As ParameterInfo = frame.GetMethod().GetParameters()

Is there some way to get the same information for a calling function's local variables? This is kind of what I have in mind:

Sub SomeSub()
Dim count As Integer = 10
Dim average As Single = 45.67

[Code]......

View 4 Replies


ADVERTISEMENT

Use Reflection To Get At All Variables?

Aug 25, 2009

I have been trying to use reflection to get at all variables I have in classes. I have a bunch of classes and they all use private fields, with public properties to access these private variables.I have used the method Type.getFields() to get to all the public fields, but it doesnt return anything. It seems to completely ignore properties. If I add some test public variables as normal, it picks these up, however I was hoping to keep using the public properties in these classes.

Is there anyway to force the Type.getFields() to pick up on public properties? I see it has some binding flags, and one for getProperty, however it doesnt seem to work.

[Code]...

View 4 Replies

Reflection And Changing A Variables Type At Runtime?

May 26, 2010

I'm trying to create an object Of a specific type. I've got the following code, but it fails because it can't cast the new table object to the one that is already defined. I need table to start of an IEnumerable type so I can't declare is an object.

Public sub getTable(ByVal t as Type)
Dim table As Table(Of Object)
Dim tableType As Type = GetType(Table(Of )).MakeGenericType(t)

[code]....

is there a way of changing a variable type at runtime?

View 3 Replies

Disposal Of Local Variables

Feb 3, 2010

When you declare a local variable (inside a method), is it automatically disposed when the method ends? Or should I still use variable.Dispose() ?

View 16 Replies

List Of Local Variables

Feb 6, 2010

I am using a lot of variables in my code and like to have them listed or printed. How can I do that?

View 3 Replies

List Of Local Variables?

Feb 7, 2010

I am a Visual Basic 2008 user (under Visual Studio 2008) and I have numerous local variables in my project. How can I list them to a file or to a printer?

View 2 Replies

Local Variables Are Automatically Shared

Mar 13, 2012

I was reviewing the MSDN documentation on VB.Net's little-used Static keyword for local variables. My question is not about how Static works (I personally plan to avoid using it as it seems like it could cause grief to future programmers who don't notice the side-effects.) My question is about this statement in the docs:[code]So can anyone interpret the above statement for me in a way that makes sense? Or is this a bug in the documentation? It's been there since the VS 2005 version of the docs and is still present in the Visual Studio 11 version.

View 2 Replies

Private Fields Or Local Variables?

Apr 18, 2012

I am wondering if you have a class and in the class you have a function which executes a sqlcommand. Which would u use ? the local variable declaration or the private member command variable.Assuming that the class has a private field called m_Cmd as OracleCommand..i am using oracle db so i use oraclecommand , if sql server then it should be sqlCommand.[code]

View 3 Replies

Serialize All The Available Local Variables And Save Them?

May 13, 2010

when an exception occures, I want to save the data available on the stack and log it. how can I serialize all the available local variables and save them?

View 1 Replies

Asp.net - Server.Transfer Losing Local Variables?

Oct 26, 2011

For my application, I have a page that redirects to another page (within the same application) via Server.Transfer. I need to do this because the original page has an object that I need to access by using the Page.PreviousPage property.

Once my "destination" page has been fully loaded, a local deep clone that I made of the source page's object is suddenly released from memory once I perform a postback? Is this by design--something to do with the Server.Transfer?

Page1.aspx:
Public Structure myCustomObject
Implements ICloneable
Dim someField as String = "default value" ' Default value

[code]....

At this point, EVERYTHING works as it should. Stuff got cloned over correctly and all is well.(Let's say this is on a button click event) Debug.Write(newObj.someField) ' Output: "default value"<- This is NOT "changed value from source page" for some reason when it was working literally a few lines ago! My guess is that the Server.Transfer stops any association with the source page after the new page loads.

View 1 Replies

Creating Temp Local Variables - Bad Practice?

Jan 12, 2012

When I want to maintain code readability and keep things neat. I would create temp variables . Below is one of my functions that uses it. Is it a bad practice? I would create temp variables cost more memory ?

Private sub test(byref transac as transaction , byref txntime as string )
Dim cmd as OracleCommand = nothing
Dim Adapter As OracleDataAdapter = nothing
Dim SQLStr As New StringBuilder
[Code] .....

View 9 Replies

Server.Transfer Losing Local Variables?

May 24, 2010

I have a page that redirects to another page (within the same application) via Server.Transfer. I need to do this because the original page has an object that I need to access by using the Page.PreviousPage property

View 1 Replies

Private Shared Variables Vs Local / Namespace Performance

Jun 8, 2009

I came across a number of new Private Shared variables (of type Hashtables(Of String), initialized in the declaration) added to a partial class for a very large (DataContext-derived) class. This seems sensible to me in one sense because they never change, and making these shared variables ensures that they won't get re-initialized every time a function is called. However, these variables are only used within the scope of one function in the class, and I fear the private namespace of this DataContext-derived class is getting rather polluted, and having these sorts of things exposed at such a high level might be confusing to others reading the code in the future.

Would there be negative performance impact to making these local variables within the function where they are used, or is there some better way to handle this? Basically we are using these 3 hashtables to determine whether anything within particular subsets of properties changed (using GetModifiedMembers and then using the Overlaps function of the hashset to see if any of the modified members correspond to members we care about).

Edit: I caved and took the time to write my own test program, which confirmed that there is a cost to using local variables (which I assume applies generally to all cases -- I doubt there's any case where a shared variable would be slower unless using the shared variable requires some additional logic to do so properly): [Code]

So in this particular case, using the local variable costs about 200%. But in most cases (including my own), the time is probably negligible compared to the overall task. So I guess the question now becomes, how do people generally feel about improving code maintainability at the cost of negligible but known performance impacts?

View 3 Replies

Reading SQL Select Values Back Into Local Variables?

Apr 20, 2010

I as part of the support VB code for a larger ASP project, I need to read back the existing data from an Access database, to see if user has changed a value.

I'm reading the existing data back into a DataView using the following function:

Public Shared Function GetPolicyStatus(ByVal intPolicyID As Integer) As DataView
Dim strConString As String
Dim conMyData As OleDbConnection

[Code]....

View 4 Replies

Use Of Static Local Variables In Lazy Loading Property

Sep 19, 2011

I just recently learned about the uses of static local variables in VB.NET and wondered about it's potential use in lazy loading properties.

Consider the following example code.

Public Class Foo
Implements IFoo
End Class

[Code].....

As far as i can see, this has a few advantages over the usual implementation, primary your inability to access the variable outside of the property, as well as not having to use an additional variable.

My question to you is: Which of those is the "right" way to do it? I know that static variables have additional overhead, but is it bad enough to create, in my personal opinion, unclearer code that can be misused easier? How much performance do you lose compared to the "traditional" method? How does it matter for small classes compared to huge factories?

View 2 Replies

How To Get Data From Crystal Report Viewer Fields To Local Variables

Jan 23, 2010

I need to get data from reports fields to open others windows forms or other reports, How I can get the values of reports fields to pass to local C# o VB.net variables? After many time ... With this upgrade making click on any Textobject on the Report the ClickPage event fire and in that sub is possible to get the Textobject data. You have to upgrade to Crystal Report 2008 SP 3.6, Link below [URL]

Private Sub crViewer_ClickPage(ByVal sender As Object, ByVal e As CrystalDecisions.Windows.Forms.PageMouseEventArgs) Handles crViewer.ClickPage
If Not IsNothing(e.ObjectInfo.Text) Then
Clipboard.Clear()
Clipboard.SetText(e.ObjectInfo.Text)
Me.CallBackForm(e.ObjectInfo.Name.ToUpper.Trim, e.ObjectInfo.Text)
End If
End Sub

View 1 Replies

Local Variables In Shared Method Work Like Static Variable In C?

Aug 23, 2011

Will the list in this shared method keep its state throughout the life of the method? Or will a new list be created every time this method is called?

[Code]...

View 3 Replies

Programatically Get Hold Of The Autos/local Variables That Is Shown When Debugging?

Mar 9, 2010

Im trying to build an error-logger that loggs running values that is active in the function that caused the error. (just for fun so its not a critical problem)When going in break-mode and looking at the locals-tab and autos-tab you can see all active variables (name, type and value), it would be useful to get hold of that for logging purposes when an error occur and on some other occasions.For my example, I just want to find all local variables that are of type string and integer and store the name and value of them.

View 1 Replies

Asp.net - Local Static Variables In Timer.Tick Event (Stopping A Timer)

Jul 9, 2009

I have a timer on a page in ASP.NET.

After a certain period of time elapses, I want to disable the timer.

I want to put a static variable in the timers tick event that will track how many seconds have elapsed.

My question is, will this work?

If user X and Y are viewing the page will they both have separate local static variables?

What is the best method of shutting down an ASP.NET timer after a certain elapsed time?

View 1 Replies

Add Domain User To Local Group While Logged In As Local Account?

Sep 15, 2010

Does anyone know how this can be done? The problem is that when you run the script to add a domain user to the local group as a local user you have no permissions to query the domain. Is there a way to pass a user name and password when doing this? [code]...

View 3 Replies

VS 2008 - Take A String Of Variables With A Common Delimiter And Break It All Back Out Into Separate Variables

Dec 11, 2011

Last year (2010) I came across a FANTASTIC command that allowed me to take a string of variables with a common delimiter and break it all back out into separate variables (possibly an array) with one statement.

[Code]...

As long as the delimiter was a unique specifiable character, this one-statement command could break it out into elements. my memory and point me in the right direction.

View 2 Replies

Passing Multiple Byref Variables / Variables Fail To Change Calling Funct W/ Invoke

Sep 27, 2010

I have code, shown below, that works all except for 1 thing: The variables being passed byRef get passed, but once modified in the else section of the "if me.invokerequired" code of RecordData, the variables are never updated in the calling function. To reiterate, the calling function does not receive the updated data that is in the variables custid and amt.When debugging, I see the data change in the else section of "if me.invokerequired", but once it returns from the callback the data is missing.[code]

View 15 Replies

Define Some Global Variables Of A Class - Variables Occupy Memory?

Mar 23, 2012

I define some global variables of a class as follows:

Private Class MyClass
Private var1 as Decimal
Private list1 as List(Of string)[code].....

But I found that after this form is closed, all above variables, var1, list1, list2 still exist in memory. I thought they should be collected by gc since the form is already disposed as I confirmed.

Add: I have monitored half an hour after the form is closed. But these variables are not collected by gc. I have an automatic update procedure on the form which uses above variables.Since the above variables still hold values, the automatic update procedure is always called which causes exception. (One quick fix is to check if form.isDisposed in update procedure. But I do not think this is elegeant. Besides, these variables occupy memory.)

View 2 Replies

Memory Used In Declaring Variables Are Reclaimed By The OS When These Variables Go Out Of Scope?

Jan 7, 2010

Does the memory used in declaring variables are reclaimed by the OS when these variables go out of scope?Does the memory used be released by setting thier value to nothing? if not, then how can I force the garbage collector to run or excecute at a certain/desired time..How about in Windows Forms..How can we make sure that the memory used in initializing and showing forms be released if those forms were closed?

View 13 Replies

Multithreading: Reading/setting Variables, And Passing Variables?

Mar 8, 2011

Question 1: What is the difference between "Background Worker" and "Worker Pool" as indicated within the MSDN samples provided.

Question 2: I noticed while using, AddressOf _Function_, variables cannot be passed; what would be an efficient solution to this?

Question 3: While using multithreading is it required to invoke before setting variables, or only form properties?

Question 4: While using System.Net.Sockets is it safe/efficient to use Application.DoEvents while waiting for new data; or would be using a Do While loop be fine without DoEvents since the action would be multithreaded? Note: there can be up to 2000-3000 sockets in use at a time.

View 10 Replies

Use Variables Or Properties, And Global Or Static Variables In A Class?

Jun 9, 2012

I'm new in .NET programming.I have a class Form1 that includes Button1_Click event.Button1_Click creates a multiple Text Boxies at run time)Here is the class:

Public Class Form1
Dim shiftDown As Integer
Dim counter As Integer

[code].....

View 3 Replies

How To Use Reflection On COM Object

Sep 23, 2011

I'm wondering if there's a way to use Reflection to inspect properties of a COM object? GetType() doesn't want to return the actual type.

View 3 Replies

Using LINQ With Reflection?

Aug 4, 2010

I am trying to build a test app to test my objects. I want it to get all the classes/modules from a project/exe/dll then display the methods and allow them to be invoked. I can get a list from the running project, a dll or exe. But I am having trouble filtering.

[Code]...

View 2 Replies

.net - Using Reflection In C# To Try And Access My.Resources

Nov 10, 2011

I have inherited a large project written in a mixture of C# and VB.Net

The project involves many separate assemblies.

There are hundreds (or thousands) of resources (png files) that have been inserted into the project using the VB My.Resources functionality that I would like to access from some C# code, in a different assembly.

Microsoft has a KB article about this. It includes some sample code, but I can't get it to work (and I can't quite follow the code).

// Gets a reference to the same assembly that
// contains the type that is creating the ResourceManager.
System.Reflection.Assembly myAssembly;

[Code]......

View 1 Replies

.net - Using Reflection In C# To Try And Access Resources?

Jan 28, 2009

.net - Using reflection in C# to try and access My.Resources

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved