本文整理汇总了C#中System.TypeSpec类的典型用法代码示例。如果您正苦于以下问题:C# TypeSpec类的具体用法?C# TypeSpec怎么用?C# TypeSpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeSpec类属于System命名空间,在下文中一共展示了TypeSpec类的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: Class
public Class(TypeContainer parent, MemberName name, Modifiers mod, Attributes attrs)
: base(parent, name, attrs, MemberKind.Class)
{
var accmods = IsTopLevel ? Modifiers.INTERNAL : Modifiers.PRIVATE;
this.ModFlags = ModifiersExtensions.Check (AllowedModifiers, mod, accmods, Location, Report);
spec = new TypeSpec (Kind, null, this, null, ModFlags);
}
示例3: Lifted
public Lifted(Expression expr, Unwrap unwrap, TypeSpec type)
{
this.expr = expr;
this.unwrap = unwrap;
this.loc = expr.Location;
this.type = type;
}
示例4: IsValidEnumType
static bool IsValidEnumType (TypeSpec t)
{
return (t == TypeManager.int32_type || t == TypeManager.uint32_type || t == TypeManager.int64_type ||
t == TypeManager.byte_type || t == TypeManager.sbyte_type || t == TypeManager.short_type ||
t == TypeManager.ushort_type || t == TypeManager.uint64_type || t == TypeManager.char_type ||
TypeManager.IsEnumType (t));
}
示例5: EmitContext
// TODO: Replace IMemberContext with MemberCore
public EmitContext (IMemberContext rc, ILGenerator ig, TypeSpec return_type)
{
this.MemberContext = rc;
this.ig = ig;
this.return_type = return_type;
}
示例6: CreateDelegateType
public static TypeSpec CreateDelegateType (ResolveContext rc, AParametersCollection parameters, TypeSpec returnType, Location loc)
{
Namespace type_ns = rc.Module.GlobalRootNamespace.GetNamespace ("System", true);
if (type_ns == null) {
return null;
}
if (returnType == rc.BuiltinTypes.Void) {
var actArgs = parameters.Types;
var actionSpec = type_ns.LookupType (rc.Module, "Action", actArgs.Length, LookupMode.Normal, loc).ResolveAsType(rc);
if (actionSpec == null) {
return null;
}
if (actArgs.Length == 0)
return actionSpec;
else
return actionSpec.MakeGenericType(rc, actArgs);
} else {
TypeSpec[] funcArgs = new TypeSpec[parameters.Types.Length + 1];
parameters.Types.CopyTo(funcArgs, 0);
funcArgs[parameters.Types.Length] = returnType;
var funcSpec = type_ns.LookupType (rc.Module, "Func", funcArgs.Length, LookupMode.Normal, loc).ResolveAsType(rc);
if (funcSpec == null)
return null;
return funcSpec.MakeGenericType(rc, funcArgs);
}
}
示例7: ArrayToIList
//
// From a one-dimensional array-type S[] to System.Collections.IList<T> and base
// interfaces of this interface, provided there is an implicit reference conversion
// from S to T.
//
static bool ArrayToIList (ArrayContainer array, TypeSpec list, bool isExplicit)
{
if (array.Rank != 1 || !list.IsGeneric)
return false;
var open_version = list.GetDefinition ();
if ((open_version != TypeManager.generic_ilist_type) &&
(open_version != TypeManager.generic_icollection_type) &&
(open_version != TypeManager.generic_ienumerable_type))
return false;
var arg_type = list.TypeArguments[0];
if (array.Element == arg_type)
return true;
if (isExplicit)
return ExplicitReferenceConversionExists (array.Element, arg_type);
if (MyEmptyExpr == null)
MyEmptyExpr = new EmptyExpression (array.Element);
else
MyEmptyExpr.SetType (array.Element);
return ImplicitReferenceConversionExists (MyEmptyExpr, arg_type);
}
示例8: ExplicitConversion
/// <summary>
/// Performs an explicit conversion of the expression `expr' whose
/// type is expr.Type to `target_type'.
/// </summary>
public static Expression ExplicitConversion(ResolveContext ec, Expression expr,
TypeSpec target_type, Location loc)
{
Expression e = ExplicitConversionCore (ec, expr, target_type, loc);
if (e != null) {
//
// Don't eliminate explicit precission casts
//
if (e == expr) {
if (target_type.BuiltinType == BuiltinTypeSpec.Type.Float)
return new OpcodeCast (expr, target_type, OpCodes.Conv_R4);
if (target_type.BuiltinType == BuiltinTypeSpec.Type.Double)
return new OpcodeCast (expr, target_type, OpCodes.Conv_R8);
}
return e;
}
TypeSpec expr_type = expr.Type;
if (target_type.IsNullableType) {
TypeSpec target;
if (expr_type.IsNullableType) {
target = Nullable.NullableInfo.GetUnderlyingType (target_type);
Expression unwrap = Nullable.Unwrap.Create (expr);
e = ExplicitConversion (ec, unwrap, target, expr.Location);
if (e == null)
return null;
return new Nullable.LiftedConversion (e, unwrap, target_type).Resolve (ec);
}
if (expr_type.BuiltinType == BuiltinTypeSpec.Type.Object) {
return new UnboxCast (expr, target_type);
}
target = TypeManager.GetTypeArguments (target_type) [0];
e = ExplicitConversionCore (ec, expr, target, loc);
if (e != null)
return TypeSpec.IsReferenceType (expr.Type) ? new UnboxCast (expr, target_type) : Nullable.Wrap.Create (e, target_type);
} else if (expr_type.IsNullableType) {
e = ImplicitBoxingConversion (expr, Nullable.NullableInfo.GetUnderlyingType (expr_type), target_type);
if (e != null)
return e;
e = Nullable.Unwrap.Create (expr, false);
e = ExplicitConversionCore (ec, e, target_type, loc);
if (e != null)
return EmptyCast.Create (e, target_type);
}
e = ExplicitUserConversion (ec, expr, target_type, loc);
if (e != null)
return e;
expr.Error_ValueCannotBeConverted (ec, target_type, true);
return null;
}
示例9: BoolConstant
public BoolConstant(TypeSpec type, bool val, Location loc)
: base(loc)
{
eclass = ExprClass.Value;
this.type = type;
Value = val;
}
示例10: ImplicitConversionRequired
public Constant ImplicitConversionRequired (ResolveContext ec, TypeSpec type, Location loc)
{
Constant c = ConvertImplicitly (type);
if (c == null)
Error_ValueCannotBeConverted (ec, type, false);
return c;
}
示例11: Class
public Class(NamespaceEntry ns, DeclSpace parent, MemberName name, Modifiers mod,
Attributes attrs)
: base(ns, parent, name, attrs, MemberKind.Class)
{
var accmods = (Parent == null || Parent.Parent == null) ? Modifiers.INTERNAL : Modifiers.PRIVATE;
this.ModFlags = ModifiersExtensions.Check (AllowedModifiers, mod, accmods, Location, Report);
spec = new TypeSpec (Kind, null, this, null, ModFlags);
}
示例12: CompilerGeneratedContainer
protected CompilerGeneratedContainer (TypeContainer parent, MemberName name, Modifiers mod, MemberKind kind)
: base (parent, name, null, kind)
{
Debug.Assert ((mod & Modifiers.AccessibilityMask) != 0);
ModFlags = mod | Modifiers.COMPILER_GENERATED | Modifiers.SEALED;
spec = new TypeSpec (Kind, null, this, null, ModFlags);
}
示例13: ResolveType
public bool ResolveType(IMemberContext mc, TypeSpec defaultType)
{
if (TypeExpression != null)
this.Type = TypeExpression.ResolveAsType (mc);
else
this.Type = defaultType;
return this.Type != null;
}
示例14: 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;
}
示例15: Iterator
//
// Our constructor
//
public Iterator(ParametersBlock block, IMethodData method, TypeContainer host, TypeSpec iterator_type, bool is_enumerable)
: base(block, TypeManager.bool_type, block.StartLocation)
{
this.OriginalMethod = method;
this.OriginalIteratorType = iterator_type;
this.IsEnumerable = is_enumerable;
this.Host = host;
this.type = method.ReturnType;
}