As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [reflection]

Reflection is the ability of a program to observe and/or modify its structure and/or behavior at runtime. Reflection is dependent on the supporting programming language - please tag the programming language being used when using this tag.

Filter by
Sorted by
Tagged with
0 votes
3 answers
47 views

C# help creating a 1d array from an array of class data

Need some help pulling data out of a class in different orders - think I need reflection but not sure how to set it up. public class Strike { public float volume { get; private set; } public ...
Dan Gordon's user avatar
4 votes
2 answers
80 views

What is the fully qualified class name of an enum defined locally within a method?

As of Java 16, we can now define an enum locally, within a method. This feature came as part of the work for the new records feature. (Interfaces too can be local, by the way.) What is the fully-...
Basil Bourque's user avatar
0 votes
1 answer
14 views

Call Select with own type and expression

I want to done follow: var xpQuery = new XPQuery<Contact>(session); var select = xpQuery.Select(s => s.FullName); var distinct = select.Distinct(); var list = distinct.ToList(); XPQuery is ...
Andrey Kucher's user avatar
0 votes
1 answer
18 views

DynamicForm Component that takes Generic Model Class as Parameter to Generate EditForm

I have a component called DynamicForm which accepts couple of Parameters including Generic Model Class. @typeparam TModel <EditForm Model="@Model" OnValidSubmit="@HandleFormSubmit&...
Alisbha Khan's user avatar
0 votes
1 answer
25 views

Use of ReflectionTestUtils.setField() in Junit testing to set a List of objects

in my implementation , i have List<recordEntity> entityList = service.mapper(parameter1,parameter2); i need to set the value for this entityList with a static value for my unit testing, i know ...
user_che_ban's user avatar
0 votes
2 answers
31 views

Can I perform type conversion using the type found through Java reflection?

Can I perform type conversion using the type found through Java reflection? public class Dto { private String name; private int age; public Dto(){} } It has two fields of different types....
Henry C.'s user avatar
0 votes
1 answer
20 views

how to edit method annotation attributes on runtime in springboot project?

how to edit method annotation attributes on runtime in springboot project? i've known there's a way to edit by using reflection like invocationHandler.getClass().getDeclaredField("memberValues&...
near's user avatar
  • 1
0 votes
0 answers
37 views

Assembly Resolve Context problems

I'm loading an Assembly that references to TPL.DataFlow library and I was having problems because TPL.DataFlow dll was not loading. As I have read in Microsoft Documentation when using Assembly....
JuanDYB's user avatar
  • 568
0 votes
0 answers
22 views

System.InvalidProgramException Common Language Runtime detected an invalid program for Reflection

System.InvalidProgramException : Common Language Runtime detected an invalid program. Seeing this error message whilst trying to check the expression's correctness and if it is the correct IL. The ...
bob123123123123's user avatar
2 votes
1 answer
54 views

How can I generate an array of all fields in a JSON struct instance using reflection?

Let me show my code first: This is my structure type Lessee struct { Name string `json:"name" gorm:"name"` ShortName string `json:"shortName" gorm:&...
Jayleonc's user avatar
0 votes
0 answers
23 views

Access Property values at run time from a mapping function

I have a list of objects let's say it is FirstName, LastName, Age, Address. It reality it is about 20 of those. Now I want to populate an excel file. I do know in advance that for example FirstName's ...
MidTown's user avatar
  • 83
0 votes
0 answers
8 views

How to Fix Loading Issues in Unity Reflect and Correct Red/Blue Box Errors?

red boxes around objects and they wont load in correctly and some stay blue and never load.. i have tried exporting it again and to different projects locally and on the cloud. I in in the eastern us ...
J Show's user avatar
  • 1
0 votes
0 answers
25 views

Spring find custom annotations at startup and get method for posterior execution [closed]

using spring boot how could I: find all beans methods annoted with a custom annotation at application startup, then store this methods references into a map in a service, then call this service to ...
Rafael de Oliveira's user avatar
2 votes
0 answers
41 views

Get properties types of Class.Type in Swift

I want to retrieve all classes that conform specific protocol protocol Service: NSObject {} and then build a dictionary [ClassName: [String array of property types]]. I managed to retrieve all classes ...
Bohdan Savych's user avatar
0 votes
1 answer
26 views

How to get interface implementation type for currently executing method?

I have an interface with several implementations. The implementations and interface method call are in different packages if that matters. I'm trying to catch the exception that may occur during the ...
Pukanium's user avatar
0 votes
1 answer
30 views

How to fill current object (this) by another object

I need to copy all properties from another object to curren object (this) in Kotlin. object.copy() is not solution because i can't use it on curren instance of class. Maybe by reflection. In c# it ...
marios160's user avatar
1 vote
0 answers
54 views

Get or recreate .class file of java.lang.Class instance

I'm using a library which generates some classes at runtime, now I want to export them to look at their bytecode since reflection on the classes doesn't give me enough info about them. I tried using ...
uglibubla's user avatar
0 votes
1 answer
28 views

Java reflection: Class.getConstructor throws NoSuchMethodException but Class.getConstructors finds the correct constructor

I'm attempting to use reflection to create a new instance of a class, using Class.getConstructor, like so: class Program { public static void main(String[] args) { // this throws ...
Nonne's user avatar
  • 25
0 votes
1 answer
29 views

How to access the values of a data class in Kotlin?

Here's the codes that is working: data class Abc( val a: String, val b: String, val c: String, val d: D ) { data class D( val e: String, val f: String, val ...
user3768495's user avatar
  • 3,967
-1 votes
1 answer
20 views

How can I dynamically add ValidationAttributes to properties in WPF/AvaloniaUI

I want to dynamically add ValidationAttributes to a property, which enables error validation on whichever control has a binding to that specific property, by calling the attributes IsValid function. I ...
Htennek's user avatar
0 votes
2 answers
72 views

Build getters and setters lambdas to avoid using reflection in c#

I am validating a lot of complex objects in my applications. For example: public class School{ public string Name {get;set;} public DateTime DateCreated {get;set;} public List<Person > ...
Tono Nam's user avatar
  • 33.7k
4 votes
1 answer
93 views

How does magic_enum library can output enum value as string with msvc?

The magic_enum library provides way to retrieve an enum value as its name, in the form of a string. For instance: #include <iostream> #include "magic_enum.hpp" enum class Dummy : ...
Dharmesh946's user avatar
1 vote
0 answers
41 views

Kotlin no-arg compiler plugin doesn't generate constructors

Because I need some way to initialize all variables in the noArg constructor, I've tried to apply no-arg Kotlin Compiler Plugin. Build.gradle: plugins { id "org.jetbrains.kotlin.plugin.noarg&...
Samuel's user avatar
  • 11
0 votes
0 answers
32 views

llegal reflective access at HtmlPipelineContext constructor of itext 5

context: jdk11, springboot, itextpdf 5.5.13.3, ubuntu, eclipse during: new HtmlPipelineContext(null); throughout new CssAppliersImpl(new XMLWorkerFontProvider()); and last CssAppliersImpl(){// map ...
Andrzej Więcławski's user avatar
0 votes
1 answer
62 views

Golang: how to determine a method is promoted from an embedded struct instead of being directly implemented

How can I tell if a method/interface is promoted from an embedded struct (in other words: a struct "inherits" a method instead of directly implementing it)? For example: is there a way to ...
kzantow's user avatar
  • 39
0 votes
1 answer
38 views

How to access functional option function name

Given the following program, how would I go about accessing the functional options function names using reflection? package main import ( "fmt" "path" "reflect&...
dillon's user avatar
  • 811
3 votes
1 answer
34 views

xml.Unmarshal unsupported type struct

I'm getting an error where I cannot xml.Marshal a struct made at runtime with reflect. It is giving me the following error: xml: unsupported type: struct { ... } Here is my go-playground link. Anyone ...
nigel239's user avatar
  • 1,381
0 votes
1 answer
46 views

Named fields for another class

I need to access some private fields via reflection. While this is considered bad, it is an external library and I have no other way to access it. The field names (and types) are known in advance (...
Marc's user avatar
  • 33
0 votes
0 answers
81 views

Using reflection for getting the typelist of a class constructor

I need a template that receives a class as a type, and returns a list of types from its constructor. I tried to use the first answer of this SO question, but it only works for some classes. This ...
carraro's user avatar
  • 142
1 vote
1 answer
36 views

Calling java.lang.reflect.Field::getValue(this) from abstract superclass defined method returns IllegalAccessException

I'm trying to print the whole hierarchy of a class using reflection. To do this I defined an abstract superclass A that defines the toString(int offset) method: abstract class A { public String ...
Federico Xella's user avatar
0 votes
1 answer
42 views

How to convert lambda expression from a type to another type in Java?

I'm using mybatis-plus's lambda chained query and it looks like this Long uid = new LambdaQueryChainWrapper(baseMapeer) .select(User::getUid) .eq(User::getUsername, username) ...
Emiya Elien's user avatar
0 votes
1 answer
22 views

How to remove all registered event handlers of a specific event from a UWP Control

I would like to know, how can I remove all the event handler registered in a particular event in a UWP Control (e.g., button or toggle switch). Consider the fact that I don't have any access to the ...
Redwan Dipto's user avatar
0 votes
3 answers
55 views

How to pass parameter to invoke method as a vararg of a relfected class in case of Java reflection?

I have a project in which I am using a third party library. However, I need to call methods from the third party only if the user has copied those jars in the project, or else use the existing jars. ...
Abhishek Ingale's user avatar
0 votes
1 answer
38 views

How to cast to a list of a type inaccessible due to protection level?

I have a type in a 3rd party library I can't mark as public but need to iterate through a list of these objects. I can get the object using reflection but this object is of a List. Simply casting it ...
Cheyenne's user avatar
0 votes
0 answers
41 views

How do I describe a constructor with boost::describe?

The boost::describe library works when defining reflection info for member functions and variables, but is it possible to describe constructors?
JvJ's user avatar
  • 112
1 vote
1 answer
25 views

Blazor - Reflection issue

I'm trying to get the data values out of an object. I can get the properties from the Class just fine. But when I ask for the values, it fails. Any thoughts on why the GetValues line isn't working? @...
Angela's user avatar
  • 13
-5 votes
2 answers
78 views

How to get values from the array, that put into the object? [closed]

I am making json parser so I need the universal method, thats why I can not int[] arr = obj as int[]; int[] array = new int[] { 0, 1, 2 }; object obj = array; //I need to get value from the 'obj' I ...
justSMTH's user avatar
0 votes
2 answers
49 views

Index specific TypeORM entity fields

I'm building an indexing service to index various entity fields. I'd like to be able to add a decorator like @Searchable or similar to the fields I want to decorate and then using some kind of ...
robertmain's user avatar
-1 votes
0 answers
43 views

Invoke a method which returns an object from a specific class

I have a Java method that I am going to call using reflection, but it throws an UnsupportedOperationException: invalid class reference provided: package example; public class TestContract extends ...
mr123xkdas3's user avatar
1 vote
1 answer
59 views

How to access the embedded struct inside the Slice of Pointers field of a Struct

I want to add functionality to take the first element when the data is []*struct. func getEncFields(t reflect.Type, list map[string]int) { for t.Kind() == reflect.Ptr { t = t.Elem() } ...
Hariharan Panneerselvam's user avatar
0 votes
1 answer
55 views

Using C# Reflection to parse a hierarchy of data classes

I have written a data parser for my script engine that uses reflection to get the value of actual program data classes. I have a hierarchy of classes where some of my sub-classes hide other sub-...
Digilee's user avatar
  • 33
2 votes
1 answer
52 views

Passing Java Function to KFunction

Is there any way way to pass a Function to method with parameters KFunction? I have library in kotlin which I want to make work in java but I'm unable to convert Function to KFunction (?). The ...
Cherry's user avatar
  • 29
0 votes
0 answers
19 views

Can I control reflection intensity with a map in three.js?

I'm currently working on a project where I would like to control what portions of the material have reflectivity. I was hoping this could be achievable with something like an alpha/specular/bump map ...
Zach's user avatar
  • 91
0 votes
1 answer
60 views

Having a hard time with reflection in golang

I am trying to dynamically design a protocol test. The function which I need to use is go-ethereum's Decode: https://github.com/ethereum/go-ethereum/blob/master/p2p/message.go#L54 Then some of my code ...
transient_loop's user avatar
0 votes
1 answer
18 views

Only one Rigidbody can be added to a GameObject, yet Rigidbodies lack [DisallowMultipleComponentAttribute]. Why?

Obviously GameObjects should not have more than one Rigidbody. Yet, after digging through the source code, I don't see any attribute that would cause the behaviour. namespace UnityEngine { ... [...
Isaac Thompson's user avatar
1 vote
1 answer
41 views

CLR Reflection and Metadata management - where is the truth?

I always thought that Reflection in CLR loads metadata for types on demand, when you actually request needed information. And then it is cached, and all subsequent calls will be cheaper. At least, ...
grilledCheeze's user avatar
0 votes
1 answer
52 views

Why below function is not being optimized by using delegate?

I have below function to send the log. And I used to have a reflection approach.(The commented code inside the function). I would like to optimize the reflection, after some investigation online, I ...
wadefanyaoxia's user avatar
1 vote
0 answers
57 views

Separate implicit vs. explicit definition of equals/hashCode for Java Record, via reflection?

Is it possible to determine (via Reflection) for a Java Record class, if it has an implicit or explicit definition of equals() and/or hashCode(Object)? For some reflection-based meta-validation of all ...
weiresr's user avatar
  • 630
2 votes
1 answer
37 views

What is the difference between the metaclass Type and the metaclass Class in Java?

What is the difference between the metaclass Type and the metaclass Class in Java? When should I be using one or the other when programming with reflection? Instances of the class Class represent ...
Kim Mens's user avatar
  • 327
0 votes
0 answers
15 views

How to get proto message leaf data in C++ if we only know the leaf paths?

I have some paths, such as "data.user.user_id"、"data.user.name" etc. And some messages, maybe proto like: message xxx { Data data = 0; } message Data { User user = 0; } ...
Anna's user avatar
  • 251

1
2 3 4 5
496