本文整理汇总了C#中System.Compiler.TypeNode.IsAssignableTo方法的典型用法代码示例。如果您正苦于以下问题:C# TypeNode.IsAssignableTo方法的具体用法?C# TypeNode.IsAssignableTo怎么用?C# TypeNode.IsAssignableTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Compiler.TypeNode
的用法示例。
在下文中一共展示了TypeNode.IsAssignableTo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandlersMatching
/// <summary>
/// Returns a list of CfgBlock that are handlers of the current block, handling an exception
/// of the given type, or a subtype thereof.
/// </summary>
/// <param name="exception">Type of exception thrown. It is assumed that any actual subtype could be thrown</param>
/// <returns>All handlers that could apply directly to this exception.
/// In addition, if the method might not handle it, then the ExceptionExit block is
/// part of this list.</returns>
public System.Collections.IEnumerable/*CfgBlock*/ HandlersMatching(TypeNode exception) {
ArrayList handlers = new ArrayList();
CfgBlock currentBlock = this;
while (currentBlock != null) {
CfgBlock handler = this.cfg.ExceptionHandler(currentBlock);
if (handler == null || handler.Statements == null || handler.Statements.Count < 1) break;
Catch stat = handler.Statements[0] as Catch;
if (stat != null) {
if (exception.IsAssignableTo(stat.Type)) {
// handles exceptions completely
handlers.Add(handler);
break;
}
if (stat.Type.IsAssignableTo(exception)) {
// handles part of it
handlers.Add(handler);
}
currentBlock = handler;
}
else {
// must be the Unwind block
handlers.Add(handler);
break;
}
}
return handlers;
}
示例2: IsSubclassOf
private static bool IsSubclassOf(TypeNode t1, TypeNode t2)
{
Contract.Requires(t1 != null);
if (t2 == null) return false;
return t1.IsAssignableTo(t2);
}
示例3: FindImplementedMethod
private static Method FindImplementedMethod(MethodList candidates, TypeNode targetTypeInstance)
{
if (candidates != null)
{
for (int i = 0; i < candidates.Count; i++)
{
var candidate = candidates[i];
if (candidate == null) continue;
if (targetTypeInstance.IsAssignableTo(candidate.DeclaringType)) return candidate;
}
}
return null;
}
示例4: LeastCommonAncestor
public static TypeNode LeastCommonAncestor(TypeNode t1, TypeNode t2)
{
if (t1.IsAssignableTo(t2))
{
return t2;
}
// walk up t1 until assignable to t2
TypeNode frame = t1;
while (frame != null)
{
if (t2.IsAssignableTo(frame))
{
return frame;
}
frame = frame.BaseType;
}
// if we get here, we haven't found a common basetype. Return object
return Cci.SystemTypes.Object;
}
示例5: TypeMatches
public bool TypeMatches(TypeNode t) {
if (types == null || t == null) return true;
foreach (TypeNode a in types) {
if (a == null) return true;
if (t.IsAssignableTo(a)) return true;
}
return false;
}
示例6: IsValidTemplateArgument
/// <summary>
/// This is used to see if a type and parameter are valid template arguments
/// </summary>
/// <param name="type">The type to check</param>
/// <param name="parameter">The parameter to check</param>
/// <returns>True if it is valid, false if not</returns>
private static bool IsValidTemplateArgument(TypeNode type, TypeNode parameter)
{
if(type == null)
throw new ArgumentNullException("type");
// Check that the parameter really is a type parameter
ITypeParameter itp = parameter as ITypeParameter;
if(itp == null)
throw new ArgumentException("The 'parameter' argument is null or not an 'ITypeParameter'.");
// Test constraints
bool reference = ((itp.TypeParameterFlags & TypeParameterFlags.ReferenceTypeConstraint) > 0);
if(reference && type.IsValueType)
return (false);
bool value = ((itp.TypeParameterFlags & TypeParameterFlags.ValueTypeConstraint) > 0);
if(value && !type.IsValueType)
return (false);
InterfaceList contracts = parameter.Interfaces;
if(contracts != null)
foreach(Interface contract in contracts)
if(!type.IsAssignableTo(contract))
return false;
TypeNode parent = parameter.BaseType;
if(parent != null && !type.IsAssignableTo(parent))
return false;
// Okay, passed all tests
return true;
}