private FieldReflector <TimeRegistrationModel> BuildHourTypeField(ExactOnlineConnector connector) { var reflector = new FieldReflector <TimeRegistrationModel>(nameof(TimeRegistrationModel.HourType)); reflector.SetType(null); reflector.SetDefine((state, field) => { var recentHourTypes = _cacheService.RetrieveForUser <TimeAndBillingRecentHourCostType[]>(key_hourTypes, _userId); if (recentHourTypes == null) { TimeRegistrationConnector timeConnector = new TimeRegistrationConnector(); recentHourTypes = timeConnector.GetRecentHourCostTypes(connector).ToArray(); _cacheService.CacheForUser(key_hourTypes, recentHourTypes, _userId); } foreach (var recentHourType in recentHourTypes) { field .AddDescription(recentHourType.ItemId.ToString(), recentHourType.ItemDescription) .AddTerms(recentHourType.ItemId.ToString(), recentHourType.ItemDescription); } return(Task.FromResult(true)); }); return(reflector); }
private FieldReflector <TimeRegistrationModel> BuildCustomerField(ExactOnlineConnector connector) { var reflector = new FieldReflector <TimeRegistrationModel>(nameof(TimeRegistrationModel.Customer)); reflector.SetType(null); reflector.SetDefine((state, field) => { var recentAccounts = _cacheService.RetrieveForUser <TimeAndBillingRecentAccount[]>(key_customers, _userId); if (recentAccounts == null) { TimeRegistrationConnector timeConnector = new TimeRegistrationConnector(); recentAccounts = timeConnector.GetRecentAccounts(connector).ToArray(); _cacheService.CacheForUser(key_customers, recentAccounts, _userId); } foreach (var recentAccount in recentAccounts) { field .AddDescription(recentAccount.AccountId.ToString(), recentAccount.AccountName) .AddTerms(recentAccount.AccountId.ToString(), recentAccount.AccountName); } return(Task.FromResult(true)); }); return(reflector); }
public override IFormBuilder <T> Field(string name, ActiveDelegate <T> active = null, ValidateAsyncDelegate <T> validate = null) { var field = new FieldReflector <T>(name, _ignoreAnnotations); field.SetActive(active); field.SetValidate(validate); return(Field(field)); }
public void Test_StronglyTyped_InvalidCast_Set( ) { using (var field = new FieldReflector <string>(Agent007, "id")) { Assert.Catch <ArgumentException>(() => field.SetValue(Agent007, "Abacus"), "Expected InvalidCastException to be raised when attempting to" + " retrieve field of type Guid as a string."); } }
public void Test_WeaklyTyped_TargetException_Set( ) { using (var field = new FieldReflector(typeof(Person), "id")) { // This is a non-static field thus field access requires a target object instance. Assert.Catch <TargetException>(() => field.SetValue(null, Guid.NewGuid( )), "Expected TargetException to be raised when attempting to " + "assign the value of non-static field."); } }
public void Test_StronglyTyped_TargetException_Get( ) { using (var field = new FieldReflector <Guid>(typeof(Person), "id")) { // This is a non-static field thus field access requires a target object instance. Assert.Catch <TargetException>(() => field.GetValue(null), "Expected TargetException to be raised when attempting to " + "retrieve the value of non-static field."); } }
public FieldReflectorBenchmarks() { FieldFakes.StaticFiled = "StaticFiled"; _staticField = typeof(FieldFakes).GetTypeInfo().GetField("StaticFiled"); _staticFieldReflector = _staticField.GetReflector(); _instance = new FieldFakes(); _instance.InstanceField = "InstanceField"; _field = typeof(FieldFakes).GetTypeInfo().GetField("InstanceField"); _fieldReflector = _field.GetReflector(); }
private static FieldReflector <ConfirmModel> BuildConfirmationField() { var reflector = new FieldReflector <ConfirmModel>(nameof(ConfirmModel.Confirmation)); reflector.SetType(typeof(Boolean)); reflector.SetPrompt(new PromptAttribute(Text + "{||}")); return(reflector); }
public void Test_StronglyTyped_Get( ) { using (var field = new FieldReflector <Guid>(Agent007, "id")) { Assert.NotNull(field.FieldInfo, $"Field named \"id\" not found in type {Agent007.GetType( )}"); Assert.NotNull(field.GetValue(Agent007), $"Value returned was null."); Assert.IsTrue(field.Value is Guid, $"Unexpected value type for field \"id\" in {Agent007.GetType( )}, " + $"expected {typeof( Guid )}."); } }
public void Test_WeaklyTyped_Get( ) { // Wrapping instantiation in a using statements allows for automatic disposable of the reflector when // it's no longer required. using (var field = new FieldReflector(Agent007, "id")) { Assert.NotNull(field.FieldInfo, $"Field named \"id\" not found in type {Agent007.GetType( )}"); Assert.NotNull(field.GetValue(Agent007), $"Value returned was null."); } }
public void Test_WeaklyTyped_Set( ) { using (var field = new FieldReflector(Agent007, "id")) { Assert.NotNull(field.FieldInfo, $"Field named \"id\" not found in type {Agent007.GetType( )}"); Assert.NotNull(field.GetValue(Agent007), $"Value returned was null."); var id = field.GetValue(Agent007); field.SetValue(Agent007, Guid.NewGuid( )); Assert.AreNotEqual(id, field.GetValue(Agent007), "Expected change in Agent007's id did not occur."); } }
private static IForm <MeetingRequestInput> BuildMeetingRequestInputForm() { Field <MeetingRequestInput> durationField = new FieldReflector <MeetingRequestInput>(nameof(MeetingRequestInput.MeetingDuration)); // TODO: Seems this is a good chance for an enum durationField.SetPrompt(new PromptAttribute("What is the meeting duration?")); durationField.SetLimits(60, 3600); return(new FormBuilder <MeetingRequestInput>() .Field(nameof(MeetingRequestInput.RequestedDateTime), "What day would you like to meet?") .Field(durationField) .Field(nameof(MeetingRequestInput.AttendeeEmail), "What is e-mail address of the person you'd like to meet?") .Field(nameof(MeetingRequestInput.AttendeeName), "What the name of the person you're meeting?") .Field(nameof(MeetingRequestInput.MeetingSubject), "What is the meeting about?") .Build()); }
private FieldReflector <TimeRegistrationModel> BuildProjectField(ExactOnlineConnector connector) { var reflector = new FieldReflector <TimeRegistrationModel>(nameof(TimeRegistrationModel.Project)); reflector.SetType(null); reflector.SetDefine((state, field) => { Guid?customerId = !String.IsNullOrEmpty(state.Customer) ? Guid.Parse(state.Customer) : (Guid?)null; if (customerId != null) { string key = key_hours + customerId.ToString(); var recentProjects = _cacheService.RetrieveForUser <RecentHours[]>(key, _userId); if (recentProjects == null) { TimeRegistrationConnector timeConnector = new TimeRegistrationConnector(); recentProjects = timeConnector.GetRecentProjects(connector, customerId).ToArray(); _cacheService.CacheForUser(key, recentProjects, _userId); } foreach (var recentProject in recentProjects) { field .AddDescription(recentProject.ProjectId.ToString(), recentProject.ProjectDescription) .AddTerms(recentProject.ProjectId.ToString(), recentProject.ProjectDescription); } // if there's only one option to select; select it! if (recentProjects.Length == 1) { state.Project = recentProjects.First().ProjectId.ToString(); return(Task.FromResult(false)); } } return(Task.FromResult(true)); }); return(reflector); }