本文整理汇总了C#中Mono.CSharp.TypeParameterSpec类的典型用法代码示例。如果您正苦于以下问题:C# TypeParameterSpec类的具体用法?C# TypeParameterSpec怎么用?C# TypeParameterSpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeParameterSpec类属于Mono.CSharp命名空间,在下文中一共展示了TypeParameterSpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImplicitTypeParameterConversion
public static Expression ImplicitTypeParameterConversion (Expression expr, TypeParameterSpec expr_type, TypeSpec target_type)
{
//
// From T to a type parameter U, provided T depends on U
//
if (target_type.IsGenericParameter) {
if (expr_type.TypeArguments != null && expr_type.HasDependencyOn (target_type)) {
if (expr == null)
return EmptyExpression.Null;
if (expr_type.IsReferenceType && !((TypeParameterSpec) target_type).IsReferenceType)
return new BoxedCast (expr, target_type);
return new ClassCast (expr, target_type);
}
return null;
}
//
// LAMESPEC: From T to dynamic type because it's like T to object
//
if (target_type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
if (expr == null)
return EmptyExpression.Null;
if (expr_type.IsReferenceType)
return new ClassCast (expr, target_type);
return new BoxedCast (expr, target_type);
}
//
// From T to its effective base class C
// From T to any base class of C (it cannot contain dynamic or be of dynamic type)
// From T to any interface implemented by C
//
var base_type = expr_type.GetEffectiveBase ();
if (base_type == target_type || TypeSpec.IsBaseClass (base_type, target_type, false) || base_type.ImplementsInterface (target_type, true)) {
if (expr == null)
return EmptyExpression.Null;
if (expr_type.IsReferenceType)
return new ClassCast (expr, target_type);
return new BoxedCast (expr, target_type);
}
if (target_type.IsInterface && expr_type.IsConvertibleToInterface (target_type)) {
if (expr == null)
return EmptyExpression.Null;
if (expr_type.IsReferenceType)
return new ClassCast (expr, target_type);
return new BoxedCast (expr, target_type);
}
return null;
}
示例2: TypeParameterInflator
public TypeParameterInflator(TypeSpec type, TypeParameterSpec[] tparams, TypeSpec[] targs)
{
if (tparams.Length != targs.Length)
throw new ArgumentException ("Invalid arguments");
this.tparams = tparams;
this.targs = targs;
this.type = type;
}
示例3: HoistedStoreyClass
public HoistedStoreyClass (DeclSpace parent, MemberName name, TypeParameter[] tparams, Modifiers mod)
: base (parent, name, mod | Modifiers.PRIVATE)
{
if (tparams != null) {
type_params = new TypeParameter[tparams.Length];
var src = new TypeParameterSpec[tparams.Length];
var dst = new TypeParameterSpec[tparams.Length];
for (int i = 0; i < type_params.Length; ++i) {
type_params[i] = tparams[i].CreateHoistedCopy (this, spec);
src[i] = tparams[i].Type;
dst[i] = type_params[i].Type;
}
// A copy is not enough, inflate any type parameter constraints
// using a new type parameters
var inflator = new TypeParameterInflator (null, src, dst);
for (int i = 0; i < type_params.Length; ++i) {
src[i].InflateConstraints (inflator, dst[i]);
}
}
}
示例4: ImportedGenericMethodDefinition
public ImportedGenericMethodDefinition (MethodInfo provider, AParametersCollection parameters, TypeParameterSpec[] tparams)
: base (provider, parameters)
{
this.tparams = tparams;
}
示例5: ExplicitTypeParameterConversionToT
static Expression ExplicitTypeParameterConversionToT (Expression source, TypeSpec source_type, TypeParameterSpec target_type)
{
//
// From the effective base class C of T to T and from any base class of C to T
//
var effective = target_type.GetEffectiveBase ();
if (TypeSpecComparer.IsEqual (effective, source_type) || TypeSpec.IsBaseClass (effective, source_type, false))
return source == null ? EmptyExpression.Null : new ClassCast (source, target_type);
return null;
}
示例6: TypeParameter
public TypeParameter (TypeParameterSpec spec, DeclSpace parent, TypeSpec parentSpec, MemberName name, Attributes attrs)
: base (parent, name, attrs)
{
this.spec = new TypeParameterSpec (parentSpec, spec.DeclaredPosition, spec.MemberDefinition, spec.SpecialConstraint, spec.Variance, null) {
BaseType = spec.BaseType,
InterfacesDefined = spec.InterfacesDefined,
TypeArguments = spec.TypeArguments
};
}
示例7: CreateTypeParameter
TypeParameterSpec CreateTypeParameter (MetaType type, TypeSpec declaringType)
{
Variance variance;
switch (type.GenericParameterAttributes & GenericParameterAttributes.VarianceMask) {
case GenericParameterAttributes.Covariant:
variance = Variance.Covariant;
break;
case GenericParameterAttributes.Contravariant:
variance = Variance.Contravariant;
break;
default:
variance = Variance.None;
break;
}
SpecialConstraint special = SpecialConstraint.None;
var import_special = type.GenericParameterAttributes & GenericParameterAttributes.SpecialConstraintMask;
if ((import_special & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0) {
special |= SpecialConstraint.Struct;
} else if ((import_special & GenericParameterAttributes.DefaultConstructorConstraint) != 0) {
special = SpecialConstraint.Constructor;
}
if ((import_special & GenericParameterAttributes.ReferenceTypeConstraint) != 0) {
special |= SpecialConstraint.Class;
}
TypeParameterSpec spec;
var def = new ImportedTypeParameterDefinition (type, this);
if (type.DeclaringMethod != null) {
spec = new TypeParameterSpec (type.GenericParameterPosition, def, special, variance, type);
} else {
spec = new TypeParameterSpec (declaringType, type.GenericParameterPosition, def, special, variance, type);
}
return spec;
}
示例8: ImportedGenericMethodDefinition
public ImportedGenericMethodDefinition (MethodInfo provider, TypeSpec type, AParametersCollection parameters, TypeParameterSpec[] tparams, MetadataImporter importer)
: base (provider, type, parameters, importer)
{
this.tparams = tparams;
}
示例9: HasSameConstraintsDefinition
//
// Constraints have to match by definition but not position, used by
// partial classes or methods
//
public bool HasSameConstraintsDefinition (TypeParameterSpec other)
{
if (spec != other.spec)
return false;
if (BaseType != other.BaseType)
return false;
if (!TypeSpecComparer.Override.IsSame (InterfacesDefined, other.InterfacesDefined))
return false;
if (!TypeSpecComparer.Override.IsSame (targs, other.targs))
return false;
return true;
}
示例10: TypeParameter
public TypeParameter (DeclSpace parent, int index, MemberName name, Constraints constraints, Attributes attrs, Variance variance)
: base (parent, name, attrs)
{
this.constraints = constraints;
// this.variance = variance;
this.spec = new TypeParameterSpec (null, index, this, SpecialConstraint.None, variance, null);
}
示例11: CheckConversion
static void CheckConversion (IMemberContext mc, MemberSpec context, TypeSpec atype, TypeParameterSpec tparam, TypeSpec ttype, Location loc)
{
var expr = new EmptyExpression (atype);
if (!Convert.ImplicitStandardConversionExists (expr, ttype)) {
mc.Compiler.Report.SymbolRelatedToPreviousError (tparam);
if (TypeManager.IsValueType (atype)) {
mc.Compiler.Report.Error (315, loc, "The type `{0}' cannot be used as type parameter `{1}' in the generic type or method `{2}'. There is no boxing conversion from `{0}' to `{3}'",
atype.GetSignatureForError (), tparam.GetSignatureForError (), context.GetSignatureForError (), ttype.GetSignatureForError ());
} else if (atype.IsGenericParameter) {
mc.Compiler.Report.Error (314, loc, "The type `{0}' cannot be used as type parameter `{1}' in the generic type or method `{2}'. There is no boxing or type parameter conversion from `{0}' to `{3}'",
atype.GetSignatureForError (), tparam.GetSignatureForError (), context.GetSignatureForError (), ttype.GetSignatureForError ());
} else {
mc.Compiler.Report.Error (311, loc, "The type `{0}' cannot be used as type parameter `{1}' in the generic type or method `{2}'. There is no implicit reference conversion from `{0}' to `{3}'",
atype.GetSignatureForError (), tparam.GetSignatureForError (), context.GetSignatureForError (), ttype.GetSignatureForError ());
}
}
}
示例12: CheckConstraint
static bool CheckConstraint (IMemberContext mc, MemberSpec context, TypeSpec atype, TypeParameterSpec tparam, Location loc)
{
//
// First, check the `class' and `struct' constraints.
//
if (tparam.HasSpecialClass && !TypeManager.IsReferenceType (atype)) {
mc.Compiler.Report.Error (452, loc,
"The type `{0}' must be a reference type in order to use it as type parameter `{1}' in the generic type or method `{2}'",
TypeManager.CSharpName (atype), tparam.GetSignatureForError (), context.GetSignatureForError ());
return false;
}
if (tparam.HasSpecialStruct && (!TypeManager.IsValueType (atype) || TypeManager.IsNullableType (atype))) {
mc.Compiler.Report.Error (453, loc,
"The type `{0}' must be a non-nullable value type in order to use it as type parameter `{1}' in the generic type or method `{2}'",
TypeManager.CSharpName (atype), tparam.GetSignatureForError (), context.GetSignatureForError ());
return false;
}
//
// The class constraint comes next.
//
if (tparam.HasTypeConstraint) {
CheckConversion (mc, context, atype, tparam, tparam.BaseType, loc);
}
//
// Now, check the interfaces and type parameters constraints
//
if (tparam.Interfaces != null) {
if (TypeManager.IsNullableType (atype)) {
mc.Compiler.Report.Error (313, loc,
"The type `{0}' cannot be used as type parameter `{1}' in the generic type or method `{2}'. The nullable type `{0}' never satisfies interface constraint",
atype.GetSignatureForError (), tparam.GetSignatureForError (), context.GetSignatureForError ());
} else {
foreach (TypeSpec iface in tparam.Interfaces) {
CheckConversion (mc, context, atype, tparam, iface, loc);
}
}
}
//
// Finally, check the constructor constraint.
//
if (!tparam.HasSpecialConstructor)
return true;
if (!HasDefaultConstructor (atype)) {
mc.Compiler.Report.SymbolRelatedToPreviousError (atype);
mc.Compiler.Report.Error (310, loc,
"The type `{0}' must have a public parameterless constructor in order to use it as parameter `{1}' in the generic type or method `{2}'",
TypeManager.CSharpName (atype), tparam.GetSignatureForError (), context.GetSignatureForError ());
return false;
}
return true;
}
示例13: CheckAll
/// <summary>
/// Check the constraints; we're called from ResolveAsTypeTerminal()
/// after fully resolving the constructed type.
/// </summary>
public static bool CheckAll (IMemberContext mc, MemberSpec context, TypeSpec[] targs, TypeParameterSpec[] tparams, Location loc)
{
for (int i = 0; i < tparams.Length; i++) {
if (!CheckConstraint (mc, context, targs [i], tparams [i], loc))
return false;
}
return true;
}
示例14: Mutate
public TypeParameterSpec Mutate (TypeParameterSpec tp)
{
for (int i = 0; i < mvar.Length; ++i) {
if (mvar[i].Type == tp)
return var[i].Type;
}
return tp;
}
示例15: Inflate
public TypeSpec Inflate (TypeParameterSpec tp)
{
for (int i = 0; i < tparams.Length; ++i)
if (tparams [i] == tp)
return targs[i];
// This can happen when inflating nested types
// without type arguments specified
return tp;
}