public object GetValue(string name, RegistryValueOptions options) { if (IsMarkedForDeletion) { return(null); } if (name == null) { name = string.Empty; } object value = values [name]; ExpandString exp = value as ExpandString; if (exp == null) { return(value); } if ((options & RegistryValueOptions.DoNotExpandEnvironmentNames) == 0) { return(exp.Expand()); } return(exp.ToString()); }
void LoadKey(SecurityElement se) { Hashtable h = se.Attributes; try { string name = (string)h ["name"]; if (name == null) { return; } string type = (string)h ["type"]; if (type == null) { return; } switch (type) { case "int": values [name] = Int32.Parse(se.Text); break; case "bytearray": values [name] = Convert.FromBase64String(se.Text); break; case "string": values [name] = se.Text == null ? String.Empty : se.Text; break; case "expand": values [name] = new ExpandString(se.Text); break; case "qword": values [name] = Int64.Parse(se.Text); break; case "string-array": var sa = new List <string> (); if (se.Children != null) { foreach (SecurityElement stre in se.Children) { sa.Add(stre.Text); } } values [name] = sa.ToArray(); break; } } catch { // We ignore individual errors in the file. } }
public object GetValue(string name, RegistryValueOptions options) { if (this.IsMarkedForDeletion) { return(null); } if (name == null) { name = string.Empty; } object obj = this.values[name]; ExpandString expandString = obj as ExpandString; if (expandString == null) { return(obj); } if ((options & RegistryValueOptions.DoNotExpandEnvironmentNames) == RegistryValueOptions.None) { return(expandString.Expand()); } return(expandString.ToString()); }
// // This version has to do argument validation based on the valueKind // public void SetValue (string name, object value, RegistryValueKind valueKind) { SetDirty (); if (name == null) name = string.Empty; switch (valueKind){ case RegistryValueKind.String: if (value is string){ values [name] = value; return; } break; case RegistryValueKind.ExpandString: if (value is string){ values [name] = new ExpandString ((string)value); return; } break; case RegistryValueKind.Binary: if (value is byte []){ values [name] = value; return; } break; case RegistryValueKind.DWord: try { values [name] = Convert.ToInt32 (value); return; } catch (OverflowException) { break; } case RegistryValueKind.MultiString: if (value is string []){ values [name] = value; return; } break; case RegistryValueKind.QWord: try { values [name] = Convert.ToInt64 (value); return; } catch (OverflowException) { break; } default: throw new ArgumentException ("unknown value", "valueKind"); } throw new ArgumentException ("Value could not be converted to specified type", "valueKind"); }
void LoadKey (SecurityElement se) { Hashtable h = se.Attributes; try { string name = (string) h ["name"]; if (name == null) return; string type = (string) h ["type"]; if (type == null) return; switch (type){ case "int": values [name] = Int32.Parse (se.Text); break; case "bytearray": values [name] = Convert.FromBase64String (se.Text); break; case "string": values [name] = se.Text == null ? String.Empty : se.Text; break; case "expand": values [name] = new ExpandString (se.Text); break; case "qword": values [name] = Int64.Parse (se.Text); break; case "string-array": var sa = new List<string> (); if (se.Children != null){ foreach (SecurityElement stre in se.Children){ sa.Add (stre.Text); } } values [name] = sa.ToArray (); break; } } catch { // We ignore individual errors in the file. } }
// // This version has to do argument validation based on the valueKind // public void SetValue(string name, object value, RegistryValueKind valueKind) { SetDirty(); if (name == null) { name = string.Empty; } lock (values){ switch (valueKind) { case RegistryValueKind.String: if (value is string) { values [name] = value; return; } break; case RegistryValueKind.ExpandString: if (value is string) { values [name] = new ExpandString((string)value); return; } break; case RegistryValueKind.Binary: if (value is byte []) { values [name] = value; return; } break; case RegistryValueKind.DWord: try { values [name] = Convert.ToInt32(value); return; } catch (OverflowException) { break; } case RegistryValueKind.MultiString: if (value is string []) { values [name] = value; return; } break; case RegistryValueKind.QWord: try { values [name] = Convert.ToInt64(value); return; } catch (OverflowException) { break; } default: throw new ArgumentException("unknown value", "valueKind"); } } throw new ArgumentException("Value could not be converted to specified type", "valueKind"); }
// // This version has to do argument validation based on the valueKind // public void SetValue (string name, object value, RegistryValueKind valueKind) { SetDirty (); if (name == null) name = string.Empty; switch (valueKind){ case RegistryValueKind.String: if (value is string){ values [name] = value; return; } break; case RegistryValueKind.ExpandString: if (value is string){ values [name] = new ExpandString ((string)value); return; } break; case RegistryValueKind.Binary: if (value is byte []){ values [name] = value; return; } break; case RegistryValueKind.DWord: if (value is long && (((long) value) < Int32.MaxValue) && (((long) value) > Int32.MinValue)){ values [name] = (int) ((long)value); return; } if (value is int){ values [name] = value; return; } break; case RegistryValueKind.MultiString: if (value is string []){ values [name] = value; return; } break; case RegistryValueKind.QWord: if (value is int){ values [name] = (long) ((int) value); return; } if (value is long){ values [name] = value; return; } break; default: throw new ArgumentException ("unknown value", "valueKind"); } throw new ArgumentException ("Value could not be converted to specified type", "valueKind"); }
// // This version has to do argument validation based on the valueKind // public void SetValue(string name, object value, RegistryValueKind valueKind) { SetDirty(); if (name == null) { name = string.Empty; } switch (valueKind) { case RegistryValueKind.String: if (value is string) { values [name] = value; return; } break; case RegistryValueKind.ExpandString: if (value is string) { values [name] = new ExpandString((string)value); return; } break; case RegistryValueKind.Binary: if (value is byte []) { values [name] = value; return; } break; case RegistryValueKind.DWord: if (value is long && (((long)value) < Int32.MaxValue) && (((long)value) > Int32.MinValue)) { values [name] = (int)((long)value); return; } if (value is int) { values [name] = value; return; } break; case RegistryValueKind.MultiString: if (value is string []) { values [name] = value; return; } break; case RegistryValueKind.QWord: if (value is int) { values [name] = (long)((int)value); return; } if (value is long) { values [name] = value; return; } break; default: throw new ArgumentException("unknown value", "valueKind"); } throw new ArgumentException("Value could not be converted to specified type", "valueKind"); }