Search Results

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

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

  • Java: Reflection against casting when you know superclass

    - by Ema
    I don't know exactly how to define my doubt so please be patient if the question has already been asked. Let's say I have to dinamically instantiate an object. This object will surely be instance of a subclass of a known, immutable class A. I can obtain dinamically the specific implementation class. Would it be better to use reflection exactly as if I didn't know anything about the target class, or would it be preferrable/possible to do something like: A obj = (Class.forName("com.package.Sub-A")) new A(); where Sub-A extends A ? The purpose would be to avoid reflection overhead times... Thank you in advance.

    Read the article

  • NoSuchMethodException while using JAVA Reflection

    - by Appps
    Hi I'm trying to use reflection to invoke a method and update the setter value of that method. But I'm getting NoSuchMethodException while ivoking that method. com.test.Test.setAddress1(java.lang.Double) .But I've this method defined in my Class. Is the problem with my code. Can someone please help me? Thanks in advance. I've my code below. Class[] doubleArrayParamTypes = new Class[ 1 ]; doubleArrayParamTypes[ 0 ] = Double.class; Class class=Class.forName( "com.test.Test"); Object voObject = class.newInstance(); String data="TestData"; performMapping(class,"setAddress1",doubleArrayParamTypes ,voObject,data); /* Reflection to set the data */ private void performMapping(Class class,String methodName,Class[] clazz,Object voObject,Object data) { class.getMethod( "set" + methodName, clazz ).invoke( voObject, data ); }

    Read the article

  • C#: Basic Reflection Class

    - by Mike
    I'm trying to find a basic reflection abstract class that will generate basic information about a class. I have a template of how I would like it to work: class ThreeList<string,Type,T> { string Name {get; set;} Type Type {get; set;} T Value {get; set;} } abstract class Reflect<T> { List<ThreeList<string, Type, T> list; ReturnType MethodName() { foreach (System.Reflection.PropertyInfo prop in this.GetType().GetProperties()) { object value = prop.GetValue(this, new object[] { }); list.Add(prop.Name, prop.DeclaringType, value); } } } I'd like it to be infinitely deep, recursively calling Reflect. Something like this has to exist. I'm not really opposed to coding it myself, I just don't want to go through the hassle if its already been done.

    Read the article

  • Retrieve a static variable using its name dynamically using reflection

    - by user2538438
    How to retrieve a static variable using its name dynamically using Java reflection? If I have class containing some variables: public class myClass { string [][] cfg1= {{"01"},{"02"},{"81"},{"82"}}; string [][]cfg2= {{"c01"},{"c02"},{"c81"},{"c82"}}; string [][] cfg3= {{"d01"},{"d02"},{"d81"}{"d82"}}; int cfg11 = 5; int cfg22 = 10; int cfg33 = 15; } And in another class I want variable name is input from user: class test { Scanner in = new Scanner(System.in); String userInput = in.nextLine(); // get variable from class myClass that has the same name as userInput System.out.println("variable name " + // correct variable from class) } Using reflection. Any help please?

    Read the article

  • Define a method in base class that returns the name of itself (using reflection) - subclasses inheri

    - by Khnle
    In C#, using reflection, is it possible to define method in the base class that returns its own name (in the form of a string) and have subclasses inherit this behavior in a polymorphic way? For example: public class Base { public string getClassName() { //using reflection, but I don't want to have to type the word "Base" here. //in other words, DO NOT WANT get { return typeof(Base).FullName; } return className; //which is the string "Base" } } public class Subclass : Base { //inherits getClassName(), do not want to override } Subclass subclass = new Subclass(); string className = subclass.getClassName(); //className should be assigned "Subclass"

    Read the article

  • Java reflection field value in extends class

    - by Lukasz Wozniczka
    Hello i hava got problem with init value with java reflection. i have got simple class public class A extends B { private String name; } public class B { private String superName; } and also i have got simple function: public void createRandom(Class<T> clazz , List<String> classFields){ try { T object = clazz.newInstance(); for(String s : classFields){ clazz.getDeclaredField(s); } } catch(Exception e){ } } My function do other stuff but i have got problem because i have got error : java.lang.NoSuchFieldException: superName How can i set all class field also field from super Class using reflection ??

    Read the article

  • Invoking WCF functions using Reflection

    - by Jankhana
    I am pretty new to WCF applications. I have a WCF application that is using NetTcpBinding. I wanted to invoke the functions in WCF service using the System.Reflection's Methodbase Invoke method. I mean I wanted to Dynamically call the Function by passing the String as the Function name. Reflection works great for Web Service or a Windows application or any dll or class. So their is certain way to do this for WCF also but I am not able to find that. I am getting the Assembly Name than it's type everything fine but as we cannot create an instance of the Interface class I tried to open the WCF connection using the binding and tried to pass that object but it's throwing the exception as : "Object does not match target type." I have opened the connection and passed the object and type is of interface only. I don't know whether I'm trying wrong thing or in wrong way. Any idea how shall I accomplish this??? The NetTCPBinding all are properly given while opening the connection. And one more thing I am using WCF as a Windows Service using NETTCPBinding.

    Read the article

  • Java reflection

    - by heldopslippers
    Hi people. I have a question about reflection I am trying to have some kind of eval() method. So i can call for example: eval("test('woohoo')"); Now I understand the there is no eval method in java but there is reflection. I made the following code: String s = "test"; Class cl = Class.forName("Main"); Method method = cl.getMethod(s, String.class); method.invoke(null, "woohoo"); This works perfectly (of course there is a try, catch block around this code). It runs the test method. However I want to call multiple methods who all have different parameters. I don't know what parameters these are (so not only String.class). But how is this possible? how can I get the parameter types of a method ? I know of the following method: Class[] parameterTypes = method.getParameterTypes(); But that will return the parameterTypes of the method I just selected! with the following statement: Method method = cl.getMethod(s, String.class); Any help would be appreciated !

    Read the article

  • Strategy Pattern with Type Reflection affecting Performances ?

    - by Aurélien Ribon
    Hello ! I am building graphs. A graph consists of nodes linked each other with links (indeed my dear). In order to assign a given behavior to each node, I implemented the strategy pattern. class Node { public BaseNodeBehavior Behavior {get; set;} } As a result, in many parts of the application, I am extensively using type reflection to know which behavior a node is. if (node.Behavior is NodeDataOutputBehavior) workOnOutputNode(node) .... My graph can get thousands of nodes. Is type reflection greatly affecting performances ? Should I use something else than the strategy pattern ? I'm using strategy because I need behavior inheritance. For example, basically, a behavior can be Data or Operator, a Data behavior can IO, Const or Intermediate and finally an IO behavior can be Input or Output. So if I use an enumeration, I wont be able to test for a node behavior to be of data kind, I will need to test it to be [Input, Output, Const or Intermediate]. And if later I want to add another behavior of Data kind, I'm screwed, every data-testing method will need to be changed.

    Read the article

  • Reflection for a Field going wrong

    - by TiGer
    Hi, I have been trying to use reflection for a specifiec Field in the android.os.build class, the MANUFACTURER field... I have tried by using this code : try { Class myBuildClass = android.os.Build.class; Field m1 = Build.class.getDeclaredField("MANUFACTURER"); validField = true; manufacturer = Build.MANUFACTURER; } catch(Exception ex) { manufacturer = Build.PRODUCT; System.err.println("getDeviceSpecifics, got an exception during getting Field : " + ex.toString()); } I am gettign the following errors : 06-01 11:26:37.639: WARN/dalvikvm(7342): VFY: unable to resolve static field 2 (MANUFACTURER) in Landroid/os/Build; 06-01 11:26:37.639: WARN/dalvikvm(7342): VFY: rejecting opcode 0x62 at 0x0048 06-01 11:26:37.639: WARN/dalvikvm(7342): VFY: rejected Lmobilaria/android/managementModule/Management;.getDeviceSpecifics ()V 06-01 11:26:37.639: WARN/dalvikvm(7342): Verifier rejected class Lmobilaria/android/managementModule/Management; And when debugging I noticed that InvocationtargetException is continuesly thrown, so I am guessing I haven't been implementing the whole Reflection principle correctly... Any idea where things are going wrong or otherwise on how to implement Refelction for a single Field correctly ?

    Read the article

  • Say goodbye to System.Reflection.Emit (any dynamic proxy generation) in WinRT

    - by mbrit
    tl;dr - Forget any form of dynamic code emitting in Metro-style. It's not going to happen.Over the past week or so I've been trying to get Moq (the popular open source TDD mocking framework) to work on WinRT. Irritatingly, the day before Release Preview was released it was actually working on Consumer Preview. However in Release Preview (RP) the System.Reflection.Emit namespace is gone. Forget any form of dynamic code generation and/or MSIL injection.This kills off any project based on the popular Castle Project Dynamic Proxy component, of which Moq is one example. You can at this point in time not perform any form of mocking using dynamic injection in your Metro-style unit testing endeavours.So let me take you through my journey on this, so that other's don't have to...The headline fact is that you cannot load any assembly that you create at runtime. WinRT supports one Assembly.Load method, and that takes the name of an assembly. That has to be placed within the deployment folder of your app. You cannot give it a filename, or stream. The methods are there, but private. Try to invoke them using Reflection and you'll be met with a caspol exception.You can, in theory, use Rotor to replace SRE. It's all there, but again, you can't load anything you create.You can't write to your deployment folder from within your Metro-style app. But, can you use another service on the machine to move a file that you create into the deployment folder and load it? Not really.The networking stack in Metro-style is intentionally "damaged" to prevent socket communication from Metro-style to any end-point on the local machine. (It just times out.) This militates against an approach where your Metro-style app can signal a properly installed service on the machine to create proxies on its behalf. If you wanted to do this, you'd have to route the calls through a C&C server somewhere. The reason why Microsoft has done this is obvious - taking out SRE know means they don't have to do it in an emergency later. The collateral damage in removing SRE is that you can't do mocking in test mode, but you also can't do any form of injection in production mode. There are plenty of reasons why enterprise apps might want to do this last point particularly. At CP, the assumption was that their inspection tools would prevent SRE being used as a malware vector - it now seems they are less confident about that. (For clarity, the risk here is in allowing a nefarious program to download instructions from a C&C server and make up executable code on the fly to run, getting around the marketplace restrictions.)So, two things:- System.Reflection.Emit is gone in Metro-style/WinRT. Get over it - dynamic, on-the-fly code generation is not going to to happen.- I've more or less got a version of Moq working in Metro-style. This is based on the idea of "baking" the dynamic proxies before you use them. You can find more information here: https://github.com/mbrit/moqrt

    Read the article

  • Reflection: Get FieldInfo from PropertyInfo

    - by Ed Woodcock
    Hi guys. I'm doing some dynamic code generation using Reflection, and I've come across a situation where I need to get the backing field of a property (if it has one) in order to use its FieldInfo object. Now, I know you can use .IsDefined(typeof(CompilerGeneratedAttribute), false); on a FieldInfo to discover whether it's autogenerated, so I assume there's a similar thing for Properties which auto-generate fields? Cheers, Ed

    Read the article

  • Java Reflection Utility

    - by DD
    Is there a utility to get a property which isnt prefixed by get from an object using reflection similar to BeanUtils? e.g. if I specify "hashcode" and I want to get the object.hashcode() value. Thanks.

    Read the article

  • Use reflection to get a list of static classes

    - by Christian
    Hi, many questions are close, but none answers my problem... How do I use reflection in C# 3.5 to get all classes which are static from an assembly. I already get all Types defined, but there is no IsStatic property. Counting 0 constructors is really slow and did not work either. Any tips or a line of code? :-) Chris

    Read the article

  • Determine if method is unsafe via reflection

    - by hmemcpy
    I'm looking for a way to filter out methods which have the unsafe modifier via reflection. It doesn't seem to be a method attribute. Is there a way? EDIT: it seems that this info is not in the metadata, at least I can't see it in the IL. However reflector shows the unsafe modifier in C# view. Any ideas on how it's done? Thanks!

    Read the article

  • Get Token's Name with Reflection API.

    - by Mark Tomlin
    I want to find the token's name passed by augment into a function. class Norm { const STR_NORM = 0; const INT_NORM = 0; } function foo($Arg1, $Arg2 = NULL) { getConstName($Arg1); # Should Return STR_NORM; return $Arg1, $Arg2; } echo foo(Norm::STR_NORM); Is there any way to implement getConstName via the PHP Reflection API?

    Read the article

  • Java reflection framework and security

    - by Jijoy
    Hi , Assume I have a singleton class in an external lib to my application. But still I can create instances of that particular class using reflection. Like this Class clas = Class.forName(Private.class.getName()); for(Constructor c : clas.getDeclaredConstructors()){ c.setAccessible(true); Private p = (Private) c.newInstance(); System.out.println(p); } How can I restrict this ? . Thanks J

    Read the article

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