首页 \ 问答 \ 如何通过IInterceptionBehavior吞下Exception?(How to swallow Exception by IInterceptionBehavior?)

如何通过IInterceptionBehavior吞下Exception?(How to swallow Exception by IInterceptionBehavior?)

我有一个类似于打击的IInterceptionBehavior:

public class TraceBehavior : IInterceptionBehavior
{
    public IEnumerable<Type> GetRequiredInterfaces()
    {
        return Type.EmptyTypes;
    }

    public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
    {
        Console.WriteLine(string.Format("Invoke method:{0}",input.MethodBase.ToString()));
        IMethodReturn result = getNext()(input, getNext);
        if (result.Exception == null)
        {
            Console.WriteLine("Invoke successful!");
        }
        else 
        {
            Console.WriteLine(string.Format("Invoke faild, error: {0}", result.Exception.Message));
            result.Exception = null;
        }
        return result;
    }

    public bool WillExecute { get { return true; } }
}

不管我是否把它放在方法上,总是抛出异常。 有人可以帮帮我吗?


I have a IInterceptionBehavior like blow:

public class TraceBehavior : IInterceptionBehavior
{
    public IEnumerable<Type> GetRequiredInterfaces()
    {
        return Type.EmptyTypes;
    }

    public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
    {
        Console.WriteLine(string.Format("Invoke method:{0}",input.MethodBase.ToString()));
        IMethodReturn result = getNext()(input, getNext);
        if (result.Exception == null)
        {
            Console.WriteLine("Invoke successful!");
        }
        else 
        {
            Console.WriteLine(string.Format("Invoke faild, error: {0}", result.Exception.Message));
            result.Exception = null;
        }
        return result;
    }

    public bool WillExecute { get { return true; } }
}

Regardless of whether I put it upon methods or not, exception throw always. Anyone can help me?


原文:https://stackoverflow.com/questions/8036559
更新时间:2023-04-19 09:04

最满意答案

您可以使用:

DisplayFormat.Interior.Color

获得细胞颜色。 其他CF属性也可以通过DisplayFormat访问


You can use:

DisplayFormat.Interior.Color

to get the cell color. Other CF properties are also accessible via DisplayFormat

相关问答

更多
  • 这会让你为你的简单案例找到答案,但是你能否扩展你将如何知道需要比较哪些列(在这种情况下是B和C)以及初始范围(本例中为A1:D5 )将会? 然后我可以尝试提供更完整的答案。 Sub setCondFormat() Range("B3").Select With Range("B3:H63") .FormatConditions.Add Type:=xlExpression, Formula1:= _ "=IF($D3="""",FALSE,IF($F3>= ...
  • 如果您想知道已通过条件格式规则(CFR) 着色的单元格的颜色,请使用.Range.DisplayFormat.Interior.Color¹。 如果你想明确地知道一个单元格可能是或者可能没有被 CFR 着色的颜色 ,你需要遍历可能影响该单元格的CFR并查看每个.Range.FormatConditions( x ).Interior.Color 。 ¹ 注意:.DisplayFormat不适用于工作表UDF。 If you want to know the color of a cell that has ...
  • 如果没有提供更好的答案,则可以尝试此解决方法: 将数据链接/复制到图表下的单元格(使用公式如=Sheet1!A1 ) 应用相同的条件格式 隐藏值(使用自定义数字格式,如"" ,即空字符串(2个双引号)) 使图表透明 将单元格与图表对齐 更新 : 或者如果条件格式仅使用2个基色(r1,g1,b1)和(r2,g2,b2)来处理2个角落情况,则可以尝试通过对每个R,G,B通道进行线性近似来计算颜色 min和max ,例如:0 - 4 000 min和max 百分比 ,例如:10% - 90% (我相信你可以使用% ...
  • 最简单的方法是在工作表上的某个单元格中创建列表。 然后你使用命名范围的能力为它命名,比如说这个例子是ValidList。 您可以通过选择列表为其命名,然后转到“插入”菜单并选择“名称” - >“定义”,然后输入名称并单击“确定”。 然后,您将转到问题单元格(我们将在此示例中使用A1),选择它,然后转到数据验证菜单。 选择列表选项时,请为源输入以下内容: =ValidList 然后选择单元格,进入条件格式,选择公式选项,然后输入以下公式,以及所需的结果: =ISERROR(MATCH(A1, ValidLi ...
  • 以下函数CalcColorScale将返回给定任意两种颜色和比例的颜色。比例是当前数据相对于数据范围的值。 例如,如果您的数据是从0到200,那么数据值100将按比例缩放50%(.5) 该图像显示红色和蓝色之间缩放的结果 Public Sub Test() ' Sets cell A1 to background purple Sheet1.Range("A1").Interior.Color = CalcColorScale(rgbRed, rgbBlue, 0.5) End Sub ' ...
  • 更改单元格的背景颜色很简单。 确定改变它的颜色是这里的关键步骤。 如果您知道这4种颜色是唯一的选择,我只会敲出案例并设置颜色。 如果您发现这种颜色越来越多,您可能希望在Dictionary中定义它们并执行查找而不是SELECT-CASE构造。 这个简单的代码适用于您的示例。 您将需要根据您的实际应用更好地定义范围(可能不是“D2:D5”)并调整颜色。 Sub ColorWithText() Dim cell As Range For Each cell In Range("D2:D5") ...
  • 听起来您的数据是数字,但Excel将其视为文本。 这是解决问题的方法: 找到一些空白单元格并输入数字0。 复制该单元格(Ctrl-C)。 选择有问题的数据单元格并使用以下设置执行“选择性粘贴”:从“粘贴”部分选择“值”,然后从“操作”部分选择“添加”,单击“确定”。 这可以通过向每个单元格添加零来实现,这些单元格不会更改其值,但会强制Excel将它们视为数字。 It sounds like your data is numeric, but Excel sees it as text. Here's a w ...
  • =IF(LARGE(A$1:A$15;COUNTIF(A$1:A$15;MAX(A$1:A$15))+2)<=A1;1;0) 如果数据的第一个单元格位于单元格A1,那么这就是公式。 将公式复制到具有足够空间的空单元格中,以将其扩展为15 * 20矩阵。 总结所有行,你会得到你想要的结果;) 如果需要,您可以隐藏用于计算最终结果的列! 要对最小值执行相同操作,您只需使用SMALL而不是LARGE ,并更改COUNTIF的条件: =IF(SMALL(A$1:A$15;COUNTIF(A$1:A$15;MIN( ...
  • 在Excel 2010+中,您可以遍历单元格,使用DisplayFormat.Interior.Color查找CF颜色,并将Interior.Color设置为该值,然后删除所有CF. Sub CopyCfFills() Dim rng As Range, c As Range 'Get all cells with CF: `On Error Resume Next` ignores error if no cells On Error Resume Next Set r ...
  • 您可以使用: DisplayFormat.Interior.Color 获得细胞颜色。 其他CF属性也可以通过DisplayFormat访问 You can use: DisplayFormat.Interior.Color to get the cell color. Other CF properties are also accessible via DisplayFormat

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。