Questions tagged [reflect]
123 questions
-1
votes
1 answer
Avoid duplicating identical code for string map and slice
While writing two methods (one for a slice and one for a string map) I realized the implementation for both methods is identical and the only thing that changes is the prototype of the functions.
I'm trying to avoid repeating it and originally I…

Towerman
- 185
- 1
- 4
-1
votes
1 answer
Reflecting tables with Flask-Sqlalchemy when using AppFactory Structure raises Runtime errors
I am having the same issue as this thread: Reflecting tables with Flask-SQLAlchemy raises RuntimeError: application not registered
I tried adding:
db.reflect(app=app)
in the db initialization method, but I am still getting:
File…

maslyankov
- 21
- 3
-1
votes
1 answer
How to create an instance of an generic class in java?
I was wondering if it is possible to create a construtor function:
public C newInstance(Class constructor_class,
Class type,
Object...parameters){
// create a new…

Karl Sassie
- 17
- 6
-1
votes
1 answer
How to get a class of a generic in a superclass?
How do I get a class of the generic type inside of the super class constructor?
In other words I want a Class instance where T is the generic from my super class.
This would work in the code below for the ChildA class where I define the generic…

Karl Sassie
- 17
- 6
-1
votes
1 answer
Get all the class implementing a given interface using java.lang.reflect only
I try to use reflection to get every class that implements a given interface in java, using the classes in java.lang.reflect only. For of many reasons i can't use any external library.
I've found many tutorials to do a lot of things with…

Axel
- 165
- 3
- 14
-1
votes
2 answers
Golang: update slice in loop for empty interface
For example, we have 3 CSV files and common for all is Email column. In first file are Name and Email, in another are Email (plus different info) and no Name field. So, if I need to fill in 2 and 3 files field Name based on the correspondence of the…

xiaose
- 616
- 1
- 7
- 19
-1
votes
1 answer
How to use reflection to assign values to unknown structures
Structs may contains float32, int32, string or pointer to struct.
Here is my code. But i do not know how to assign values to the structs inside.
type T struct {
A int
B string
C *P
}
type P struct {
A string
B int
}
func…

ray
- 21
- 5
-1
votes
1 answer
How to determine type of values in a slice of interface{}
Consider the following code:
package main
import (
"fmt"
"reflect"
)
func f(v interface{}) {
fmt.Println(reflect.TypeOf(v).Elem())
fmt.Println(reflect.ValueOf(v))
}
func main() {
var aux []interface{}
aux =…

Jesus Fernandez
- 43
- 1
- 4
-1
votes
1 answer
Can a c# console app get reflection info on a Windows Control?
I am writing a console app that is run by Visual Studio as a pre-build step. This app needs to be able to get Type information on controls (like System.Windows.Controls.Button) which normally isn't possible since System.Windows.Controls isn't…

Betty Crokker
- 3,001
- 6
- 34
- 68
-1
votes
1 answer
In Go, how to check that an interface implements all of a struct's exported methods?
I'm working on a Go library in which I've used the interfacer tool (https://github.com/rjeczalik/interfaces) to create an interface from a struct, and subsequently ran moq (https://github.com/matryer/moq) to generate a mock object for that…

Kurt Peek
- 52,165
- 91
- 301
- 526
-1
votes
1 answer
Iterating over json using reflection
I'm trying to consume a rest endpoint in my golang project. The JSON structure is pretty large and is semi-structured, so I'm using reflection to iterate over it and grab the information that I am interested in.
Here is how I'm unmarshal-ing the…

Gerb
- 883
- 12
- 31
-1
votes
1 answer
Generic function which appends two arrays
Not able to figure out how to convert interface{} returned from function into an array of structs
As part of some practise i was trying to create a function which can take 2 slices of some type and concatenates both and returns the slice.
The code…

suraj pillai
- 9
- 2
-1
votes
1 answer
go reflect find by structtag
type A struct {
Name *NameS `json:"name"`
}
for a struct A,is there a method in reflect that I can find a field by structtag
like
reflect.ValueOf(&ns)
// struct
s := ps.Elem()
s.FieldByTag("name")

curtank
- 600
- 2
- 7
- 18
-1
votes
1 answer
element type of []interface{}
How to get the runtime element type of []interface{}?
I tried the following test.
var data interface{}
temp := make([]interface{}, 0)
temp = append(temp, int64(1))
data = temp
elemType := reflect.TypeOf(data).Elem()
switch elemType {
case…

Hel
- 305
- 5
- 14
-1
votes
1 answer
NUnit seems to lose track of Reflect.js after cancelling an alert
I am using C# and the Selenium Webdriver in Visual Studio 2017 to automate some tests. I am currently stuck with a test that fails to find an element after canceling an alert.
When I step through the code, I get an error indicating that Reflect.js…

Kelly
- 1
- 1