Is it possible to get an “object” from PropertyInfo?

In my suspension questions I want to get some values ​​through reflection. Now I want the values ​​to be set by objects thanks to reflection.

I want to write this:

private void AppliquerColonnesPersonnalisation(Control control, Propriete propriete, PropertyInfo Info)
        {
            UltraGrid grille = (UltraGrid)control;
            SortedList<int,string> sortedOrderedColumns = new SortedList<int,string>();

            if (grille != null)
            {
                // I want to write MapPropertyInfo method 
                ColumnsCollection cols = MapPropertyInfo(Info);

PropertyInfo contains type ColumnsCollection. I just want to "map" my PropertyInfo to an object to define some properties after: For example:

cols[prop.Nom].Hidden = false;

Is it possible?

Regards,

Florian

EDIT: I tried the GenericTypeTea solution, but I have some problems. Here is my code snippet:

        private void AppliquerColonnesPersonnalisation(Control control, Propriete propriete, PropertyInfo Info)
    {
        UltraGrid grille = (UltraGrid)control;
        ColumnsCollection c = grille.DisplayLayout.Bands[0].Columns;

                    // Throw a not match System.Reflection.TargetException
        ColumnsCollection test = Info.GetValue(c,null) as ColumnsCollection;
        SortedList<int,string> sortedOrderedColumns = new SortedList<int,string>();

But TargetException

+3
source share
1 answer

, PropertyInfo, ColumnsCollection?

, :

var original = GetYourObject();
PropertyInfo Info = GetYourPropertyInfo(original);
ColumnsCollection collection = Info.GetValue(original) as ColumnsCollection;

, PropertyInfo GetValue, . ColumnsCollection, .

UPDATE:

:

object original = grille.DisplayLayout.Bands[0];
PropertyInfo info = original.GetProperty("Columns");

ColumnsCollection test = info.GetValue(original, null) as ColumnsCollection;

Info PropertyInfo . , . , . grille.DisplayLayout.Bands[0].Columns ?

+2

Source: https://habr.com/ru/post/1753165/


All Articles