Код: Выделить всё
public bool IsDeviceOperable(ServiceType type, bool isServer, string domain)
{
string settingsFileContent = _fileReader.Read(_filePathProvider.GetSettingsFilePath());
var settings = _jsonDeserializer.Deserialize(settingsFileContent);
var settingsName = GetSettingsNameByType(type);
string deviceType = GetDeviceType(isServer);
var info = settings.GetType().GetProperty(domain.ToUpper())
.PropertyType.GetProperty(settingsName)
.PropertyType.GetProperty(deviceType);
bool value = (bool)info.GetValue(settings, null);
return value;
}
System.Reflection.TargetException: «Объект не соответствует целевому типу».
Файл моих настроек выглядит следующим образом:
Код: Выделить всё
public class Settings
{
public FirstDomain First { get; set; }
public SecondDomain Second { get; set; }
...
}
Код: Выделить всё
public class FirstDomain
{
public Settings1 firstSettings { get; set; }
public Settings2 secondSettings { get; set; }
...
}
public class SecondDomain
{
public Settings1 firstSettings { get; set; }
public Settings2 secondSettings { get; set; }
...
}
Код: Выделить всё
public class Settings1
{
public bool RunOnClient { get; set; }
public bool RunOnServer { get; set; }
}
public class Settings2
{
public bool RunOnClient { get; set; }
public bool RunOnServer { get; set; }
}
Подробнее здесь: https://stackoverflow.com/questions/731 ... s-property