I’m starting to learn C# for WP7, I’m making an app to scrape various sites and display a couple of items of info off the page.
I’m going to allow the user to create multiple “accounts” on the phone – each is a set of login details for a particular site. For example, if I was to use stackoverflow as an example, I’d have a class:
public abstract class MyBaseClass
{
public Dictionary<string, string> fields;
}
public class StackOverflow : MyBaseClass
{
public StackOverflow()
{
fields.Add("Username", "Default Username");
fields.Add("Password", "");
}
}
The class will do all the work, I want people to be able to submit new classes for inclusion in later releases.
The application will iterate over each of the fields, displaying the appropriate form field to the user. Once completed, the UI will update the dictionary, ready to start scraping.
Using a dictionary seemed ok to start, but I hadn’t thought about how to represent the data type – I want to define whether the input should be text, number, or password.
How would I best include that data?
You are going to have to create your own model to represent this. Just do what comes naturally and makes sense. How about this:
By the way, don’t make the
fieldsvariable ofMyBaseClasspublic, this is an implementation detail and should be hidden / encapsulated!