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


ADVERTISEMENT

Get A Property To Access Its Own Name And Type At Runtime Using Reflection?

Mar 12, 2010

Is there a way for a property to access its own name and type at runtime using reflection? I want to access this info without hard coding the name or index of the property in the class.

Simple Example Code:

Private ReadOnly Property MyProperyName() As String
Get
Console.WriteLine((Get Current Property Info).Type.ToString)
Console.WriteLine((Get Current Property Info).Name)

[code]....

View 1 Replies

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 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

ASP.NET - Ascx.designer 'properties' Not Showing Up In Reflection At Runtime

Jul 2, 2010

I have a very simple setup, single mycontrol.ascx with assoicated mycontrol.ascx.designer.vb and mycontrol.ascx.vb file.

mycontrol.ascx embeds a single reference to a custom control: "MyMenu":

<mM:myMenu id="myMenu1" runat="server" />

This has created a protected reference in the mycontrol.ascx.designer.vb file:

Protected WithEvents myMenu1 As Global.CustomControls.MyMenu

Now, when I breakpoint the Page_Load() event of mycontrol.ascx, and inspect the members returned from the type via:

Me.GetType().GetMembers()

I cannot any reference to myMenu1. If I look at the control with intellisence, the property is accessible:

Me.myMenu1

what I'm missing and what I need to do to access designer created properties at runtime through reflection?

View 2 Replies

Get A String Form A Table And Executed At Runtime Using Reflection?

Mar 20, 2009

Is it possible to get a string form a table and executed at runtime using reflection?(.Amount > 1000) and ((.Total * 80%) >.Amount)� Amount and Total are Decimal properties of an existing class

View 4 Replies

VS 2008 Pointer - Error32'System.Reflection.Pointer' Has No Type Parameters And So Cannot Have Type Arguments

Jul 15, 2010

I have an open source project I converted to vb.net. I solved all the errors, except for one. This is the C# line

[Code]....

View 4 Replies

Set Field Value On Value Type Using Reflection?

Mar 23, 2010

.NET I want to clone a value type's fields. How can i set a field value on a value type using reflection (or something else dynamically)?

This works for reference types but not for value types. I understand why but I don't know an alternative.

shared function clone(of t)(original as t) as t
dim cloned as t
'if class then execute parameterless constructor

[Code]....

View 2 Replies

Reflection , Need To Get A Type From A Class Name String?

Dec 30, 2011

