本文整理汇总了C#中System.Compiler.TypeNode.IsStructurallyEquivalentTo方法的典型用法代码示例。如果您正苦于以下问题:C# TypeNode.IsStructurallyEquivalentTo方法的具体用法?C# TypeNode.IsStructurallyEquivalentTo怎么用?C# TypeNode.IsStructurallyEquivalentTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Compiler.TypeNode
的用法示例。
在下文中一共展示了TypeNode.IsStructurallyEquivalentTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsAssignableToInstanceOf
/// <summary>
/// Returns true if this type is assignable to some instance of the given template.
/// </summary>
public virtual bool IsAssignableToInstanceOf(TypeNode targetTemplate)
{
if(this == CoreSystemTypes.Void || targetTemplate == null)
return false;
if(targetTemplate.IsStructurallyEquivalentTo(this.Template == null ? this : this.Template) ||
this.BaseType != null && (this.BaseType.IsAssignableToInstanceOf(targetTemplate) ||
this.BaseType.Template != null && this.BaseType.Template.IsAssignableToInstanceOf(targetTemplate)))
return true;
InterfaceList interfaces = this.Interfaces;
if(interfaces == null)
return false;
for(int i = 0, n = interfaces.Count; i < n; i++)
{
Interface iface = interfaces[i];
if(iface == null)
continue;
if(iface.IsAssignableToInstanceOf(targetTemplate))
return true;
}
return false;
}
示例2: TypeMatch
private static bool TypeMatch(TypeNode type1, TypeNode type2) {
// the two types must be of the same kind
if (type1.NodeType != type2.NodeType) return (false);
if (type1.NodeType == NodeType.ArrayType) {
// they are arrays, so check elements
ArrayType array1 = (ArrayType)type1;
ArrayType array2 = (ArrayType)type2;
return (TypeMatch(array1.ElementType, array2.ElementType));
} else {
// they are normal types
return (type1.IsStructurallyEquivalentTo(type2));
}
}
示例3: GetImplicitCoercionFromMethod
public virtual Method GetImplicitCoercionFromMethod(TypeNode sourceType)
{
if(sourceType == null)
return null;
Method result = null;
if(this.implicitCoercionFromTable != null)
result = (Method)this.implicitCoercionFromTable[sourceType.UniqueKey];
if(result == TypeNode.MethodDoesNotExist)
return null;
if(result != null)
return result;
lock(this)
{
if(this.implicitCoercionFromTable != null)
result = (Method)this.implicitCoercionFromTable[sourceType.UniqueKey];
if(result == TypeNode.MethodDoesNotExist)
return null;
if(result != null)
return result;
MemberList coercions = this.ImplicitCoercionMethods;
for(int i = 0, n = coercions.Count; i < n; i++)
{
Method m = (Method)coercions[i];
if(sourceType.IsStructurallyEquivalentTo(TypeNode.StripModifiers(m.Parameters[0].Type))) { result = m; break; }
}
if(this.implicitCoercionFromTable == null)
this.implicitCoercionFromTable = new TrivialHashtable();
if(result == null)
this.implicitCoercionFromTable[sourceType.UniqueKey] = TypeNode.MethodDoesNotExist;
else
this.implicitCoercionFromTable[sourceType.UniqueKey] = result;
return result;
}
}