giannisf
giannisf

Reputation: 2599

Setting property doesn't work

I have a class Banner

public class Banner
{
    public virtual int Id { get; protected set; }
    public virtual string Url { get; set; }
    public virtual string Path { get; set; }
    public virtual bool Disabled { get; set; }
    public virtual string TextField { get; set; }
    public virtual DateTime UploadDate { get; set; }
}

and somewhere in my code i have a method to change the value of Disabled.

public void ToggleEnableDisable(int Id)
{
    Banner banner = _session.Query<Banner>().FirstOrDefault(x => x.Id == Id);

    if (banner != null && banner.Disabled)
    {
        banner = banner.Disabled = false //This isn't working, i get cannot convert source type to target type
    }
}

What am i doing wrong ?

Upvotes: 0

Views: 141

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1499840

The problem isn't the fact that you're setting the property - it's that you're trying to use the result of setting the property as the input for setting banner itself. You just want:

banner.Disabled = false;

Upvotes: 5

Related Questions