What I wanted to do was, given the table name (as string), use reflection to instantiate the get method for specific fields (defined as properties with Get and Set methods.

Public Property VC60() As String
Get
Return _VC60

[code].....

View 2 Replies

Reflection - Getting Item Type Of A Bindinglist

May 27, 2010

I am trying to write a function that has an object parameter. That object will always be an BindingList. That BindingList will be of some unknown (at design Time) class. I think I've figured out how to get the type of the collection object, but now here the tricky part. I'm trying to create a function that can handle any type of collection and be able to return an item from that collection. I need to create a new object of that type and return it from the function. [Code]

View 1 Replies

C# - Casting System.__ComObject To Known Type Reflection

Sep 15, 2011

I am trying to create an Excel file using reflection. The reason, the application will be running on many machines some of which may or not have excel installed. I decided to embed the "Microsoft.Office.Interop.Excel.dll" and via reflection generated the excel spreadsheet. The code I am trying to resemble is:

[Code]....

View 1 Replies

Getting Static Field Values Of A Type Using Reflection?

Jun 2, 2009

I've got a set of static "enumeration" classes that I'm using to hold meaningful variable names to represent meaningless code values I receive on an input file. Here's an example of one.

Public Class ReasonCodeValue
Private Sub New()
End Sub

[code].....

View 2 Replies

Reflection - Passing Values To Constructor Of Type T?

Jun 18, 2012

I have this code to get the default constructor:

Public Function f(ByVal t As System.Type) As Object
Return t.GetConstructor(New System.Type() {}).Invoke(New Object() {})
End Function

I need to pass values to the Constructor as

Public Function f(ByVal t As System.Type) As Object
Return t.GetConstructor(New System.Type() {someInteger,someString,etc.etc}).Invoke(New Object() {})
End Function

Also I have 3 classes of Type T, with all having different parametric constructor. It's important for me to have it generic as the Classes of type T might increase in future with less or more parameters.

View 1 Replies

Search Namespace For Generic Type (Reflection)

Sep 27, 2010

I'm attempting to dynamically register entities and configurations with a context (ef4 code-only). I would normally do:

Private Shared Sub ConfigureDatabase(ByRef Builder As ContextBuilder(Of ContextExtension))
'Load configurations for each of the tables (Entity sets) in our database...
ConfigureEntity(Builder, New ContactConfig)
End Sub
Private Shared Sub ConfigureEntity(Of T)(ByRef Builder As ContextBuilder(Of ContextExtension), ByVal config As EntityConfiguration(Of T), ByVal setName As String)
'Register the entity configuration with the builder
Builder.Configurations.Add(config)
'Register the entity set name with the builder
Builder.RegisterSet(Of T)(setName)
End Sub

Where ContactConfig is a class which inherits EntityConfiguration(Of Contact) and Contact is a class which implements an interface IEntity (IEntity is common to all entities). So... I need to search a namespace (say Project.DB.Client) for all signatures that match:
EntityConfiguration(Of <Class which implements IEntity>)
How can I achieve this?

View 1 Replies

Reflection - .NET: Checking If Variable Is Of Guid (nullable) Type?

Jan 16, 2012

I'm trying to check if a variable has been defined as a nullable Guid. eg.

Dim myGuid As Nullable(Of Guid) or Dim myGuid As Guid?

It seems doing a myGuid.GetType returns the underlying type, that is type Guid, not Guid?. So testing myGuid.GetType Is GetType(Guid?) always returns False.How do I find out if myGuid is a nullable type?

Ed: I can do the following, which correctly returns True for "Guid?" and False for "Guid":

Not Nullable.GetUnderlyingType(GetType(Guid?)) Is Nothing

The problem is that I don't know how to retrieve the nullable type from the variable itself, in order to test it. I've only been able to get the underlying (non-nullable) system type.

I've written a db helper function. I pass it an object comprised of public members, representing the row data of a table. The members are the table columns.Using reflection, I loop through these public members to create an INSERT statement for a command object and populate its parameters with the values in those members. So far so good.But now there's a table which has a uniqueidentifier column which I must not populate from the row object, as it defaults to "NEWID()" (using SQL Server 2008). Instead of skipping all Guid columns, which would be easy, I only want to skip ones defined in the row data class as "Guid" (non-nullable).Basically, I'm using the Guid? (Nullable) type to indicate it's ok to populate that uniqueidentifier column with data. If it's non-nullable, that tells me to skip it because the column has a NEWID() default value.

View 3 Replies

C# - .net Type Mismatch Looking Up A Constructor By Reflection (Integer() Vs System.Int32[])?

Jan 29, 2010

I'm passing a type name and some parameters from C# code into a navigation framework written in VB. The navigation framework looks for a constructor on the type that matches the parameters passed in using Type.GetConstructor(Types()). The constructor that I'm looking for expects an array of integers Integer() in vb. But it gets an array of System.Int32. I've gone so far as to try this:

[Code]...

And the VB code still sees System.Int32 on the other end, which means that it doesn't find the constructor.

View 2 Replies

Reflection - Function Witch Return Type Is The Class Itself In Inherited Classes?

Dec 10, 2011

I have a parent class that is also a factory. For example:

Public Class Factory
Public Function clone() as Factory
' Some logic here

[code].....

View 2 Replies

Retrieve Declared Type For Value Type Variables?

Sep 22, 2009

I have an object that I know was originally declared was an enum, but I need tothe specificnum type. I'm aware of the GetType method and it appears to work correctly, but I can't figure out how to go from there to a direct type comparison For reference types, you can use Typeof(object1) Is Class1, but this doesn't seem to work for value types.

View 3 Replies

VS 2005 DrawString Changing All Painted Variables

Jun 5, 2009

Why dose this paint event change all the strings that have been painted to the current variable in Me.txtSheetLabel.Text?

Private Sub Drawing_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
For Each l As Line In Lines

[Code]....

View 4 Replies

Changing App Icon In Runtime?

Nov 2, 2009

Is it possible to change the icon of my app in runtime?

View 8 Replies

Changing Connectionstring At Runtime

Feb 18, 2010

Im writing a app using vb.net, which has multiple front ends e.g a windows service and a windows forms app. Ive got all my business logic and database stuff compiled into 1 project (producing a dll) then the different front ends as different projects calling the dll.

In the backend / dll project Im connecting to 2 databases using app.config to store the connection strings and DataSets / TableAdapters. This all works fine .... Until

When I deploy the windows app, it deploys the exe and the dll produced by the backend project. when its installed on a client PC, Im need to point the app at a different db server and therefore need to change the connectionstring, but its packaged up in the dll.

is there any way I can use a settings file within my windows app (therefore deployed with my windows app) where I can define the connectionstring, which onload gets passsed through into my dll, so the backend connects the correct database. I know how to pass standard settings through (strings etc) but the my.settings.connectionstrings seem to be readonly.

View 2 Replies

Changing Background Image During Runtime?

Dec 9, 2010

i have a program i've made a while, and one of the users wants to be able to load his own images to the background instead of the plain grey that is there now. i've searched and searched, and basically can get this working

BackgroundImage = Image.FromFile("C:UsersMeFileName.png")

i just slapped that onto a button just to get it to work as i was experimenting. but that only works for a file of that name, on my computer, in that folder. what i'm looking to do is get it so a user can browse his own directories for images and upload them as the background on the form. and be able to save the settings as well. but so far i have only seen different ways to load preset images that you can load. if it's even possible? i'd assume that you'd use the openfiledialog command, but i'm not that well versed in vb as of yet.

View 8 Replies

Changing Forms Title At Runtime?

Oct 9, 2011

I'm trying to change a forms title at runtime where it = my textbox's text. But I can't even get it to change to "test". When I try to google it, it comes up with vb6's
.caption = "test".
When I try to search it on the forum, it gives me a error message saying:
"Error 502 Bad gateway"

View 10 Replies

Changing From Menu In Form During Runtime

May 11, 2010

I have a forms application and I have multiple localizations for it. I've figured out how to add a button to a form, to change the localization and then read all the labels/etc and change them to the other language.What I would want to do instead now is click a button and it changes to the other language the current form but also the entire application so that any other windows opened while the application is open open in that other language.[code]This is the code I use when a button is clicked on a form to change it to Hindi the current form. However I want to when the button is clicked, change application to continue to run on that localization instead for the remainder of the time it is open.[code]

View 3 Replies

Changing From Menu In Form During Runtime?

Mar 8, 2011

I have a forms application and I have multiple localizations for it. I've figured out how to add a button to a form, to change the localization and then read all the labels/etc and change them to the other language.What I would want to do instead now is click a button and it changes to the other language the current form but also theentire application so that any other windows opened while the application is open open in that other language.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Present <> OriginalCulture Then

[code].....

View 7 Replies

Changing Multiple Controls During Runtime?

Mar 15, 2012

I need to change size parameter of OvalShape, I have about 100 of them, named like OvalShape1, OvalShape1...... OvalShape100

This example works for Label, but throws error for OvalShape, following is my modified code that giving error;
For Count As Integer = 1 To 100

[code].....

View 5 Replies

Changing ReportViewer BindingSource At Runtime?

Feb 17, 2012

possible Changing ReportViewer BindingSource at Runtime? in visual basic 2010

View 1 Replies

VS 2008 : Changing .txt Files At Runtime?

Jun 4, 2009

I am working on a project that uses a .txt file to store data for my arrays. Everything is working correctly i.e. I can read the file and write to the file, my issues when I exit out of runtime I get this msg

Quote:

M:My4BVB....Customer.txt

This file has been modified outside of the source editor. Do you want to reload it?I understand what it means, what I would like to know - is there a way to stop it from popping-up?

View 2 Replies

VS 2008 : Changing My.Settings Value During Runtime?

Sep 4, 2009

How do I change my code so that it will change the Value of the My.Settings.* to what TextBox1.Text is

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If RadioButton1.Checked = True Then
My.Settings.Acc1 = TextBox1.Text And My.Settings.Pass1 = TextBox2.Text

[code]....

View 2 Replies

VS 2008 Changing DGV Fonts At Runtime

May 9, 2009

I have 2 Comboboxes on my Form which also has a DataGridView. One ComboBox is populated with Font Names and the other is populated with a range of Numbers (Font Sizes). On a button click I've added this code

[Code]...

View 2 Replies







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