/// <summary> /// Resolve effective setting within the purpose for the specified entity /// </summary> /// <param name="entity">Entity to for which settings are to be resolved</param> /// <param name="purpose">The purpose of the settings which are to be resolved</param> /// <param name="name">Name of the setting for the specified entity and purpose</param> /// <returns>Effective setting for the specified entity, purpose, and name</returns> /// <exception cref="ArgumentException">One of the specified arguments fail validation</exception> /// <exception cref="UnknownEntityType">Specified entity type is not known within settings schema</exception> /// <exception cref="UnknownSetting">Specified setting name is not known within settings schema</exception> public Setting ResolveSetting(EntityIdentifier entity, string purpose, string name) { #region input validation ValidateEntityIdentifier(entity); if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(name)); } #endregion #region input clean-up entity = Normalize(entity); purpose = NormalizePurposeName(purpose); name = name.Trim(); #endregion IEntityType entityType = _settingsSchema.GetEntityType(entity.Type); /* * An exception should be thrown if entity-type does not exist, e.g. incorrect or has been removed from schema, * to alert developer of usage of removed/unknown entity-type */ if (entityType == null) { throw new UnknownEntityType(); } IEnumerable <SettingDefinition> settingDefinitions = entityType.GetSettings(purpose, name); SettingDefinition settingDefinition = settingDefinitions.FirstOrDefault(); /* * An exception should be thrown if setting definition does not exist, e.g. incorrect or has been removed from schema, * to alert developer of usage of removed/unknown setting */ if (settingDefinition == null) { throw new UnknownSetting(); } Setting setting = _settingStore.GetSetting(entity, purpose, name); return(ResolveSetting(purpose, name, setting, settingDefinition)); }