tags:

views:

59

answers:

1

The answer to this SO question says that you can create an api by exposing methods, objects and .ect by setting their scope to public. http://stackoverflow.com/questions/630971/how-to-start-creating-an-application-api-in-net

One of the main things I want to expose is the text of a textbox. Would the best way to do this be to create a public static Text property that is updated by the textbox's textchanged event? Also what would a developer do in order to interact with this text property while my program is running? Would they add a reference to the program .exe in their program? Then would thier program have to be in the same directory as my exe?

Please help, I'm quite clueless here. Also was not sure how to word this question, feel free it edit if it is unclear.

--Edit--

I am working on text editor. Right now I am not completely sure about everything that I want other developers to be able to interact with. One thing that I am sure I want other developers to interact with is the textbox's text and a few labels which make up an "infobar".

+1  A: 

Rather than creating a value which is changed by the value of the text box changing, you could create a public property which returns the current value of the text box.

Assume you have a text box called txtUsername:

public string GetUsername()
{
    return txtUsername.Text;
}

A further benefit of putting them inside these types of getters is the ability to apply custom logic in a single place. For instance, in the above example, you might not care about leading and trailing spaces, and always strip them when accessing the value of the text. Rather than having to call .Trim() every time you access the text box, you can simply get the property to do it. Should requirements change and you all of a sudden do care about trailing/leading whitespace, you only have to change it in one spot (the property).

public string GetUsername()
{
    return txtUsername.Text.Trim();
}

Although this is a very simple example, and in a larger more complex environment there would be better ways to achieve this type of 'business logic'.

Michael Shimmins