throwtypedexception.cs

来自「WF本质论一书的源码,要书籍的朋友同我联系.」· CS 代码 · 共 35 行

CS
35
字号
using System;
using System.Workflow.ComponentModel;

namespace EssentialWF.Activities {
    public class ThrowTypedFault : Activity {
        internal static readonly DependencyProperty FaultTypeProperty = DependencyProperty.Register("FaultType",typeof(Type),typeof(ThrowTypedFault),new PropertyMetadata(DependencyPropertyOptions.Metadata));

        public static readonly DependencyProperty FaultMessageProperty = DependencyProperty.Register("FaultMessage",typeof(string),typeof(ThrowTypedFault));

        public Type FaultType {
            get {
                return base.GetValue(FaultTypeProperty) as Type;
            }
            set {
                base.SetValue(FaultTypeProperty, value);
            }
        }

        public string FaultMessage {
            get {
                return base.GetValue(FaultMessageProperty) as string;
            }
            set {
                base.SetValue(FaultMessageProperty, value);
            }
        }
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext context) {
            System.Reflection.ConstructorInfo c = FaultType.GetConstructor(new Type[] { typeof(System.String) } );
            Exception e = c.Invoke(new object[] { FaultMessage }) as Exception;

            throw e;
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?