Example #1
0
 /// <summary>
 /// 文字を処理する関数を登録します。
 /// </summary>
 /// <param name="letter">
 /// 処理する対象の文字
 /// "*default" を指定すると、登録されていない文字に対する処理を設定出来ます。
 /// 既に登録されている物に対しては、上書きを行います。
 /// </param>
 /// <param name="lh">
 /// 登録しようとしている関数。GetLHType() で指定されている型の delegate を指定して下さい。
 /// 内部で文字を次に進めるか文脈終了要求を提出する必要があります。
 /// <code>
 /// void HandleA(mwg.Parse.Document doc){
 ///		doc.Next();//文字を次に進める
 /// }
 ///	void HandleRightBracket(mwg.Parse.Document doc){
 ///		doc.CurrentContext.EOC=true;//文脈終了要求を出す。
 ///	}
 ///	</code>
 /// </param>
 public void AddLetterHandler(string letter, System.Delegate lh)
 {
     if (lh.GetType() != this.GetLHType())
     {
         throw new System.Exception("delegate の種類が異なる為登録出来ません");
     }
     if (this.hLttr.Contains(letter))
     {
         this.hLttr[letter] = lh;
     }
     else
     {
         this.hLttr.Add(letter, lh);
     }
 }
Example #2
0
        public static System.Delegate ConvertTo(this System.Delegate self, System.Type type)
        {
            if (type == null)
            {
                throw new System.ArgumentNullException("type");
            }
            if (self == null)
            {
                return(null);
            }

            if (self.GetType() == type)
            {
                return(self);
            }

            return(System.Delegate.Combine(
                       self.GetInvocationList()
                       .Select(i => System.Delegate.CreateDelegate(type, i.Target, i.Method))
                       .ToArray()));
        }