private static void SaveEntity(Type type, object entity, RegistryKey root) { var entityAttribute = type.GetCustomAttribute <RegistryEntityAttribute>(); if (entityAttribute == null) { throw new MissingAttributeException(type, typeof(RegistryEntityAttribute)); } var properties = type.GetProperties().Select(x => { return(new { PropertyInfo = x, FieldAttribute = x.GetCustomAttribute <RegistryFieldAttribute>() }); }).Where(x => x.FieldAttribute != null).ToArray(); var registryKey = root.OpenSubKey(RootPath + entityAttribute.Path, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.WriteKey | RegistryRights.ReadKey | RegistryRights.CreateSubKey | RegistryRights.SetValue); try { if (registryKey == null) { registryKey = root.CreateSubKey(RootPath + entityAttribute.Path, RegistryKeyPermissionCheck.ReadWriteSubTree); } //TODO subentities foreach (var property in properties) { var pi = property.PropertyInfo; var e1 = new RegistryFieldGetPropertyValueParameters(type, pi, entity); var propertyValue = property.FieldAttribute.GetPropertyValue(e1); var e2 = new RegistryFieldSettingRegistryValueParameters(registryKey, type, pi, propertyValue); property.FieldAttribute.SettingRegistryValue(e2); property.FieldAttribute.SetRegistryValue(new RegistryFieldSetRegistryValueParameters(registryKey, type, pi, e2.Value)); } } finally { if (registryKey != null) { registryKey.Dispose(); } } }
internal protected virtual void SettingRegistryValue(RegistryFieldSettingRegistryValueParameters e) { }