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.
24,792
questions
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 ...
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-...
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 ...
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&...
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 ...
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....
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&...
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....
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 ...
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:&...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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
...
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 ...
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 ...
-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 ...
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 > ...
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 : ...
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&...
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 ...
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 ...
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&...
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 ...
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 (...
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 ...
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 ...
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)
...
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 ...
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. ...
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 ...
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?
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?
@...
-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 ...
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 ...
-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 ...
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()
}
...
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-...
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 ...
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 ...
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 ...
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
{
...
[...
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, ...
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 ...
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 ...
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 ...
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;
}
...