public void Test() { // 建立对象,并对其进行两次装饰。 bold = false, color= black IText text = new TextObject(); text = new BoldDecorator(text); text = new ColorDecorator(text); Assert.AreEqual <string>("<Black>hello</Black>", text.Content); // 动态找到需要更新的Decorator并修改相应属性 // bold = false, color = red ColorState newColorState = new ColorState(); newColorState.Color = Color.Red; IDecorator root = (IDecorator)text; root.Refresh <ColorDecorator>(newColorState); Assert.AreEqual <string>("<Red>hello</Red>", text.Content); // 动态找到需要更新的Decorator并修改相应属性 // bold = true, color = red BoldState newBoldState = new BoldState(); newBoldState.IsBold = true; root.Refresh <BoldDecorator>(newBoldState); Assert.AreEqual <string>("<Red><b>hello</b></Red>", text.Content); }
private void InstructionToolStripMenuItem_Click(object sender, EventArgs e) { var instructionTextBlock = new BoldDecorator(new ListDecorator(new PlainTextBlock())); currentGuide.Add(instructionTextBlock); EditTextBlock(instructionTextBlock); isCurrentGuideDirty = true; }
public void Test() { // 建立对象,并对其进行两次装饰 IText text = new TextObject(); text = new BoldDecorator(text); text = new ColorDecorator(text); Assert.AreEqual <string>("<color><b>hello</b></color>", text.Content); // 建立对象,只对其进行1次装饰 text = new TextObject(); text = new ColorDecorator(text); Assert.AreEqual <string>("<color>hello</color>", text.Content); // 通过装饰,撤销某些操作 text = new BlockAllDecorator(text); Assert.IsTrue(string.IsNullOrEmpty(text.Content)); }
public void Test() { //建立对象,并对其进行两次装饰 IText text = new TextObject(); text = new BoldDecorator(text); text = new ColorDecorator(text); Assert.AreEqual("<color><b>Hello<b/><color/>", text.Content); //建立对象,并对其进行一次装饰 text = new TextObject(); text = new ColorDecorator(text); Assert.AreEqual("<color>Hello<color/>", text.Content); //通过装饰,撤销某些操作 text = new BlockAllDecorator(text); Assert.IsTrue(string.IsNullOrEmpty(text.Content)); }
public virtual StringBuilder Represent(BoldDecorator text, ILanguage language) { return(representDecorator(text, language, "<b>", "</b>")); }