本文整理汇总了C#中IType.IsAssignableFrom方法的典型用法代码示例。如果您正苦于以下问题:C# IType.IsAssignableFrom方法的具体用法?C# IType.IsAssignableFrom怎么用?C# IType.IsAssignableFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IType
的用法示例。
在下文中一共展示了IType.IsAssignableFrom方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadFrom
public object ReadFrom(IHttpEntity request, IType destinationType, string parameterName)
{
if (destinationType.IsAssignableFrom<IEnumerable<IMultipartHttpEntity>>())
{
var multipartReader = new MultipartReader(request.ContentType.Boundary, request.Stream);
return multipartReader.GetParts();
}
if (destinationType.IsAssignableFrom<IDictionary<string, IList<IMultipartHttpEntity>>>())
{
return FormData(request);
}
var binder = BinderLocator.GetBinder(destinationType);
if (binder == null)
{
throw new InvalidOperationException("Cannot find a binder to create the object");
}
binder.Prefixes.Add(parameterName);
bool wasAnyKeyUsed = ReadKeyValues(request).Aggregate(false, (wasUsed, kv) => kv.SetProperty(binder) || wasUsed);
var result = binder.BuildObject();
return wasAnyKeyUsed && result.Successful ? result.Instance : Missing.Value;
}
示例2: IsAssignableFrom
public static bool IsAssignableFrom(IType expectedType, IType actualType)
{
return expectedType.IsAssignableFrom(actualType);
}
示例3: IsSubclassOf
public virtual bool IsSubclassOf(IType other)
{
if (other.IsAssignableFrom(_array)) return true;
// Arrays also implement generic IEnumerable of their element type
if (other.ConstructedInfo != null &&
other.ConstructedInfo.GenericDefinition == _enumerable &&
other.ConstructedInfo.GenericArguments[0].IsAssignableFrom(_elementType))
{
return true;
}
return false;
}
示例4: CalculateArgumentScore
private int CalculateArgumentScore(IParameter param, IType parameterType, Node arg)
{
IType argumentType = GetExpressionTypeOrEntityType(arg);
if (param.IsByRef)
{
if (IsValidByRefArg(param, parameterType, argumentType, arg))
{
return ExactMatchScore;
}
return -1;
}
else if (parameterType == argumentType
|| (TypeSystemServices.IsSystemObject(argumentType) &&
TypeSystemServices.IsSystemObject(parameterType)))
{
return parameterType is ICallableType
? CallableExactMatchScore
: ExactMatchScore;
}
else if (parameterType.IsAssignableFrom(argumentType))
{
ICallableType callableType = parameterType as ICallableType;
ICallableType callableArg = argumentType as ICallableType;
if (callableType != null && callableArg != null)
{
return CalculateCallableScore(callableType, callableArg);
}
return UpCastScore;
}
else if (TypeSystemServices.FindImplicitConversionOperator(argumentType, parameterType) != null)
{
return ImplicitConversionScore;
}
else if (TypeSystemServices.CanBeReachedByPromotion(parameterType, argumentType))
{
if (IsWideningPromotion(parameterType, argumentType)) return WideningPromotion;
return NarrowingPromotion;
}
else if (TypeSystemServices.CanBeReachedByDowncast(parameterType, argumentType))
{
return DowncastScore;
}
return -1;
}
示例5: IsAssignableFrom
bool IsAssignableFrom(IType expectedType, IType actualType)
{
return (IsPtr(expectedType) && IsPtr(actualType))
|| expectedType.IsAssignableFrom(actualType);
}
示例6: GetMostGenericType
public IType GetMostGenericType(IType current, IType candidate)
{
if (current.IsAssignableFrom(candidate))
{
return current;
}
if (candidate.IsAssignableFrom(current))
{
return candidate;
}
if (IsNumberOrBool(current) && IsNumberOrBool(candidate))
{
return GetPromotedNumberType(current, candidate);
}
if (IsCallableType(current) && IsCallableType(candidate))
{
return ICallableType;
}
if (current.IsClass && candidate.IsClass)
{
if (current == ObjectType || candidate == ObjectType)
{
return ObjectType;
}
if (current.GetTypeDepth() < candidate.GetTypeDepth())
{
return GetMostGenericType(current.BaseType, candidate);
}
return GetMostGenericType(current, candidate.BaseType);
}
return ObjectType;
}
示例7: CanBeReachedByDowncast
public virtual bool CanBeReachedByDowncast(IType expectedType, IType actualType)
{
return actualType.IsAssignableFrom(expectedType);
}
示例8: AreTypesRelated
public bool AreTypesRelated(IType lhs, IType rhs)
{
ICallableType ctype = lhs as ICallableType;
if (null != ctype)
{
return ctype.IsAssignableFrom(rhs)
|| ctype.IsSubclassOf(rhs);
}
return lhs.IsAssignableFrom(rhs)
|| (lhs.IsInterface && !rhs.IsFinal)
|| (rhs.IsInterface && !lhs.IsFinal)
|| CanBeReachedByDownCastOrPromotion(lhs, rhs)
|| FindImplicitConversionOperator(rhs,lhs) != null;
}
示例9: IsSubclassOf
public bool IsSubclassOf(IType other)
{
if (BaseType != null && (BaseType == other || BaseType.IsSubclassOf(other)))
{
return true;
}
if (other.IsInterface && Array.Exists(
GetInterfaces(),
delegate(IType i) { return other.IsAssignableFrom(i); }))
{
return true;
}
return false;
}