/// <summary> /// Sets the member of dom specified by name to val. /// If a member with the specified name does not exist an ArgumentException will be thrown. /// </summary> public void SetValue(DocumentObject dom, string name, object val) { int dot = name.IndexOf('.'); if (dot == 0) { throw new ArgumentException(DomSR.InvalidValueName(name)); } string trail = null; if (dot > 0) { trail = name.Substring(dot + 1); name = name.Substring(0, dot); } ValueDescriptor vd = _vds[name]; if (vd == null) { throw new ArgumentException(DomSR.InvalidValueName(name)); } if (trail != null) { //REVIEW DaSt: dom.GetValue(name) and call SetValue recursively, // or dom.GetValue(name.BisVorletzteElement) and then call SetValue? DocumentObject doc = (DocumentObject)dom.GetValue(name); doc.SetValue(trail, val); } else { vd.SetValue(dom, val); } }
/// <summary> /// Sets the member of dom specified by name to val. /// If a member with the specified name does not exist an ArgumentException will be thrown. /// </summary> public void SetValue(DocumentObject dom, string name, object val) { int dot = name.IndexOf('.'); if (dot == 0) { throw new ArgumentException(DomSR.InvalidValueName(name)); } string trail = null; if (dot > 0) { trail = name.Substring(dot + 1); name = name.Substring(0, dot); } ValueDescriptor vd = this.vds[name]; if (vd == null) { throw new ArgumentException(DomSR.InvalidValueName(name)); } if (trail != null) { //REVIEW DaSt: dom.GetValue(name) und rekursiv SetValue aufrufen, // oder dom.GetValue(name.BisVorletzteElement) und erst SetValue aufrufen. DocumentObject doc = dom.GetValue(name) as DocumentObject; doc.SetValue(trail, val); } else { vd.SetValue(dom, val); } }
/// <summary> /// Converts BookmarkField into DDL. /// </summary> public override void Serialize(Serializer serializer) { if (_name.Value == string.Empty) { throw new InvalidOperationException(DomSR.MissingObligatoryProperty("Name", "BookmarkField")); } serializer.Write("\\field(Bookmark)[Name = \"" + Name.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"]"); }
/// <summary> /// Sets the member of dom specified by name to null. /// If a member with the specified name does not exist an ArgumentException will be thrown. /// </summary> public void SetNull(DocumentObject dom, string name) { ValueDescriptor vd = _vds[name]; if (vd == null) { throw new ArgumentException(DomSR.InvalidValueName(name)); } vd.SetNull(dom); }
/// <summary> /// Converts InfoField into DDL. /// </summary> internal override void Serialize(Serializer serializer) { string str = "\\field(Info)"; if (this.Name == "") { throw new InvalidOperationException(DomSR.MissingObligatoryProperty("Name", "InfoField")); } str += "[Name = \"" + this.Name + "\"]"; serializer.Write(str); }
/// <summary> /// Sets the parent of the specified value. /// If a parent is already set, an ArgumentException will be thrown. /// </summary> protected void SetParent(DocumentObject documentObject) { if (documentObject != null) { if (documentObject.Parent != null) { throw new ArgumentException(DomSR.ParentAlreadySet(documentObject, this)); } documentObject.parent = this; } }
/// <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> /// Determines whether the member of dom specified by name is null. /// If a member with the specified name does not exist an ArgumentException will be thrown. /// </summary> public virtual bool IsNull(DocumentObject dom, string name) { //bool isNull = false; int dot = name.IndexOf('.'); if (dot == 0) { throw new ArgumentException(DomSR.InvalidValueName(name)); } string trail = null; if (dot > 0) { trail = name.Substring(dot + 1); name = name.Substring(0, dot); } ValueDescriptor vd = this.vds[name]; if (vd == null) { throw new ArgumentException(DomSR.InvalidValueName(name)); } if (vd is NullableDescriptor || vd is ValueTypeDescriptor) { if (trail != null) { throw new ArgumentException(DomSR.InvalidValueName(name)); } return(vd.IsNull(dom)); } DocumentObject docObj = (DocumentObject)vd.GetValue(dom, GV.ReadOnly); if (docObj == null) { return(true); } if (trail != null) { return(docObj.IsNull(trail)); } else { return(docObj.IsNull()); } // DomValueDescriptor vd = vds[name]; // if (vd == null) // throw new ArgumentException(DomSR.InvalidValueName(name)); // // return vd.IsNull(dom); }
/// <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(AppResources.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); } }
internal override void Serialize(XmlSerializer serializer) { if (_name.Value == string.Empty) { throw new InvalidOperationException(DomSR.MissingObligatoryProperty("Name", "BookmarkField")); } //serializer.Write("\\field(Bookmark)[Name = \"" + Name.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"]"); serializer.WriteStartElement("Field"); serializer.WriteSimpleAttribute("Name", Name); serializer.WriteSimpleAttribute("Type", "Bookmark"); serializer.WriteEndElement(); }
internal override void Serialize(XmlSerializer serializer) { serializer.WriteStartElement("Field"); serializer.WriteSimpleAttribute("Type", "Info"); //string str = "\\field(Info)"; if (Name == "") { throw new InvalidOperationException(DomSR.MissingObligatoryProperty("Name", "InfoField")); } //str += "[Name = \"" + Name + "\"]"; serializer.WriteSimpleAttribute("Name", Name); //serializer.Write(str); serializer.WriteEndElement(); }
/// <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> /// Gets the object specified by name from dom. /// </summary> public object GetValue(DocumentObject dom, string name, GV flags) { int dot = name.IndexOf('.'); if (dot == 0) { throw new ArgumentException(DomSR.InvalidValueName(name)); } string trail = null; if (dot > 0) { trail = name.Substring(dot + 1); name = name.Substring(0, dot); } ValueDescriptor vd = _vds[name]; if (vd == null) { throw new ArgumentException(DomSR.InvalidValueName(name)); } object value = vd.GetValue(dom, flags); if (value == null && flags == GV.GetNull) //??? also for GV.ReadOnly? { return(null); } //REVIEW DaSt: Create object in case of GV.ReadWrite? if (trail != null) { if (value == null || trail == "") { throw new ArgumentException(DomSR.InvalidValueName(name)); } DocumentObject doc = value as DocumentObject; if (doc == null) { throw new ArgumentException(DomSR.InvalidValueName(name)); } value = doc.GetValue(trail, flags); } return(value); }
/// <summary> /// Gets the object specified by name from dom. /// </summary> public object GetValue(DocumentObject dom, string name, GV flags) { int dot = name.IndexOf('.'); if (dot == 0) { throw new ArgumentException(DomSR.InvalidValueName(name)); } string trail = null; if (dot > 0) { trail = name.Substring(dot + 1); name = name.Substring(0, dot); } ValueDescriptor vd = this.vds[name]; if (vd == null) { throw new ArgumentException(DomSR.InvalidValueName(name)); } object value = vd.GetValue(dom, flags); if (value == null && flags == GV.GetNull) //??? oder auch GV.ReadOnly? { return(null); } //REVIEW DaSt: Sollte beim GV.ReadWrite das Objekt angelegt werden? if (trail != null) { if (value == null || trail == "") { throw new ArgumentException(DomSR.InvalidValueName(name)); } DocumentObject doc = value as DocumentObject; if (doc == null) { throw new ArgumentException(DomSR.InvalidValueName(name)); } value = doc.GetValue(trail, flags); } return(value); }
/// <summary> /// Converts Barcode into DDL. /// </summary> internal override void Serialize(Serializer serializer) { if (this.code.Value == "") { throw new InvalidOperationException(DomSR.MissingObligatoryProperty("Name", "BookmarkField")); } serializer.WriteLine("\\barcode(\"" + this.Code + "\")"); int pos = serializer.BeginAttributes(); base.Serialize(serializer); if (!this.orientation.IsNull) { serializer.WriteSimpleAttribute("Orientation", this.Orientation); } if (!this.bearerBars.IsNull) { serializer.WriteSimpleAttribute("BearerBars", this.BearerBars); } if (!this.text.IsNull) { serializer.WriteSimpleAttribute("Text", this.Text); } if (!this.type.IsNull) { serializer.WriteSimpleAttribute("Type", this.Type); } if (!this.lineRatio.IsNull) { serializer.WriteSimpleAttribute("LineRatio", this.LineRatio); } if (!this.lineHeight.IsNull) { serializer.WriteSimpleAttribute("LineHeight", this.LineHeight); } if (!this.narrowLineWidth.IsNull) { serializer.WriteSimpleAttribute("NarrowLineWidth", this.NarrowLineWidth); } serializer.EndAttributes(pos); }
internal override void Serialize(XmlSerializer serializer) { if (_code.Value == "") { throw new InvalidOperationException(DomSR.MissingObligatoryProperty("Name", "BookmarkField")); } serializer.WriteStartElement("Barcode"); serializer.WriteElement("Code", Code); //serializer.WriteLine("\\barcode(\"" + Code + "\")"); // int pos = serializer.BeginAttributes(); base.Serialize(serializer); /* * if (!_orientation.IsNull) * serializer.WriteSimpleAttribute("Orientation", Orientation); * if (!_bearerBars.IsNull) * serializer.WriteSimpleAttribute("BearerBars", BearerBars); * if (!_text.IsNull) * serializer.WriteSimpleAttribute("Text", Text); */ if (!_type.IsNull) { serializer.WriteSimpleAttribute("Type", Type); } /* * if (!_lineRatio.IsNull) * serializer.WriteSimpleAttribute("LineRatio", LineRatio); * if (!_lineHeight.IsNull) * serializer.WriteSimpleAttribute("LineHeight", LineHeight); * if (!_narrowLineWidth.IsNull) * serializer.WriteSimpleAttribute("NarrowLineWidth", NarrowLineWidth); */ serializer.WriteEndElement(); // barcode //serializer.EndAttributes(pos); }
public override object GetValue(DocumentObject dom, GV flags) { if (!Enum.IsDefined(typeof(GV), flags)) { throw new /*InvalidEnum*/ ArgumentException(DomSR.InvalidEnumValue(flags), "flags"); } #if !NETFX_CORE object val = FieldInfo != null?FieldInfo.GetValue(dom) : PropertyInfo.GetGetMethod(true).Invoke(dom, null); #else object val = FieldInfo != null?FieldInfo.GetValue(dom) : PropertyInfo.GetValue(dom); #endif INullableValue ival = val as INullableValue; if (ival != null && ival.IsNull && flags == GV.GetNull) { return(null); } return(val); }
/// <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 = 0; // 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 cause it's not a ColorName. } System.Globalization.NumberStyles numberStyle = System.Globalization.NumberStyles.Integer; string number = color.ToLower(); if (number.StartsWith("0x")) { numberStyle = System.Globalization.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 (this.name.Value == string.Empty) { throw new InvalidOperationException(DomSR.MissingObligatoryProperty("Name", "Hyperlink")); } serializer.Write("\\hyperlink"); string str = "[Name = \"" + this.Name.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\""; if (!this.type.IsNull) { str += " Type = " + this.Type; } str += "]"; serializer.Write(str); serializer.Write("{"); if (this.elements != null) { elements.Serialize(serializer); } serializer.Write("}"); }
public override object GetValue(DocumentObject dom, GV flags) { if (!Enum.IsDefined(typeof(GV), flags)) { throw new /*InvalidEnum*/ ArgumentException(DomSR.InvalidEnumValue(flags), "flags"); } FieldInfo fieldInfo = FieldInfo; DocumentObject val; if (fieldInfo != null) { // Member is a field val = FieldInfo.GetValue(dom) as DocumentObject; if (val == null && flags == GV.ReadWrite) { val = (DocumentObject)CreateValue(); val._parent = dom; FieldInfo.SetValue(dom, val); return(val); } } else { // Member is a property #if !NETFX_CORE val = PropertyInfo.GetGetMethod(true).Invoke(dom, null) as DocumentObject; #else val = PropertyInfo.GetValue(dom) as DocumentObject; #endif } if (val != null && (val.IsNull() && flags == GV.GetNull)) { return(null); } return(val); }
public override object GetValue(DocumentObject dom, GV flags) { if (!Enum.IsDefined(typeof(GV), flags)) { throw new /*InvalidEnum*/ ArgumentException(DomSR.InvalidEnumValue(flags), "flags"); } Debug.Assert(MemberInfo is FieldInfo, "Properties of DocumentObjectCollection not allowed."); DocumentObjectCollection val = FieldInfo.GetValue(dom) as DocumentObjectCollection; if (val == null && flags == GV.ReadWrite) { val = (DocumentObjectCollection)CreateValue(); val._parent = dom; FieldInfo.SetValue(dom, val); return(val); } if (val != null && val.IsNull() && flags == GV.GetNull) { return(null); } return(val); }
/// <summary> /// Scans regular string literals like ?String with \"escaped\" text"? /// </summary> protected string ScanStringLiteral() { Debug.Assert(Char == '\"'); StringBuilder str = new StringBuilder(); ScanNextChar(); while (_currChar != Chars.QuoteDbl && !IsEof(_currChar)) { if (_currChar == '\\') { ScanNextChar(); // read escaped characters switch (_currChar) { case 'a': str.Append('\a'); break; case 'b': str.Append('\b'); break; case 'f': str.Append('\f'); break; case 'n': str.Append('\n'); break; case 'r': str.Append('\r'); break; case 't': str.Append('\t'); break; case 'v': str.Append('\v'); break; case '\'': str.Append('\''); break; case '\"': str.Append('\"'); break; case '\\': str.Append('\\'); break; case 'x': { ScanNextChar(); int hexNrCount = 0; //string hexString = "0x"; while (IsHexDigit(_currChar)) { ++hexNrCount; //hexString += _currChar; ScanNextChar(); } if (hexNrCount <= 2) { str.Append("?????"); //(char)AscULongFromHexString(hexString); } else { throw new DdlParserException(DdlErrorLevel.Error, DomSR.GetString(DomMsgID.EscapeSequenceNotAllowed), DomMsgID.EscapeSequenceNotAllowed); } } break; //NYI: octal numbers //case '0': //{ // ScanNextChar(); // int hexNrCount = 0; // string hexString = "0x"; // while (IsOctDigit(currChar)) // { // ++hexNrCount; // hexString += currChar; // ScanNextChar(); // } // if (hexNrCount <=2) // str += "?????"; //(char)AscULongFromHexString(hexString); // else // throw new DdlParserException(DdlErrorLevel.Error, "DdlScanner",DomMsgID.EscapeSequenceNotAllowed, null); //} // break; default: throw new DdlParserException(DdlErrorLevel.Error, DomSR.GetString(DomMsgID.EscapeSequenceNotAllowed), DomMsgID.EscapeSequenceNotAllowed); } } else if (_currChar == Chars.Null || _currChar == Chars.CR || _currChar == Chars.LF) { throw new DdlParserException(DdlErrorLevel.Error, DomSR.GetString(DomMsgID.NewlineInString), DomMsgID.NewlineInString); } else { str.Append(_currChar); } ScanNextChar(); } ScanNextChar(); // read '"' return(str.ToString()); }