public Result <string, Profile?> LoadProfile() { try { if (!File.Exists(_configFileInfo.FullName)) //don't use configFile.Exists here, since that will bug if the file is created on the first run. { return(Result <string, Profile?> .Ok(null)); } using (var streamReader = new StreamReader(_configFileInfo.FullName)) { var profileDto = _profileSerializer.Deserialize(streamReader) as ProfileDto; if (profileDto is null) { return(Result <string, Profile?> .Error(_errorMessageBuilder.Build(nameof(LoadProfile), "Profile could not be created, profileDto is null."))); } if (profileDto.Version != Version) { return(Result <string, Profile?> .Error(_errorMessageBuilder.Build(nameof(LoadProfile), "Profile could not be created since the versions do not match."))); } var viewGroups = new List <ViewGroup>(); foreach (var viewGroupsDto in profileDto.ViewGroupDtos) { var optionItems = new List <OptionItem>(); foreach (var optionItemDto in viewGroupsDto.OptionItemDtos) { ServiceType.FromName(optionItemDto.Type) .OnErrorAndSuccess( error => { Debug.Log(error); }, serviceType => optionItems.Add( new OptionItem( serviceType, optionItemDto.SystemName, optionItemDto.DisplayName, optionItemDto.Accumulation, optionItemDto.AccumulationDefault, optionItemDto.Radius, optionItemDto.RadiusDefault, optionItemDto.Ignore.GetValueOrDefault(false) ) ) ); } var viewGroup = new ViewGroup(viewGroupsDto.Name, viewGroupsDto.Order, optionItems); viewGroups.Add(viewGroup); } return(Result <string, Profile?> .Ok(new Profile(viewGroups))); } } catch (Exception ex) { return(Result <string, Profile?> .Error(_errorMessageBuilder.Build(nameof(LoadProfile), ex))); } }