本文整理汇总了C#中Function.HasCustomAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# Function.HasCustomAttribute方法的具体用法?C# Function.HasCustomAttribute怎么用?C# Function.HasCustomAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Function
的用法示例。
在下文中一共展示了Function.HasCustomAttribute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invoke
public void Invoke(Function function)
{
bool bMissingExpectedException = false;
try
{
function.Invoke();
if(function.HasCustomAttribute("NUnit.Framework.ExpectedExceptionAttribute"))
{
bMissingExpectedException = true;
}
}
catch (System.Exception ex)
{
if (!ConsumeExpectedException(function, ex))
{
System.Exception nunitEx = GetNUnitException(ex);
if (nunitEx != null)
{
throw nunitEx;
}
else
{
throw;
}
}
}
if (bMissingExpectedException)
{
System.Exception e = new System.Exception("Test failed to throw exception of type " + GetExpectedExceptionName(function) + " when it was expected to.");
throw e;
}
}
示例2: GetExpectedExceptionType
private Type GetExpectedExceptionType(Function function)
{
if (function.HasCustomAttribute("NUnit.Framework.ExpectedExceptionAttribute"))
{
System.Attribute pAttributeExpectedException = function.GetAttribute("NUnit.Framework.ExpectedExceptionAttribute");
if (pAttributeExpectedException != null)
{
System.Type pExpectedExceptionType = GetExpectedExceptionType(function, pAttributeExpectedException);
return pExpectedExceptionType;
}
}
return null;
}
示例3: ConsumeExpectedException
private bool ConsumeExpectedException(Function function, System.Exception pEx)
{
if (function.HasCustomAttribute("NUnit.Framework.ExpectedExceptionAttribute"))
{
System.Attribute pAttributeExpectedException = function.GetAttribute("NUnit.Framework.ExpectedExceptionAttribute");
if (pAttributeExpectedException != null)
{
System.Type pExpectedExceptionType = GetExpectedExceptionType(function, pAttributeExpectedException);
if (pExpectedExceptionType != null)
{
string pExpectedExceptionName = (System.String)function.GetProperty(pExpectedExceptionType, "FullName");
string pExpectedMessage = (System.String)function.GetProperty(pAttributeExpectedException, "ExpectedMessage");
if (pExpectedExceptionName != null)
{
System.Exception pTestEx = pEx;
while (pTestEx != null)
{
if (pTestEx.ToString().StartsWith(pExpectedExceptionName))
{
if ((pExpectedMessage == null) || (pTestEx.Message.CompareTo(pExpectedMessage) == 0))
{
return true;
}
}
pTestEx = pTestEx.InnerException;
}
}
}
}
}
return false;
}