tags:

views:

121

answers:

5

Have a look at this:

http://www.ajaxforasp.net/AsyncDocs/html/43a5b889-47bd-bdb6-092e-e0a91ca9e8ea.htm

WaitMessage Property Syntax

public static string WaitMessage { get; }

I'm not sure if it's because I don't know what I'm doing or the documentation is wrong, but for the life of me I can't figure out how I'm supposed to assign a value to a readonly field (I'm trying to set it to an empty string).

A: 

EDIT: Just noticed the other remarks that the field isn't actually readonly, but if it were:

You can set the value of a static readonly field in a static constructor

class A 
{    
  static readonly string b;
  static()
  {
    b = string.Empty;
  }
}
Eric J.
I don't have access the the source code, I'm using a pre-compiled library.
Daniel T.
+1  A: 

It seems to be a static readonly property, not a field. The only way to assign this value is to use reflection. But first you'd have to find out where the wait message is actually stored. E.g. use .NET reflector to find the field (if it exists) for WaitMessage. Then modify it with reflection.

But it won't work if the WaitMessage is hard-coded or comes from a resource dictionary. (But you can see that as well in .NET reflector)

chris166
A: 

You could just make it non-readonly and give it a private set() which you only call from the constructor.

tsilb
A: 

Looks like a problem with API. Library developers could simply forget to provide a setter for this property.

Pavel Chuchuva
+1  A: 

Look at the source of your file - it's open source, it only took a few minutes.
The getter is looking for the value in web.config (or app.config) with the key "WaitMessage", and then returning a default value:

http://asynccontrols.svn.sourceforge.net/viewvc/asynccontrols/AsyncControls/trunk/Utils/AsyncDefault.cs?revision=5&view=markup

This means the documentation is wrong - you cannot set this property directly.

Kobi
Thanks, that did it! I actually found out after I made this post that it was open source (stupid me for not realizing it says so right on the website), so I added a set accessor, but this way is better because if they come out with a new version, I can upgrade without breaking anything.
Daniel T.