Search Results

Search found 785 results on 32 pages for 'gettype'.

Page 16/32 | < Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >

  • Obtaining reference to Class instance by string name - VB.NET

    - by Jeff Williams
    Is it possible using Reflection or some other method to obtain a reference to a specific class instance from the name of that class instance? For example the framework for the applications i develop heavily uses public class instances such as: Public bMyreference as MyReference = new MyReference Then throughout the application bMyReference is used by custom controls and code. One of the properties of the custom controls is the "FieldName" which references a Property in these class instances (bMyReference.MyField) as a string. What i would like to be able to do is analyze this string "bMyReference.MyField" and then refer back to the actual Instance/Property. In VB6 I would use an EVAL or something simular to convert the string to an actual object but this obviously doesn't work in VB.net What I'm picturing is something like this Dim FieldName as String = MyControl.FieldName ' sets FielName to bMyReference.MyField Dim FieldObject() as String = FieldName.Split(".") ' Split into the Object / Property Dim myInstance as Object = ......... ' Obtain a reference to the Instance and set as myInstance Dim myProperty = myInstance.GetType().GetProperty(FieldObject(1))

    Read the article

  • notications pop up in user side

    - by user2931015
    i try to show notification as a pop up. like when admin login and through his account he send notification to user i add this html in admin form like this.. <asp:Button ID="notic" runat="server" Text="Send" onclick="Button1_Click" /> <br /> <input class="add_message" type="text" value="type your message" name="add_message"></input> <input type="button" value="add message" onclick="sNotify.addToQueue($('.add_message').attr('value'))"/> Then when admin click on button then notification send to users account like when any user login then he/she able to see pop ups in user form I call this java script in page load like this .. ClientScript.RegisterStartupScript(GetType(), "Javascript", "javascript:sNotify.addToQueue($('.add_message').attr('value'))();", true); it works like when i login as a admin and click on button then notification in his own page .. but i want to show this notifications in user form. so how to solve it?

    Read the article

  • Reflection PropertyInfo GetValue call errors out for Collection<> type property.

    - by Vinit Sankhe
    Hey Guys, I have a propertyInfo object and I try to do a GetValue using it. object source = mysourceObject //This object has a property "Prop1" of type Collection<>. var propInfo = source.GetType().GetProperty("Prop1"); var propValue = prop.GetValue(this, null); // do whatever with propValue // ... I get error at the GetValue() call as "Value cannot be null.\r\nParameter name: source" "Prop1" is a plain property declared as Collection. prop.PropertyType = {Name = "Collection1" FullName = "System.Collections.ObjectModel.Collection1[[Application1.DummyClass, Application1, Version=1.5.5.5834, Culture=neutral, PublicKeyToken=628b2ce865838339]]"} System.Type {System.RuntimeType}

    Read the article

  • How to invoke a method with a generic return type using reflection

    - by Andre Luus
    Hi there! I'm trying to invoke a method with reflection that has a generic return type, like this: public class SomeClass<T> { public List<T> GetStuff(); } I get an instance of SomeClass with a call to a Repository's GetClass<T> generic method. MethodInfo lGetSomeClassMethodInfo = typeof(IRepository) .GetMethod("GetClass") .MakeGenericMethod(typeof(SomeClass<>); object lSomeClassInstance = lGetSomeClassMethodInfo.Invoke( lRepositoryInstance, null); After that, I this is where I try to invoke the GetStuff method: typeof(SomeClass<>).GetMethod("GetStuff").Invoke(lSomeClassInstance, null) I get an exception about the fact that the method has generic arguments. However, I can't use MakeGenericMethod to resolve the return type. Also, if instead of typeof(SomeClass<>) I use lSomeClassInstance.GetType() (which should have resolved types) GetMethod("GetStuff") returns null! UPDATE I have found the solution and will post the answer shortly.

    Read the article

  • Raise an event when Property Changed using Reflection

    - by Dante
    I am working in C# and I have an object which I can only access using Reflection (for some personal reasons). So, when I need to set some value to one of its properties I do as below: System.Reflection.PropertyInfo property = this.Parent.GetType().GetProperty("SomeProperty"); object someValue = new object(); // Just for example property.SetValue(this.Parent, someValue, null); And, to get its value I use the method GetValue. My question is: Is there a way to fire an event when the property changes using Reflection? Thank you in advance.

    Read the article

  • Dynamically find the parameter to be passed as <T> to a generic method

    - by Codex
    A generic method is defined as follows: private static T GetComparisonObject<T>(ComparisonAttribute attribute, object objectToParse) { // Perform a some action return (T)resultObject; } The method is invoked as follows: var srcObjectToCompare = GetComparisonObject<DynamicType>(attributeToCompare, srcObject); The type for which the method needs to be invoked is configured in the config file as: <add attributename ="Count" attributetype ="MemberInformation" attributeparam ="Count" type="System.Int32" comparertype="ditCreditEMGTestAutomationDifferenceEngine.Comparers.TypeComparer, ditCreditEMGTestAutomationDifferenceEngine.dll" /> The token that is passed in < for the generic methods has to be the type for which the method is being invoked. From the type key configuration in the XML, an instance of Type represnting the type can be created{i.e. Type.GetType("System.Int32")}, but how can the Type Definition be generated which can then be passed to the the Generic method? Hope am not missing something elementary here!! :-O Thanks in advance.

    Read the article

  • JPA One to Many using JoinTable Error

    - by user553015
    I am trying to model 1:N (Person & Address) relationship using a junction table (Person_Address). 1.Person (personId PK) 2.Address (addressId PK) 3.PersonAddress ( personId, addressId composite PK, personId FK references Person, addressid FK references Address ) @Entity public class Person { @OneToMany @JoinTable( name="PersonAddress", joinColumns = @JoinColumn( name="personId"), inverseJoinColumns = @JoinColumn( name="addressId") ) public Set<Address> getAddresses() {...} ... } I encounter following error. Not able to find any solution. Caused by: org.hibernate.MappingException: Could not determine type for: com.realestate.details.Address, at table: Person, for columns: [org.hibernate.mapping.Column(address)] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:269) at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253) at org.hibernate.mapping.Property.isValid(Property.java:185) at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:440) at org.hibernate.mapping.RootClass.validate(RootClass.java:192) at org.hibernate.cfg.Configuration.validate(Configuration.java:1108) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1293)

    Read the article

  • c# Reflection - Find the Generic Type of a Collection

    - by Andy Clarke
    Hi, I'm reflecting a property 'Blah' its Type is ICollection public ICollection<string> Blah { get; set; } private void button1_Click(object sender, RoutedEventArgs e) { var pi = GetType().GetProperty("Blah"); MessageBox.Show(pi.PropertyType.ToString()); } This gives me (as you'd expect!) ICollection<string> ... But really I want to get the collection type i.e. ICollection (rather than ICollection<string>) - does anyone know how i'd do this please?

    Read the article

  • Help System.Web.Compilation.BuildManager find a type in a non-referenced assembly

    - by asbjornu
    I'm trying to write a plug-in system where assemblies can be dropped in a folder that ASP.NET has no knowledge about. This plug-in system works fine for ASP.NET MVC based assemblies, but for old-school WebForm assemblies (where the .aspx files Inherits the System.Web.UI.Page derived classes) System.Web.Compilation.BuildManager is responsible for compiling the .aspx file into a dynamic assembly. My problem is that the BuildManager knows nothing about the assemblies within my plug-in folder and it seems to be absolutely nothing I can do to help it. If I do: BuildManager.GetType("Type.Defined.In.Plugin.Assembly", true, true) it throws. If I first get a reference to the Type and then try: var instance = BuildManager.CreateInstanceFromVirtualPath(path, type); it still throws, even though I've now passed in the specific type it needs to compile the .aspx file. Is there anything I can do to help BuildManager find the types it needs to compile the .aspx file?

    Read the article

  • Activator.CreateInstance with type name as string and including parameters

    - by Kelly
    I am working in .Net 3.5, looking at all the various constructors for Activator.CreateInstance. I want to create an instance of a class, calling a particular constructor. I do not have the class type, only its name. I have the following, which works, but actually winds up calling the parameterless constructor first, then the one I want. This is not a terribly big deal, but the parameterless constructor calls a rather busy base constructor, and the constructor I want to call does, too. In other words, given a type, calling CreateInstance with parameters is easy (only the last two lines below), but given only a type name, is there a better way than this? ObjectHandle oh = Activator.CreateInstance( "MyDllName", "MyNS." + "MyClassName" ); object o = oh.Unwrap( ); object newObj = Activator.CreateInstance( o.GetType( ), new object[] { param1 } ); return ( IMyDesiredObject )newObject; Thanks!

    Read the article

  • How do I get client ip address using TcpClient?

    - by brendan
    I am using TcpClient to listen on a port for requests. When the requests come in from the client I want to know the client ip making the request. I've tried: Console.WriteLine(tcpClient.Client.RemoteEndPoint.ToString()); Console.WriteLine(tcpClient.Client.LocalEndPoint.ToString()); var networkStream = tcpClient.GetStream(); var pi = networkStream.GetType().GetProperty("Socket", BindingFlags.NonPublic | BindingFlags.Instance); var socketIp = ((Socket)pi.GetValue(networkStream, null)).RemoteEndPoint.ToString(); Console.WriteLine(socketIp); All of these addresses output 10.x.x.x addresses which are private addresses and are clearly not the address of the clients off my network making the requests. What can I do to get the public ip of the clients making the requests?

    Read the article

  • Using a Type object to create a generic

    - by Richard Neil Ilagan
    Hello all! I'm trying to create an instance of a generic class using a Type object. Basically, I'll have a collection of objects of varying types at runtime, and since there's no way for sure to know what types they exactly will be, I'm thinking that I'll have to use Reflection. I was working on something like: Type elType = Type.GetType(obj); Type genType = typeof(GenericType<>).MakeGenericType(elType); object obj = Activator.CreateInstance(genType); Which is well and good. ^_^ The problem is, I'd like to access a method of my GenericType< instance, which I can't because it's typed as an object class. I can't find a way to cast it obj into the specific GenericType<, because that was the problem in the first place (i.e., I just can't put in something like:) ((GenericType<elType>)obj).MyMethod(); How should one go about tackling this problem? Many thanks! ^_^

    Read the article

  • .NET - Retrieve attribute from controller context?

    - by ropstah
    I have a controller insert action: <AcceptVerbs(HttpVerbs.Post)> _ Function InsertObject(<Bind(Exclude:="Id")> <ModelBinder(GetType(CustomModelBinder))> ByVal object As SomeObject) As ActionResult End Function And i have a CustomModelBinder class with a BindModel implementation: Public Function BindModel( _ ByVal controllerContext As System.Web.Mvc.ControllerContext, _ ByVal bindingContext As System.Web.Mvc.ModelBindingContext) As Object Implements System.Web.Mvc.IModelBinder.BindModel For Each s In HttpContext.Current.Request.Form.Keys HttpContext.Current.Response.Write(s & ": " & HttpContext.Current.Request.Form(s) & "<br />") Next HttpContext.Current.Response.End() End Function As you can see I have a controllerContext and a ModelBindingContext available. How do I get the: <Bind(Exclude:="Id")> part inside the BindModel implementation?

    Read the article

  • addDoubleClickHandler to a FixedWidthGrid !!

    - by MArio
    Hello so I got a FixedWidthGrid table which is made from a pagingtable FixedWidthGrid dataTable = x.getDataTable(); I could add alot of handlers to the dataTables rows like selected or sort policies. but I cant add a double click handler ... anyway idea's ?! thank you I do have a class which I made to try to add a double click hander but it didn't work. class: public class DoubleClickTable extends FixedWidthGrid implements HasDoubleClickHandlers { public DoubleClickTable() { super(); } public HandlerRegistration addDoubleClickHandler(DoubleClickHandler handler) { return addDomHandler(handler, DoubleClickEvent.getType()); } } Thank you so much for your help.

    Read the article

  • LuaInterface - how to register overloaded methods?

    - by JeffreySadeli
    Hello world! I'm trying to integrate Lua to my C# app when I hit a little snag. I was hoping someone with more expertise could help point me to the right direction. Let's say I have the following C# methods: public void MyMethod(int foo) { ... } public void MyMethod(int foo, int bar) { ... } I would like to register it to my Lua script environment so that I can do something like this: -- call method with one param MyMethod(123) -- call method with two params MyMethod(123, 456) I tried RegisterFunction("MyMethod", this, this.GetType().GetMethod("MyMethod")) but it reasonably complains about ambiguous match. Any ideas?

    Read the article

  • Auto injecting logger with guice

    - by koss
    With reference to Guice's custom injections article, its TypeListener performs a check for InjectLogger.class annotation - which can be optional. Removing that check will inject to all Logger.class types. class Log4JTypeListener implements TypeListener { public <T> void hear(TypeLiteral<T> typeLiteral, TypeEncounter<T> typeEncounter) { for (Field field : typeLiteral.getRawType().getDeclaredFields()) { if (field.getType() == Logger.class && field.isAnnotationPresent(InjectLogger.class)) { typeEncounter.register(new Log4JMembersInjector<T>(field)); } } } } I'm tempted to remove "&& field.isAnnotationPresent(InjectLogger.class)" from the listener. If we're using Guice to inject all instances of our Logger, is there any reason not to do it automatically (without need to annotate)?

    Read the article

  • Getting fields of a class through reflection

    - by Water Cooler v2
    I've done it a gazillion times in the past and successfully so. This time, I'm suffering from lapses of amnesia. So, I am just trying to get the fields on an object. It is an embarrassingly simple and stupid piece of code that I am writing in a test solution before I do something really useful in production code. Strangely, the GetFieldsOf method reports a zero length array on the "Amazing" class. Help. class Amazing { private NameValueCollection _nvc; protected NameValueCollection _myDict; } private static FieldInfo[] GetFieldsOf(string className, string nameSpace = "SomeReflection") { Type t; return (t = Assembly.GetExecutingAssembly().GetType( string.Format("{0}.{1}", nameSpace, className) )) == null ? null : t.GetFields(); }

    Read the article

  • Filter records based on Date Range + ASP.NET + Regex + Javascript

    - by ASIF
    Hi I need to filter data based on a date range. My table has a field Process date. I need to filter the records and display those in the range FromDate to ToDate. How do I write a function in VB.NET which can help me filter the data. Protected Shared Function ObjectInRange(ByRef obj As Object, ByVal str1 As String, ByVal str2 As String) As Boolean Dim inRange = False For Each prop As PropertyInfo In obj.GetType().GetProperties() Dim propVal = prop.GetValue(obj, Nothing) If propVal Is Nothing Then Continue For End If Dim propValString = Convert.ToString(propVal) If Regex....WHAT GOES HERE? Then inRange = True Exit For End If Next Return inRange End Function Am I on the right track??

    Read the article

  • Identifying all types with some attribute

    - by Tom W
    Hello SO; I have an issue with .Net reflection. The concept is fairly new to me and I'm exploring it with some test cases to see what works and what doesn't. I'm constructing an example wherein I populate a set of menus dynamically by scanning through my Types' attributes. Basically, I want to find every type in my main namespace that declares 'SomeAttribute' (doesn't matter what it is, it doesn't have any members at present). What I've done is: For Each itemtype As Type In Reflection.Assembly.GetExecutingAssembly().GetTypes If itemtype.IsDefined(Type.GetType("SomeAttribute"), False) Then 'do something with the type End If Next This crashes the application on startup - the first type it identifies is MyApplication which is fairly obviously not what I want. Is there a right and proper way to look for all the 'real' 'sensible' types - i.e. classes that I've defined - within the current assembly?

    Read the article

  • Get property name from class

    - by Polaris
    I need property name in my app and I use next code to get it string PropertyName =SomeClass.GetType().GetProperty("Category").Name; But I think that is bad idea. Because I use web service classes and I dont know when property names can be changed. This code give me exception only in runtime. But if I write something like this SomeClassInstance.Property.GetProperyName i get exception in moment of compilation and repair this problem. Is it possible to get property name dynamically?

    Read the article

  • Page submission problem with safari

    - by jestges
    Hi I'm working with a simple application in asp.net (c#). In my page1 I've a load button in that load button click event I try to open another window. In my second window I've a button If I click on that button my intension is to reload parent page (i.e page1). So I try to use this script scriptString = " window.opener.location.href = myparentpage; window.opener.document.getElementById('ValidationSummary1').style.display='none';"; Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "script", scriptString); But it is not working in Safari. Is there any solution?

    Read the article

  • GetdataBy date doesn't work Why?

    - by vp789
    I am trying to pull the data by date in vb.net. It is not throwing the error nor giving any result. Whereas It shows the results in table adapter configuration wizard when I try through query builder. I am using date time picker in the form. But I have formatted the date in the database as date.I am puzzled. Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click Try Dim dt As Date = CDate(tspTextDate.Text) Me.Bank_transactionsTableAdapter.GetDataByDate(dt) 'Catch ex As Exception Catch ex As FormatException MessageBox.Show("date is wrong", "Entry Error") Catch ex As SqlException MessageBox.Show("SQL Server error#" & ex.Number _ & ":" & ex.Message, ex.GetType.ToString) End Try End Sub rows of data BT102 4/5/2010 BKS 200.00 1200.00 1400.00 BT103 4/5/2010 BKS 200.00 1400.00 1600.00 BT105 4/6/2010 BKS 200.00 1800.00 1800.00

    Read the article

  • form submit not working in firefox but works fine in IE

    - by jestges
    Hi, I want to submit my parent page when I click on submit button of the child page. In my child page I've written my code as string scriptString = "<script language=JavaScript> window.opener.document.forms(0).submit(); </script>"; // ASP.NET 2.0 if (!Page.ClientScript.IsClientScriptBlockRegistered(scriptString)) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "script", scriptString); } it is working fine in IE but not working in Firefox. What could be the alternate method for this? Thank in advance

    Read the article

  • Dynamically Loading a DLL

    - by TooFat
    I am trying to simply load a dll written in C# at run time and create an instance of a class in that dll. Assembly a = Assembly.LoadFrom(@"C:\Development\DaDll.dll"); Type type = a.GetType("FileReleaseHandler", true); TestInterface.INeeedHelp handler = Activator.CreateInstance(type) as TestInterface.INeeedHelp; No errors are thrown, and if I step through the code I can walk though the FileReleaseHandler Class as it executes the constructor but the value of handler is always null. What am I missing here? or even is there a better way I should be going about this?

    Read the article

  • Using MicrosoftReportViewer with Web Forms programmatically

    - by user283897
    Hi, I'm repeating my question because the prior one under this topic was lost. Could you please help me? I want to use MicrosoftReportViewer for Web Forms so that the DataSource be set programmatically. There is some sample code on the Internet for Windows Forms but I haven't found anything for Web Forms. For example, here is some code I've tried to use. It gives no errors but nothing is displayed. How should I modify the code to display a table in the ReportViewer? Imports System.Data Imports Microsoft.Reporting.WebForms Partial Class TestReportViewer Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load CreateReport() End Sub Sub CreateReport() Dim dt As DataTable Dim rpt As ReportDataSource dt = New DataTable("Sample") With dt .Columns.Add("No", GetType(Integer)) .Columns.Add("Name") .Rows.Add(1, "A1") .Rows.Add(2, "A2") .Rows.Add(3, "A3") .Rows.Add(4, "A4") .AcceptChanges() End With rpt = New ReportDataSource rpt.DataMember = "Sample" rpt.Value = dt rpt.Name = "test" With ReportViewer1 .LocalReport.DataSources.Add(rpt) .DataBind() .LocalReport.Refresh() End With End Sub End Class

    Read the article

< Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >