Search Results

Search found 1787 results on 72 pages for 'reflection emit'.

Page 4/72 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • How to call a generic method through reflection

    - by milan
    Hi, is it possible to call with reflection a method with "explict type argument" <S> definition e.g. oObject.Cast<S>() ? where is: IList <P> oObject = new List <P>(); I tried with oObject.getType().InvokeMember( "Cast", BindingFlags.InvokeMethod, null, oObject, null) but it does not work, does anyone know why?

    Read the article

  • .net - invoke methods from classes from a certain namespace via reflection

    - by Kristian Hildebrandt
    SPL and PHP allows you to create objects on the fly from classes, that fulfill certain conditions, such as implementing certain interfaces and stuff like that. However, I would like to do something similar in c# and automatically create objects from all classes in a namespace and invoke a particular method from those classes that implement a certain interface. My experience developing desktop apps is very limited. I am not quite sure if I should use delegates to archive this or if reflection is really the way to go.

    Read the article

  • [NET] Reflection

    - by pipiscrew
    using : Dim a As [Assembly] = [Assembly].LoadFile("C:\test.exe") Dim testTP As Type testTP = a.GetType("SplashScreen", True, True) obj1 = Activator.CreateInstance(withoutFOR) obj1.show() my prog made reflection to test.exe SplashScreen loaded , also obj1 filled when SplashScreen disposed - MainForm loaded the obj1 isnothing! when try to access obj1 VS say : AccessibilityObject = {"Cannot access a disposed object. Object name: 'SplashScreen'."} I want always obj1 filled from the active form!! how????

    Read the article

  • instantiate object with reflection using constructor arguments

    - by justin
    I'm trying to figure out how to instantiate a case class object with reflection. Is there any support for this? The closest I've come is looking at scala.reflect.Invocation, but this seems more for executing methods that are a part of an object. case class MyClass(id:Long, name:String) def instantiate[T](className:String)(args:Any*) : T = { //your code here } Is close to the API I'm looking for. Any help would be appreciated.

    Read the article

  • Detect if a method was overridden using Reflection (C#)

    - by Andrey
    Say I have a base class TestBase where I define a vistual method TestMe() class TestBase { public virtual bool TestMe() { } } Now I inherit this class: class Test1 : TestBase { public override bool TestMe() {} } Now, using Reflection, I need to find if the method TestMe has been overriden in child class - is it possible? What I need it for - I am writing a designer visualizer for type "object" to show the whole hierarchy of inheritance and also show which virtual methods were overridden at which level.

    Read the article

  • Use reflection to get the value of a property by name in a class instance

    - by TheMoot
    Lets say I have class Person { public Person(int age, string name) { Age = age; Name = name; } public int Age{get;set} public string Name{get;set} } and I would like to create a method that accepts a string that contains either "age" or "name" and returns an object with the value of that property. Like the following pseudo code: public object GetVal(string propName) { return <propName>.value; } How can I do this using reflection? I am coding using asp.net 3.5, c# 3.5

    Read the article

  • Is there a good reflection library available for Scala?

    - by Erik Engbrecht
    I'm working on a library that needs reflection, and needs Scala-specific information as opposed to what is available via the standard Java reflection API. Right now I'm using the undocumented code in scalap (the Scala equivalent to javap) and trying to associate the data it provides with Java reflection objects so that I can call methods and such (scalap just parses class files). I found this but there's nothing there... https://github.com/dubochet/scala-reflection ...and I've searched the Scala SVN repo for traces of it and failed to find it there, either (but it could be I just missed it). Does anyone know of a Scala reflection library that provides information similar to what scalap provides but also allows you to call methods, access fields, etc like the Java reflection library?

    Read the article

  • C# Using Reflection to copy base class properties

    - by David Liddle
    I would like to update all properties from MyObject to another using Reflection. The problem I am coming into is that the particular object is inherited from a base class and those base class property values are not updated. The below code copies over top level property values. public void Update(MyObject o) { MyObject copyObject = ... FieldInfo[] myObjectFields = o.GetType().GetFields( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); foreach (FieldInfo fi in myObjectFields) { fi.SetValue(copyObject, fi.GetValue(o)); } } I was looking to see if there were any more BindingFlags attributes I could use to help but to no avail.

    Read the article

  • .NET How can i set field value on value type using reflection

    - by soccerazy
    .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 if getType(t).isClass then cloned = reflector.construct(of t)() dim public_fields = original.getType.getFields() for each field in public_fields dim original_value = field.getValue(original) 'this won't work for value type, but it does work for reference type ??? field.setValue(cloned, original_value) next return cloned end function

    Read the article

  • C# - setting a property by reflection with a string value

    - by David Hodgson
    Hi, I'd like to set a property of an object through reflection, with a value of type string. So, for instance, suppose I have a Ship class, with a property of Latitude, which is a double. Here's what I'd like to do: Ship ship = new Ship(); string value = "5.5"; PropertyInfo propertyInfo = ship.GetType().GetProperty("Latitude"); propertyInfo.SetValue(ship, value, null); As is, this throws an Argument exception (Object of type 'System.String' cannot be converted to type 'System.Double'). How can I convert value to the proper type, based on propertyInfo?

    Read the article

  • Accessing the constructor by using Reflection

    - by Md. Rashim Uddin
    Assume the class is public and and the constructor is internal like as Public class A { private string text; internal A(string submittedText); public string StrText { get; } } In this case how could I Access the constructor by using Reflection. What I have done so far Type[] pTypes = new Type[1]; pTypes[0] = typeof(object); object[] argList = new object[1]; argList[0] = "Some Text"; ConstructorInfo c = typeof(A).GetConstructor (BindingFlags.NonPublic | BindingFlags.Instance, null, pTypes, null); A foo = (A)c.Invoke(BindingFlags.NonPublic, null, argList, Application.CurrentCulture); But it shows an error. Any Suggestions

    Read the article

  • Need to call COM component using reflection in .NET

    - by Usman
    I need to determine the COM component(unmanaged code) type and invoke the exposed interface's methods using reflection in C# at runtime. First What member of "Type" tells that type is COM component and we can take CLSID at runtime? Is Type.COMObject? I need to call methods of exposed interfaces as they called in unmanaged code using CoCreateInstance by passing CLSID and REFID ... I am using InvokeMember but it returns null or 0 as out parameter. How to pass out parameter in this case.? Is there any need to pass out parameter? As all my COM unmanaged code suppose to take last parameter as an OUT parameter and after executing it puts the result into that out param. But I've converted all my unmanaged COM code to .NET managed assemblies using tlbimp.exe.

    Read the article

  • Setting a value through reflection is not working.

    - by Scott Chamberlain
    I am trying to set a value through reflection. I created this little test program struct headerIndexes { public int AccountNum{ get; set; } public int other { get; set; } public int items { get; set; } } static void Main(string[] args) { headerIndexes headers = new headerIndexes(); headers.AccountNum = 1; Console.WriteLine("Old val: {0}", headers.AccountNum); foreach (var s in headers.GetType().GetProperties()) { if (s.Name == "AccountNum") s.SetValue(headers, 99, null); } Console.WriteLine("New val: {0}", headers.AccountNum); Console.ReadKey(); } Steping thorugh the program i see it correctly does the command s.SetValue(headers, 99, null); however the value of headers.AccountNum stays at 1 when setValue is run. Am I missing a obvious step?

    Read the article

  • Reflection, invoke

    - by Alaa'
    Hi, I have a dll file, and i took an object from it and called the functions inside this dll by the object, like this way: Command testClass = (Command)assembly.CreateInstance(creatObject); testClass.Execute(); anyway, the i used reflection from some reason. so i need to use invoke function & set values for variables, then calling the basic function Execute. Before: i wrote the following: object returnValue = objectType.GetMethod("setValues").Invoke(classObject, arguments); testClass.Execute(); but it wasnt useful for me. i used the following: object returnValue = objectType.GetMethod("setValues").Invoke(classObject, arguments); object returnValue1 = objectType.GetMethod("Execute").Invoke(classObject, null); i just want to ask if this is right, to calling the execute in this way, and by the way it works! Thank you.

    Read the article

  • Using Visual sudio .ncb file for reflection.

    - by Rushi
    I am developing visual game level editor in c++. For this I want reflection(RTTI) mechanism to know class attributes at runtime. I am currently using PDB files for this.But using PDB I couldn't retrieve actual code line for extra information in commented format which is given for that attribute. Visual studio uses NCB files for intelligence. So will it be better idea to use NCB instead PDB? If yes,How to retrieve information from NCB files? Is there any SDK like DIA SDK?

    Read the article

  • C# Reflection - Casting private Object field

    - by alhazen
    I have the following classes: public class MyEventArgs : EventArgs { public object State; public MyEventArgs (object state) { this.State = state; } } public class MyClass { // ... public List<string> ErrorMessages { get { return errorMessages; } } } When I raise my event, I set 'State' of the MyEventArgs object to an object of type MyClass. I'm trying to retrieve ErrorMessages by reflection in my event handler: public static void OnEventEnded(object sender, EventArgs args) { Type type = args.GetType(); FieldInfo stateInfo = type.GetField("State"); PropertyInfo errorMessagesInfo = stateInfo.FieldType.GetProperty("ErrorMessages"); object errorMessages = errorMessagesInfo.GetValue(null, null); } But this returns errorMessagesInfo as null (even though stateInfo is not null). Is it possible to retrieve ErrorMessages ? Thank you

    Read the article

  • How to access a field's value via reflection (Scala 2.8)

    - by soc
    Consider the following code: class Foo(var name: String = "bar") Now i try to get the value and the correct type of it via reflection: val foo = new Foo val field = foo.getDeclaredField("name") field.setAccessible(true) //This is where it doesn't work val value = field.get(????) I tried things like field.get(foo), but that just returns an java.lang.Object but no String. Basically I need the correct type, because I want to invoke a method on it (e. g. toCharArray). What is the suggested way to do that?

    Read the article

  • .Net Reflection - Calling unexisting methods

    - by Joaozinho das Couves
    Lets say i call method M1 on class A using reflection. The method does not exist. Is there any way to put a handler on class A that says, "someone is trying to execute method M1"? Or Is it possible to add a method dinamically to a class? I want to add a method M1...Mn that always does MyStaticClass.DoAction("M1...Mn"); Something like: string methodName = "M1". A.AddMethod(methodname,x = MyStaticClass.DoAction(x)); Thanks

    Read the article

  • Resolving type parameter values passed to ancester type using reflection

    - by Tom Tucker
    I've asked a similar question before, but this one is much more challenging. How do I find a value of a specific type parameter that is passed to an ancestor class or an interface implemented by one of its ancestor classes using reflection? I basically need to write a method that looks like this. // Return the value of the type parameter at the index passed to the parameterizedClass from the clazz. Object getParameterValue(Class<?> clazz, Class<?> parameterizedClass, int index) For the example below, getParameterValue(MyClass.class, Map.class, 1) would return String.class public class Foo<K, V> implements Map<K, V>{ } public class Bar<V> extends Foo<Integer, V> { } public class MyClass extends Bar<String> { } Thanks!

    Read the article

  • Silverlight: Use reflection to get the BindingExpression (and value) for controls having a ContentPr

    - by sfx
    Hello, I need to use reflection to get the binding value in a control that is a DataGridTemplateColumn (e.g HyperLinkButton). Does anyone know how I might do this? It seems simple enough to do this with a TextBlock because it has a “TextProperty” dependency property, but I can’t seem to get a binding expression from a control that does not have an immediate “TextProperty”. Here is the code I’m using to acquire the binding expression for a TextBlock: FrameworkElement fe = (FrameworkElement)dependencyObj; FieldInfo fi = fe.GetType().GetField("TextProperty"); BindingExpression bindingExpression = fe.GetBindingExpression((DependencyProperty)fi.GetValue(null)) However, the following code never works for a dependency object that is a HyperLinkButton: FieldInfo fi = fe.GetType().GetField("ContentProperty"); Does anyone know how I might be able to get the BindingExpression (and binding value) for the content of a HyperLinkButton? Cheers, sfx

    Read the article

  • Using Reflection Invoke static generic method passing a Lamba as parameter

    - by Nikos Baxevanis
    Is it possible to write the following code via Reflection? var fake = A.Fake<Foo>( o => o.WithArgumentsForConstructor(new[] { "Hello" })); Where o is: Action<IFakeOptionsBuilder<T>> Where WithArgumentsForConstructor is: IFakeOptionsBuilder<T> WithArgumentsForConstructor(IEnumerable<object> argumentsForConstructor); The Foo class is: class Foo { public Foo(string s) { } } What I did was: object fake = typeof(A) .GetMethod("Fake", new Type[] { }) .MakeGenericMethod(new[] { this.targetType }) .Invoke(null, /* Here I need to pass the lambda. */);

    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

  • Java reflection for generics

    - by Vijay Bhore
    I am using Java Reflection to expose methods in custom eclipse tool. I am writing method getReturnType which accepts java.lang.reflect.Method as input and returns object of Class private static Class<?> getReturnType(Method method) { Type type = ((ParameterizedType)method.getGenericReturnType()).getRawType(); return getClass(type); } This code compiles well but at runtime i get the below exception while casting Type to ParameterizedType. java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType Please suggest. Thanks!

    Read the article

  • C#: reflection alternative for switch on enum in order to select namespace/class

    - by Am
    Hi, I have an interface named IHarvester. There are 3 implementations of that interface, each under their own namespace: Google Yahoo Bing A HarvesterManager uses the given harvester. It knows the interface and all 3 implementations. I want some way of letting the class user say in which harvester it wants to use. And in the code select that implementation, without a switch-case implementation. Can reflection save my day? Here is the code bits: // repeat for each harvester namespace Harvester.Google { public abstract class Fetcher : BaseHarvester, IInfoHarvester {...} } public enum HarvestingSource { Google, Yahoo, Bing, } class HarvesterManager { public HarvestingSource PreferedSource {get;set;} public HarvestSomthing() { switch (PreferedSource) .... // awful... } } Thanks.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >