user1765862
user1765862

Reputation: 14145

setting property by reflection

I'm trying to set UpperTitle populating Title.ToUpper every time Title set accessor is hit.

public string Title 
{
   get { return Title; }
   set
       {
          Title = value;
          UpperTitle = Title.ToUpper();
       }
}
public string UpperTitle { get; protected set; }

This code compiles but I'm not sure is it ok, cause I'm getting mapping exception

problem to set property by reflection

Upvotes: 0

Views: 75

Answers (1)

Hossein Narimani Rad
Hossein Narimani Rad

Reputation: 32481

In the get you are calling the get (infinite loop) again! So change your code like this:

private string _title;

public string Title 
{
   get { return _title; }
   set
   {
      _title= value;
      UpperTitle = string.IsNullOrEmpty(_title)? string.Empty : _title.ToUpper();
   }
}

public string UpperTitle { get; protected set; }

Upvotes: 3

Related Questions