Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Acces object properties using reflection

Status
Not open for further replies.

Kai77

Programmer
Jun 7, 2004
77
0
0
NL
I have the following class:

namespace GPR.ODS.App.MSO.WebApp.Data
{
public partial class MutatieResponse
{

private MutatieStatus mutatieStatusField;

private ApplicatieFout applicatieFoutField;

///// <remarks/>
public MutatieStatus MutatieStatus
{
get
{
return this.mutatieStatusField;
}
set
{
this.mutatieStatusField = value;
}
}

///// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace = "]
public ApplicatieFout ApplicatieFout
{
get
{
return this.applicatieFoutField;
}
set
{
this.applicatieFoutField = value;
}
}
}
}

I am trying to code a static procedure which takes an object as a parameter and map the properties to the object Mutatieresponse.

I have got the following code:

public static class ConvertToMutatieResponse
{
public static MutatieResponse Convert(object value)
{
MutatieResponse mutatieResponse = new MutatieResponse();
mutatieResponse.MutatieStatus = value.GetType().GetProperty("MutatieStatus", typeof(mutatieResponse.MutatieStatus)).GetValue(value, null);
return mutatieResponse;
}
}

It keeps telling me "Cannot implicitly convert type 'object' to 'GPR.ODS.App.MSO.WebApp.Data.MutatieStatus'. An explicit conversion exists (are you missing a cast?)"

How can I return the value with the correct type?
 
Code:
public static class ConvertToMutatieResponse
    {
        public static MutatieResponse Convert(object value)
        {
            MutatieResponse mutatieResponse = new MutatieResponse();
            mutatieResponse.MutatieStatus =  [red](mutatieResponse.MutatieStatus)[/red]value.GetType().GetProperty("MutatieStatus",  typeof(mutatieResponse.MutatieStatus)).GetValue(value, null);
            return mutatieResponse;
        }
    }

probably this.

Christiaan Baes
Belgium

My Blog
"In a system where you can define a factor as part of a third factor, you need another layer to check the main layer in case the second layer is not the base unit." - jrbarnett
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top