これを試すために新プラグインをさわったと言っても過言ではない。先のWindows Live Writer、Publish Notification Hookプラグインの通常の想定される使い方は、Blogや投稿記事の内容を参照するだけの処理になります。つまり、プラグインが記事を編集することは考えられていないということ。でも、できちゃうらしいってのが今回の話し。

 記事の内容が格納されているIPostInfoオブジェクトのプロパティは全部、読み取り専用です。ですが、リフレクションによって書き換えができるらしい。できました。

 IPostInfo.Contentsプロパティでは、HTML形式の文字列となった投稿記事が参照できます。それを書き換えたのが以下。なるほどー。記事のタイトル(”Title”)も同様に変更できます。

Public Overrides Function OnPrePublish(ByVal dialogOwner As IWin32Window, ByVal properties As IProperties, ByVal publishingContext As IPublishingContext, ByVal publish As Boolean) As Boolean
    Dim info = publishingContext.PostInfo.GetType.GetProperty("Contents")
    Dim contents = DirectCast(info.GetValue(publishingContext.PostInfo, Nothing), String)
    info.SetValue(publishingContext.PostInfo, contents.Replace("ー", "━(゜∀゜)━"), Nothing)

    Return True
End Function

 ポイントはpublishingContext.PostInfoからTypeを取得してるところでしょうか。GetType(IPostInfo) のように取得すると書き換えできません。GetValueメソッドによりプロパティ値を取得したけど、これ普通に参照すればいいじゃん……。

 WLW自体は書き換えられることを想定してないので、プラグインから書き換えても投稿後にエディタ中の表示は変化しません。

フィードバック

#  publish notification hooks???post??????????????????????????????????????? - SharpLab.

2008/12/17 11:00 by Pingback/TrackBack
publish notification hooks???post??????????????????????????????????????? - SharpLab.

#  Windows Live Writer??????????????????????????????????????????????????????????????????????????????????????? - SharpLab.

2009/04/10 15:57 by Pingback/TrackBack
Windows Live Writer??????????????????????????????????????????????????????????????????????????????????????? - SharpLab.
コメントの入力
タイトル
 
名前
 
Url
コメント