override public string ValidateAndSerialize() { if (this.UiPosition == null) { throw new ArgumentNullException("UiPosition"); } if (this.UiPosition.GroupBox == null) { throw new ArgumentNullException("GroupBox"); } if (string.IsNullOrEmpty(this.UiPosition.GroupBox.Name)) { throw new Exception("GroupBox.Name should not be null or empty"); } if (!NameValidationHelper.IsValidIdentifierName(this.UiPosition.GroupBox.Name)) { throw new Exception("GroupBox.Name is not a valid name"); } if (!string.IsNullOrEmpty(this.UiPosition.RibbonTabGroup.Name)) { if (!NameValidationHelper.IsValidIdentifierName(this.UiPosition.RibbonTabGroup.Name)) { throw new Exception("RibbonTabGroup.Name is not a valid name"); } } if (!string.IsNullOrEmpty(this.UiPosition.RibbonTab.Name)) { if (!NameValidationHelper.IsValidIdentifierName(this.UiPosition.RibbonTab.Name)) { throw new Exception("RibbonTab.Name is not a valid name"); } } return(Serialize()); }
/// <summary> /// Register Name-Object Map /// </summary> /// <param name="name">name to be registered</param> /// <param name="scopedElement">object mapped to name</param> public void RegisterName(string name, object scopedElement) { if (name == null) { throw new ArgumentNullException("name"); } if (scopedElement == null) { throw new ArgumentNullException("scopedElement"); } if (name == String.Empty) { throw new ArgumentException(SR.Get(SRID.NameScopeNameNotEmptyString)); } if (!NameValidationHelper.IsValidIdentifierName(name)) { throw new ArgumentException(SR.Get(SRID.NameScopeInvalidIdentifierName, name)); } if (_nameMap == null) { _nameMap = new HybridDictionary(); _nameMap[name] = scopedElement; } else { object nameContext = _nameMap[name]; // first time adding the Name, set it if (nameContext == null) { _nameMap[name] = scopedElement; } else if (scopedElement != nameContext) { throw new ArgumentException(SR.Get(SRID.NameScopeDuplicateNamesNotAllowed, name)); } } if (TraceNameScope.IsEnabled) { TraceNameScope.TraceActivityItem(TraceNameScope.RegisterName, this, name, scopedElement); } }
/// <summary>Registers a new name-object pair into the current XAML namescope.</summary> /// <param name="name">The name to use for mapping the given object.</param> /// <param name="scopedElement">The object to be mapped to the provided name.</param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="name" /> or <paramref name="scopedElement" /> was provided as null.</exception> /// <exception cref="T:System.ArgumentException"> /// <paramref name="name" /> was provided as empty string- or -<paramref name="name" /> provided was rejected by the parser, because it contained characters that are invalid for a XAML name- or -<paramref name="name" /> provided would result in a duplicate name registration.</exception> public void RegisterName(string name, object scopedElement) { if (name == null) { throw new ArgumentNullException("name"); } if (scopedElement == null) { throw new ArgumentNullException("scopedElement"); } if (name == string.Empty) { throw new ArgumentException(SR.Get("NameScopeNameNotEmptyString")); } if (!NameValidationHelper.IsValidIdentifierName(name)) { throw new ArgumentException(SR.Get("NameScopeInvalidIdentifierName", name)); } if (_nameMap == null) { _nameMap = new HybridDictionary { [name] = scopedElement }; } else { object obj = _nameMap[name]; if (obj == null) { _nameMap[name] = scopedElement; } else if (scopedElement != obj) { throw new ArgumentException(SR.Get("NameScopeDuplicateNamesNotAllowed", name)); } } if (TraceNameScope.IsEnabled) { TraceNameScope.TraceActivityItem(TraceNameScope.RegisterName, this, name, scopedElement); } }