/// <summary> /// Static creator: deserialize instance from binary stream. /// </summary> public static HybridText Deserialize(BinReader br) { // Read number of runs short length = br.ReadShort(); // Zero runs: return one and only "empty" object if (length == 0) { return(Empty); } // OK, deserialize runs. List <TextRun> runs = new List <TextRun>(length); // Deserialize each run after looking at flags for polymorphism for (short i = 0; i != length; ++i) { byte flags = br.ReadByte(); bool isZho = ((flags & 1) == 1); TextRun tr; if (isZho) { tr = new TextRunZho(br); } else { tr = new TextRunLatin(br); } runs.Add(tr); } // Done return(new HybridText(new ReadOnlyCollection <TextRun>(runs))); }
/// <summary> /// Initializes a pure plain-text instance. /// </summary> public HybridText(string plain) { runs = new List <TextRun>(1); TextRunLatin run = new TextRunLatin(plain); runs.Add(run); }
/// <summary> /// Returns true if object is a single plain text run that equals provided string. /// </summary> public bool EqualsPlainText(string what) { if (runs.Count != 1) { return(false); } TextRunLatin trl = runs[0] as TextRunLatin; if (trl == null) { return(false); } return(trl.GetPlainText() == what); }