Most voted "reflection" questions
Reflection is the process by which a program can observe and modify its own structure and behavior at runtime. Commonly used to view metadata, associate methods and properties, and discover types.
Learn more…124 questions
Sort by count of
-
79
votes2
answers11641
viewsWhat is Reflection. Why is it useful?
It is recommended to use in projects? How to use? In what situations Reflection can be used?
-
21
votes4
answers1851
viewsInfer class type from a generic
In the following class I want to assign the attribute clazz class type inferring it from the list given in the constructor. class Foo<T> { private Class<T> clazz; Foo(List<T> list)…
-
18
votes1
answer467
viewsAre there alternatives for reflection/introspection in C++?
I have the following problem. Given some kind of a guy T: template <typename T> I need to be able to convert an object like T on a map std::unordered_map<std::string, boost::any>…
-
17
votes1
answer628
viewsWhat is C#metadata?
What is C#/. NET metadata? What are they for, and how can I use them? I was watching a template of Visual Studio, and browsing the files, I came across them.
-
14
votes2
answers225
viewsWhat is Fastexpando/Fastexpandoobject?
Was reading about Dapper and I came across a feature of him called Fastexpando or Fastexpandoobject, I didn’t understand very well and I had some doubts about this feature. Doubts What is…
-
13
votes2
answers618
viewsHow to list methods of a class in C#?
Again I have to say this: I come from PHP and am learning C# now. I usually like to list the methods that the class has, because I always did this in PHP, to test or debug. $a = new ArrayObject();…
-
10
votes1
answer479
viewsValidate array type attribute in an annotation
When using the annotation Ordem would like to make your attribute valores mandatory. By mandatory I mean that the value of your attribute should not accept an empty array, or an array with an empty…
-
10
votes2
answers513
viewsReflection C#, how does it work?
I’m doing some tests with Reflection, I made this code on the basis of trial and error, so I didn’t understand how exactly it works. This is the enum that I’m wearing: public enum TipoDoAmbiente {…
-
9
votes1
answer136
viewsArrayindexoutofboundsexception in Java 8 Parameter Reflection
I was making a code with Reflection in Java 8 when I came across a strange behavior - A ArrayIndexOutOfBoundsException unexpected. Based on this, I decided to create a minimal, complete and…
-
8
votes1
answer492
viewsHow to get the generic type entity type from the top interface?
I have the following situation: public class MinhaClasse : IMinhaClasse<Carro> { //... } public static void Main(string[] args) { var foo = new MinhaClasse(); } It is possible to get the…
-
8
votes2
answers129
viewsGet user-created methods
I have a method that lists the methods that a given object has, I want to take only the methods created by the user, in this case: Add and Subtract. What this method returns to me: Generic Class…
-
8
votes1
answer324
viewsGet all classes that implement a generic interface
I have an interface similar to this: public interface InterfaceA<T> { T Exemplo(); } And other classes implement it. public class ExemploA : InterfaceA<Int32> { Int32 Exemplo(); } public…
-
8
votes2
answers145
viewsHow to get all interfaces of an object?
I need to list all interfaces that an object implements. From what I understand, I could do the following: Object misterioso; .... misterioso.getClass().getInterfaces(); but this would only take the…
-
7
votes0
answers188
viewsHow to get all methods a class is using
I need to find a way to find all the methods a class is using (watch out, it’s not the methods stated in it). EX: public class Bondia{ public static void main(String[] args){…
-
7
votes2
answers350
viewsHow to get the set of all Python arguments?
Python has both positional and named parameters and operators * and ** which allow receiving an arbitrary number of additional arguments: def foo(a, b, c=1, *args, **kwargs): print(a, b, c, args,…
-
7
votes2
answers534
viewsIs it possible to change the value of an annotation at runtime?
Considering the following annotation: @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface MinhaAnotacao { String valor(); } Defined in a class: @MinhaAnotacao(valor =…
-
6
votes1
answer5290
viewsMethod that returns a class
I am trying to create a method that takes a string and returns an instance of the class with the name passed, example: "Calculator", will return me an instance of the class "Calculator" (If it…
-
6
votes1
answer311
viewsWhat is a Reflection?
We’re creating a website on the computer history of the '70s to '90s, and at a certain point I found the paradigm reflective. Has this last something to do with reflection, that by the way what is?…
reflectionasked 10 years ago user14079 -
6
votes1
answer83
viewsAccess properties without knowing name
You can access all your settings inside the class (estates) without having their names? For example, if I create an instance of a class $classe = new Classe(), and I’m defining things in her:…
-
6
votes1
answer694
viewsHow to pick up attribute dynamically
How I would make the following PHP code in C#? class teste{ public $x = 10; public $y = 10; } $n = new teste(); $a = "y"; print_r($n->{$a}); Note that dynamism is in the variable $a, in which if…
-
6
votes2
answers4042
viewsGet property values of a class
I have the following codes: private PropertyInfo[] ObterPropriedades(Type classe) { PropertyInfo[] properties = classe.GetProperties(); return properties; } private string[]…
-
6
votes1
answer140
viewsDynamically use LINQ aggregator
I am trying to create a function to use Linq aggregator functions (sum, Average, Count) and I am not succeeding. I have the following code: private double…
-
6
votes3
answers293
viewsHow to know if class instance inherits another class?
I’m using reflection to know if one class inherits another, what I found was this: bool herda = typeof(A).IsAssignableFrom(typeof(B)); But I want to do it in the variable getting your type. Here’s…
-
6
votes3
answers625
viewsHow to treat Nullreferenceexception with Lambda
I have a class to search for DisplayName of my entities, where I pass the entity and class returns a list with the real values and name of each attribute of the entity. My problem itself is when I…
-
6
votes2
answers368
viewsHow to get the properties of a type when using Generics C#
I have the following class: public class Pessoa { public int id { get; set; } public string Nome { get; set; } public DateTime DataNascimento { get; set; } } I’ve developed a method to get her…
-
6
votes1
answer108
viewsHow to reflect on overloaded operators in C#?
My problem is this: I’m writing an interpreter and I need to perform dynamic operations between various types. For this use dynamic links provided by DLR consisting of a static object encapsulated…
-
5
votes3
answers523
viewsDynamic display of mandatory, optional or non-existent fields
There is a class that has 12 properties, which in its insertion in the database may be mandatory, optional or non-existent, depending on the business rule specified in the registration of another…
-
5
votes2
answers349
viewsKnow if a class is native to JAVA or created by the User?
I created a method that uses Reflection to run getters on top of an object, but I need to know if the class is native to JAVA, for example: java.lang.String, or whether it has been implemented by…
-
5
votes2
answers172
viewsHow to use Reflection on a COM object?
I am trying to do a Reflection in a program, however, when the time to pick up the type of the object (Which is necessary for the Reflection) is returning "System. __Comobject", and this is not…
-
5
votes1
answer574
viewsHow does the Type.Invokemember method work?
I came across this method in a code and was curious how it works because I’ve seen some applications running in C# that use this method, and when searching for the method in Google, I found no clear…
-
5
votes2
answers887
viewsCalling a string equivalent method
Consider the following class: public class AnimationManager : MonoBehaviour { public GameObject[] Enemies; void OnTriggerEnter2D (Collider2D o) { if (o.tag == "Player") foreach(GameObject Enemy in…
-
4
votes1
answer148
viewsReflection Emit, what’s the point?
Passing a code to MVC, I saw there was a Label label= new Label(); that was underlined with red, when clicking to see the suggestions, I saw the following: using System.Web.Ui.WebControls using…
-
4
votes2
answers839
viewsHow to check if a class implements a C#interface?
How to check if a class implements an interface? For example, I want to include an if that checks if an object is of the Idisposable type. How to do? I tried something like : MinhaClasse meuObjeto =…
-
4
votes3
answers1895
viewsDynamic Query in a List
How to apply a filter to an object List generic using Lambda? I know with Reflection i can get an array with the properties names of my object and through itself Reflection recover the property of…
-
4
votes2
answers909
viewsConvert List<T> to T... dynamically in a method call
I’m in need of something that seems to be simple, but I’ve been doing some research and trying and I haven’t found anything that helps me. Problem I have a list of the kind List<T> I receive…
-
4
votes2
answers801
viewsHow to change the value of a property given its name
In my program I have some classes where data is stored. For example Class1.alfa.dado = 66; Class1.beta.dado = 56; Class1.gama.dado = 37; The user will select in a Combobox one of the options you…
-
4
votes2
answers55
viewsGet information stored in an "attribute"
In the ORM I use, classes are mapped using Attributes. I need to recover the value stored in them. Ex.: [Table("CADASTRO_CLIENTE")] public class Cliente { [Property("Id")] public int Id { get; set;…
-
4
votes1
answer999
viewsAccess Object Property with a string
Pupil: public class Aluno{ public int Id { get; set; } public string Nome { get; set; } public string Sobrenome { get; set; } } Now I need to access the student’s Name and Surname through a string,…
-
4
votes2
answers115
viewsHow to read comments of a class, function or method?
I’ve seen some implementations in the Symfony and Laravel framework that allow you to define through comments routes in controller methods, or the Doctrine Models' Annotation definitions. Sort of…
-
4
votes2
answers335
viewsHow to iterate an attribute with Java Reflection?
In the method below, I use Reflection to set attributes from one class to another, based on mapping via Annotation. How do I map an attribute of a class that is an attribute of another? For example,…
-
4
votes1
answer986
viewsHow to create runtime formulas in C#?
There are many advantages when things change for the better, so were the changes from the Clipper to Delphi and C#, actually only in the visual part. There was in the Clipper a fantastic feature…
-
4
votes2
answers378
viewsLibrary loading at runtime
Is there any contraindication in loading libraries .jar at runtime? I found this code that does this: URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader(); Class sysclass =…
-
4
votes2
answers223
viewsHow to get all constants of a class?
My project has a class helper with several constants representing roles predefined. public static class RolesHelper { public const string ModuloUsuarios = "Usuarios"; public const string ModuloMenus…
-
4
votes1
answer335
viewsGet properties of a class with condition. C#
I would like to get the properties of my Parents object, but I would not like to take the property (States) of my Country class. I tried it the way it is in the "Test" class and I couldn’t because I…
-
4
votes1
answer99
viewsIs it possible to change a String of a method at runtime?
If I have one String fixed within a method is it possible to change it using reflection or something like that? Example: public static void main(String[] args) { String nome = getName(); boolean…
-
3
votes2
answers3847
viewsIs it possible to assign the default value of a property with an attribute?
I wish I could declare a property as: [DefaultValue(10)] public int Maximo { get; set; } And when I was going to use it, it already came with the value started in 10. However the attribute does not…
-
3
votes1
answer2186
viewsHow to use generic types with type parameters?
I have a dictionary that serves as a type mapper with C#. var Map = new Dictionary<Type, Type>() { {typeof(A1), typeof(A2)}, {typeof(B1), typeof(B2)}, {typeof(C1), typeof(C2)}, {typeof(D1),…
-
3
votes1
answer2814
viewsVia java reflection, set and take values of inherited variables
I have the following class hierarchy (POSTRequestHTTP extends ReqeustHTTP) (RequestHTTP extends ComunicationObjectHTTP ) Assuming that each object can have variables corresponding to an item in a…
-
3
votes2
answers103
viewsHow to capture Assembly from classes that inherit from a single class
I have numerous classes. All inherit from a single class public abstract class ClasseBase { public int Id {get;set;} } and other classes: public class Teste1 : ClasseBase{ } public class Teste2 :…
-
3
votes1
answer253
viewsHow to convert lambda to Expression Trees format?
How to convert that lambda: Set.Asqueryable(). Where(profile => profile.CostCenters.Select(Costcentre => Costcentre.Id). Any(Id => Ids.Contains(Id))).Tolist() Actually I managed to do even…