1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System.Diagnostics; 6 7 namespace Microsoft.CSharp.RuntimeBinder.Semantics 8 { 9 internal sealed class TypeParameterSymbol : Symbol 10 { 11 private bool _bIsMethodTypeParameter; 12 private SpecCons _constraints; 13 14 private TypeParameterType _pTypeParameterType; 15 16 private int _nIndexInOwnParameters; 17 private int _nIndexInTotalParameters; 18 19 private TypeArray _pBounds; 20 21 public bool Covariant; 22 public bool Invariant { get { return !Covariant && !Contravariant; } } 23 public bool Contravariant; 24 SetTypeParameterType(TypeParameterType pType)25 public void SetTypeParameterType(TypeParameterType pType) 26 { 27 _pTypeParameterType = pType; 28 } 29 GetTypeParameterType()30 public TypeParameterType GetTypeParameterType() 31 { 32 return _pTypeParameterType; 33 } 34 IsMethodTypeParameter()35 public bool IsMethodTypeParameter() 36 { 37 return _bIsMethodTypeParameter; 38 } 39 SetIsMethodTypeParameter(bool b)40 public void SetIsMethodTypeParameter(bool b) 41 { 42 _bIsMethodTypeParameter = b; 43 } 44 GetIndexInOwnParameters()45 public int GetIndexInOwnParameters() 46 { 47 return _nIndexInOwnParameters; 48 } 49 SetIndexInOwnParameters(int index)50 public void SetIndexInOwnParameters(int index) 51 { 52 _nIndexInOwnParameters = index; 53 } 54 GetIndexInTotalParameters()55 public int GetIndexInTotalParameters() 56 { 57 return _nIndexInTotalParameters; 58 } 59 SetIndexInTotalParameters(int index)60 public void SetIndexInTotalParameters(int index) 61 { 62 Debug.Assert(index >= _nIndexInOwnParameters); 63 _nIndexInTotalParameters = index; 64 } 65 SetBounds(TypeArray pBounds)66 public void SetBounds(TypeArray pBounds) 67 { 68 _pBounds = pBounds; 69 } 70 GetBounds()71 public TypeArray GetBounds() 72 { 73 return _pBounds; 74 } 75 SetConstraints(SpecCons constraints)76 public void SetConstraints(SpecCons constraints) 77 { 78 _constraints = constraints; 79 } 80 IsValueType()81 public bool IsValueType() 82 { 83 return (_constraints & SpecCons.Val) > 0; 84 } 85 IsReferenceType()86 public bool IsReferenceType() 87 { 88 return (_constraints & SpecCons.Ref) > 0; 89 } 90 IsNonNullableValueType()91 public bool IsNonNullableValueType() 92 { 93 return (_constraints & SpecCons.Val) > 0; 94 } 95 HasNewConstraint()96 public bool HasNewConstraint() 97 { 98 return (_constraints & SpecCons.New) > 0; 99 } 100 HasRefConstraint()101 public bool HasRefConstraint() 102 { 103 return (_constraints & SpecCons.Ref) > 0; 104 } 105 HasValConstraint()106 public bool HasValConstraint() 107 { 108 return (_constraints & SpecCons.Val) > 0; 109 } 110 } 111 } 112