如何通过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>= ...
-
如何使用VBA从Excel中的条件格式获取背景颜色(How to get the background color from a Conditional Formatting in Excel using VBA)[2023-09-09]
如果您想知道已通过条件格式规则(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% (我相信你可以使用% ...
-
Excel中的条件格式(Conditional Formatting in Excel)[2022-10-16]
最简单的方法是在工作表上的某个单元格中创建列表。 然后你使用命名范围的能力为它命名,比如说这个例子是ValidList。 您可以通过选择列表为其命名,然后转到“插入”菜单并选择“名称” - >“定义”,然后输入名称并单击“确定”。 然后,您将转到问题单元格(我们将在此示例中使用A1),选择它,然后转到数据验证菜单。 选择列表选项时,请为源输入以下内容: =ValidList 然后选择单元格,进入条件格式,选择公式选项,然后输入以下公式,以及所需的结果: =ISERROR(MATCH(A1, ValidLi ... -
使用vba创建“色阶”(避免条件格式化)(Creating a “color scale” using vba (avoiding conditional formatting))[2023-02-19]
以下函数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