protected SettingsMemberInfo(MemberInfo settingsTypeMemberInfo, Type settingType, Func <object> getObject, Action <Settings> setObject) { this.getObject = getObject; this.setObject = setObject; #endif Type = settingType; FullName = settingsTypeMemberInfo.DeclaringType.FullName + "." + settingsTypeMemberInfo.Name; /*//version with static __StorageDir * string storageDir; * for (; ; ) * { * PropertyInfo fi = settingType.GetProperty(nameof(Settings.__StorageDir), BindingFlags.Static | BindingFlags.Public); * if (fi != null) * { * storageDir = (string)fi.GetValue(null); * break; * } * settingType = settingType.BaseType; * if (settingType == null) * throw new Exception("Settings type " + Type.ToString() + " or some of its ancestors must define the public static getter " + nameof(Settings.__StorageDir)); * } * File = storageDir + System.IO.Path.DirectorySeparatorChar + FullName + "." + Config.FILE_EXTENSION; */ Settings s = (Settings)Activator.CreateInstance(Type); //!!!slightly slowler than calling a static by reflection. Doesn't run slower for a bigger class though. File = s.__StorageDir + System.IO.Path.DirectorySeparatorChar + FullName + "." + Config.FILE_EXTENSION; InitFile = Log.AppDir + System.IO.Path.DirectorySeparatorChar + FullName + "." + Config.FILE_EXTENSION; Attribute = settingsTypeMemberInfo.GetCustomAttributes <SettingsAttribute>(false).FirstOrDefault(); Indented = Attribute == null ? true : Attribute.Indented; }
protected SettingsMemberInfo(MemberInfo settingsTypeMemberInfo, Type type) { Type = type; FullName = settingsTypeMemberInfo.DeclaringType.FullName + "." + settingsTypeMemberInfo.Name; Settings s = (Settings)Activator.CreateInstance(Type); File = s.__StorageDir + System.IO.Path.DirectorySeparatorChar + FullName + "." + Config.FILE_EXTENSION; InitFile = Log.AppDir + System.IO.Path.DirectorySeparatorChar + FullName + "." + Config.FILE_EXTENSION; Attribute = settingsTypeMemberInfo.GetCustomAttributes <SettingsAttribute>(false).FirstOrDefault(); Indented = Attribute == null ? true : Attribute.Indented; }