Skip to content

Instantly share code, notes, and snippets.

@akfish
Last active December 29, 2015 05:49
Show Gist options
  • Save akfish/7624307 to your computer and use it in GitHub Desktop.
Save akfish/7624307 to your computer and use it in GitHub Desktop.
Reflection utility mock up
// Define a class
[FormValidator(typeof(AccountValidator))]
[FormHandler(typeof(AccountHandler))]
[FormSection(0, "Basic Information")]
[FormSection(1, "Connection Settings")]
public class Account
{
[FormEntry(Section = 0, Step = 0)]
public string Email { get; set; }
[FormEntry(Section = 0, Step = 1)]
public string Password { get; set; }
[FormEntry(Section = 1, Step = 0)]
public string UserName { get; set; }
[FormEntry(Section = 1, Step = 1)]
public string HostName { get; set; }
[FormEntry(Section = 1, Step = 2)]
public int Port { get; set; }
[FormEntry(Section = 1, Step = 3)]
public bool UseSSL { get; set; }
[FormEntry(Section = 1, Step = 4)]
public AuthMethod AuthMethod { get; set; }
[FormEntry(Section = 1, Step = 5)]
public bool IsPrimary { get; set; }
}
// Make an instance
var account = new Acccount();
// Call injection extension
account.Inject<FormEntry>(
(target) =>
{
// target.Attribute
Cs.Write("Input {0}:", target.Name);
var line = Cs.ReadLine();
return Convert(line);
});
// Event
account
.BeforeSet<AccountValidator>(
(target, validator) =>
{
// TODO: validate target
})
.AfterSet<AccountHandler>(
(target, handler) =>
{
// TODO: update handler
})
.Inject<FormEntry>(
(target) =>
{
// TODO: same as before
});
var account = new Account();
var validator = new AccountValidator();
account.Map<validator>(
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment