internal override void Serialize(XmlSerializer serializer) { if (_name.Value == string.Empty) { throw new InvalidOperationException(DomSR.MissingObligatoryProperty("Name", "Hyperlink")); } //serializer.Write("\\hyperlink"); serializer.WriteStartElement("Hyperlink"); //string str = "[Name = \"" + Name.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\""; serializer.WriteSimpleAttribute("Name", Name); if (!_type.IsNull) { //str += " Type = " + Type; serializer.WriteSimpleAttribute("Type", Type); } //str += "]"; //serializer.Write(str); //serializer.Write("{"); if (_elements != null) { _elements.Serialize(serializer); } //serializer.Write("}"); serializer.WriteEndElement(); // }
/// <summary> /// Loads the message from the resource associated with the enum type and formats it /// using 'String.Format'. Because this function is intended to be used during error /// handling it never raises an exception. /// </summary> /// <param name="id">The type of the parameter identifies the resource /// and the name of the enum identifies the message in the resource.</param> /// <param name="args">Parameters passed through 'String.Format'.</param> /// <returns>The formatted message.</returns> public static string FormatMessage(DomMsgID id, params object[] args) { string message; try { message = DomSR.GetString(id); if (message != null) { #if DEBUG if (Regex.Matches(message, @"\{[0-9]\}").Count > args.Length) { //TODO too many placeholders or too less args... } #endif message = String.Format(message, args); } else { message = "<<<error: message not found>>>"; } return(message); } catch (Exception ex) { message = "INTERNAL ERROR while formatting error message: " + ex.ToString(); } return(message); }
public Border GetBorderReadOnly(BorderType type) { switch (type) { case BorderType.Bottom: return(_bottom); case BorderType.DiagonalDown: return(_diagonalDown); case BorderType.DiagonalUp: return(_diagonalUp); case BorderType.Horizontal: case BorderType.Vertical: return((Border)GetValue(type.ToString(), GV.GetNull)); case BorderType.Left: return(_left); case BorderType.Right: return(_right); case BorderType.Top: return(_top); } if (!Enum.IsDefined(typeof(BorderType), type)) { throw new /*InvalidEnum*/ ArgumentException(DomSR.InvalidEnumValue(type), "type"); } return(null); }
/// <summary> /// Determines whether a particular border exists. /// </summary> public bool HasBorder(BorderType type) { if (!Enum.IsDefined(typeof(BorderType), type)) { throw new /*InvalidEnum*/ ArgumentException(DomSR.InvalidEnumValue(type), "type"); } return(GetBorderReadOnly(type) != null); }
/// <summary> /// Initializes a new instance of the Unit class. /// Throws System.ArgumentException if <code>type</code> is invalid. /// </summary> public Unit(double value, UnitType type) { if (!Enum.IsDefined(typeof(UnitType), type)) { throw new /*InvalidEnum*/ ArgumentException(DomSR.InvalidEnumValue(type), "type"); } _value = (float)value; _type = type; _initialized = true; }
/// <summary> /// Sets the parent of the specified value. /// If a parent is already set, an ArgumentException will be thrown. /// </summary> protected void SetParent(DocumentObject val) { if (val != null) { if (val.Parent != null) { throw new ArgumentException(DomSR.ParentAlreadySet(val, this)); } val.parent = this; } }
/// <summary> /// Adds a DocumentObject to the styles collection. /// </summary> public override void Add(DocumentObject value) { if (value == null) { throw new ArgumentNullException("value"); } Style style = value as Style; if (style == null) { throw new InvalidOperationException(DomSR.StyleExpected); } bool isRootStyle = style.IsRootStyle; if (style.BaseStyle == "" && !isRootStyle) { throw new ArgumentException(DomSR.UndefinedBaseStyle(style.BaseStyle)); } Style baseStyle = null; int styleIndex = GetIndex(style.BaseStyle); if (styleIndex != -1) { baseStyle = this[styleIndex] as Style; } else if (!isRootStyle) { throw new ArgumentException(DomSR.UndefinedBaseStyle(style.BaseStyle)); } if (baseStyle != null) { style.styleType.Value = (int)baseStyle.Type; } int index = GetIndex(style.Name); if (index >= 0) { style = style.Clone(); style.parent = this; ((IList)this)[index] = style; } else { base.Add(value); } NameIndex[style.Name] = style; }
/// <summary> /// Sets the parent of the specified value. /// If a parent is already set, an ArgumentException will be thrown. /// </summary> protected void SetParent(DocumentObject value) { if (value != null) { if (value.Parent != null) { throw new ArgumentException(DomSR.ParentAlreadySet(value, this)); } value._parent = this; value._document = null; value._section = null; } }
/// <summary> /// Converts an existing object from one unit into another unit type. /// </summary> public void ConvertType(UnitType type) { if (this.type == type) { return; } if (!Enum.IsDefined(typeof(UnitType), type)) { throw new ArgumentException(DomSR.InvalidUnitType(type.ToString())); } switch (type) { case UnitType.Centimeter: this.value = (float)this.Centimeter; this.type = UnitType.Centimeter; break; case UnitType.Inch: this.value = (float)this.Inch; this.type = UnitType.Inch; break; case UnitType.Millimeter: this.value = (float)this.Millimeter; this.type = UnitType.Millimeter; break; case UnitType.Pica: this.value = (float)this.Pica; this.type = UnitType.Pica; break; case UnitType.Point: this.value = (float)this.Point; this.type = UnitType.Point; break; default: //Remember missing unit type!!! Debug.Assert(false, "Missing unit type"); break; } }
/// <summary> /// Converts Hyperlink into DDL. /// </summary> internal override void Serialize(Serializer serializer) { serializer.Write("\\hyperlink"); var str = "["; if (Type == HyperlinkType.ExternalBookmark || Type == HyperlinkType.File || Type == HyperlinkType.Url) { if (_filename.Value == string.Empty) { throw new InvalidOperationException(DomSR.MissingObligatoryProperty("Filename", $"Hyperlink {Type.ToString()}")); } str += " Filename = \"" + Filename.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\""; } if (Type == HyperlinkType.ExternalBookmark || Type == HyperlinkType.Bookmark || Type == HyperlinkType.EmbeddedDocument) { if (_bookmarkName.Value == string.Empty) { throw new InvalidOperationException(DomSR.MissingObligatoryProperty("BookmarkName", $"Hyperlink {Type.ToString()}")); } str += " BookmarkName = \"" + BookmarkName.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\""; } if (Type == HyperlinkType.ExternalBookmark || Type == HyperlinkType.EmbeddedDocument) { str += " NewWindow = " + NewWindow; } if (!_type.IsNull) { str += " Type = " + Type; } str += "]"; serializer.Write(str); serializer.Write("{"); if (_elements != null) { _elements.Serialize(serializer); } serializer.Write("}"); }
/// <summary> /// Parses the string and returns a color object. /// Throws ArgumentException if color is invalid. /// </summary> /// <param name="color">integer, hex or color name.</param> public static Color Parse(string color) { if (color == null) { throw new ArgumentNullException("color"); } if (color == "") { throw new ArgumentException("color"); } try { uint clr; // Must use Enum.Parse because Enum.IsDefined is case sensitive try { object obj = Enum.Parse(typeof(ColorName), color, true); clr = (uint)obj; return(new Color(clr)); } catch { // Ignore exception because it's not a ColorName. } NumberStyles numberStyle = NumberStyles.Integer; string number = color.ToLower(); if (number.StartsWith("0x")) { numberStyle = NumberStyles.HexNumber; number = color.Substring(2); } clr = uint.Parse(number, numberStyle); return(new Color(clr)); } catch (FormatException ex) { throw new ArgumentException(DomSR.InvalidColorString(color), ex); } }
/// <summary> /// Converts Hyperlink into DDL. /// </summary> internal override void Serialize(Serializer serializer) { if (_name.Value == string.Empty) { throw new InvalidOperationException(DomSR.MissingObligatoryProperty("Name", "Hyperlink")); } serializer.Write("\\hyperlink"); string str = "[Name = \"" + Name.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\""; if (!_type.IsNull) { str += " Type = " + Type; } str += "]"; serializer.Write(str); serializer.Write("{"); if (_elements != null) { _elements.Serialize(serializer); } serializer.Write("}"); }
public static string InvalidFieldFormat(string format) { return(DomSR.FormatMessage(DomMsgID.InvalidFieldFormat, format)); }
public static string InvalidValueName(string name) { return(DomSR.FormatMessage(DomMsgID.InvalidValueName, name)); }
public static string InvalidUnitType(string unitType) { return(DomSR.FormatMessage(DomMsgID.InvalidUnitType, unitType)); }
public static string InvalidColorString(string colorString) { return(DomSR.FormatMessage(DomMsgID.InvalidColorString, colorString)); }
public static string InvalidFontSize(double value) { return(DomSR.FormatMessage(DomMsgID.InvalidFontSize, value)); }
public static string UndefinedBaseStyle(string baseStyle) { return(DomSR.FormatMessage(DomMsgID.UndefinedBaseStyle, baseStyle)); }