本文整理汇总了C#中System.Reflection.TypeInfo.HasExplicitOrImplicitPublicDefaultConstructor方法的典型用法代码示例。如果您正苦于以下问题:C# TypeInfo.HasExplicitOrImplicitPublicDefaultConstructor方法的具体用法?C# TypeInfo.HasExplicitOrImplicitPublicDefaultConstructor怎么用?C# TypeInfo.HasExplicitOrImplicitPublicDefaultConstructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.TypeInfo
的用法示例。
在下文中一共展示了TypeInfo.HasExplicitOrImplicitPublicDefaultConstructor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SatisfiesConstraints
static bool SatisfiesConstraints(this TypeInfo genericVariable, SigTypeContext typeContextOfConstraintDeclarer, TypeInfo typeArg)
{
GenericParameterAttributes specialConstraints = genericVariable.GenericParameterAttributes & GenericParameterAttributes.SpecialConstraintMask;
if ((specialConstraints & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0)
{
if (!typeArg.IsValueType)
return false;
else
{
// the type argument is a value type, however if it is any kind of Nullable we want to fail
// as the constraint accepts any value type except Nullable types (Nullable itself is a value type)
if (typeArg.IsNullable())
return false;
}
}
if ((specialConstraints & GenericParameterAttributes.ReferenceTypeConstraint) != 0)
{
if (typeArg.IsValueType)
return false;
}
if ((specialConstraints & GenericParameterAttributes.DefaultConstructorConstraint) != 0)
{
if (!typeArg.HasExplicitOrImplicitPublicDefaultConstructor())
return false;
}
// Now check general subtype constraints
foreach (var constraint in genericVariable.GetGenericParameterConstraints())
{
TypeInfo typeConstraint = constraint.GetTypeInfo();
TypeInfo instantiatedTypeConstraint = typeConstraint.Instantiate(typeContextOfConstraintDeclarer);
// System.Object constraint will be always satisfied - even if argList is empty
if (instantiatedTypeConstraint.IsSystemObject())
continue;
// if a concrete type can be cast to the constraint, then this constraint will be satisifed
if (!AreTypesAssignable(typeArg, instantiatedTypeConstraint))
return false;
}
return true;
}