本文整理汇总了C#中TypeNode.GetReferenceType方法的典型用法代码示例。如果您正苦于以下问题:C# TypeNode.GetReferenceType方法的具体用法?C# TypeNode.GetReferenceType怎么用?C# TypeNode.GetReferenceType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeNode
的用法示例。
在下文中一共展示了TypeNode.GetReferenceType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InferTypeOfUnaryExpression
public virtual TypeNode InferTypeOfUnaryExpression(TypeNode origType, UnaryExpression unaryExpression){
if (unaryExpression == null) return origType;
TypeNode t = this.typeSystem.Unwrap(origType);
if (this.typeSystem.IsNullableType(t)) return this.typeSystem.CreateNullableWrapper(this.currentType, InferTypeOfUnaryExpression(this.typeSystem.RemoveNullableWrapper(t), unaryExpression));
switch (unaryExpression.NodeType){
case NodeType.AddressOf: return origType.GetPointerType();
case NodeType.OutAddress:
case NodeType.RefAddress: return origType.GetReferenceType();
case NodeType.Ldftn: return SystemTypes.IntPtr;
case NodeType.LogicalNot: return SystemTypes.Boolean;
case NodeType.UnaryPlus:
case NodeType.Neg:
case NodeType.Not:
switch(t.TypeCode){
case TypeCode.SByte:
case TypeCode.Byte:
case TypeCode.Int16:
case TypeCode.UInt16:
case TypeCode.Char:
return SystemTypes.Int32;
case TypeCode.UInt32:
if (unaryExpression.NodeType == NodeType.Neg)
return SystemTypes.Int64;
break;
}
break;
case NodeType.Parentheses:
case NodeType.SkipCheck:
case NodeType.Ckfinite:
if (unaryExpression.Operand == null){
unaryExpression.IsErroneous = true;
return t;
}
return unaryExpression.Operand.Type;
case NodeType.DefaultValue:
Literal lit = unaryExpression.Operand as Literal;
if (lit == null){
unaryExpression.IsErroneous = true;
return SystemTypes.Object;
}
TypeNode lt = lit.Value as TypeNode;
if (lt == null){
unaryExpression.IsErroneous = true;
return SystemTypes.Object;
}
return lt;
case NodeType.Sizeof:
return SystemTypes.Int32;
case NodeType.Typeof:
return !this.NonNullChecking ? SystemTypes.Type : (TypeNode)OptionalModifier.For(SystemTypes.NonNullType, SystemTypes.Type);
}
return t;
}
示例2: GetAddressOf
private Expression GetAddressOf(Expression targetOb, TypeNode tObType) {
MemberBinding tgtmb = targetOb as MemberBinding;
if (tgtmb != null && tgtmb.BoundMember is Field && ((Field)tgtmb.BoundMember).IsInitOnly) {
StatementList stats = new StatementList(2);
Local loc = new Local(targetOb.Type);
stats.Add(new AssignmentStatement(loc, targetOb));
stats.Add(new ExpressionStatement(new UnaryExpression(loc, NodeType.AddressOf, tObType.GetReferenceType())));
return new BlockExpression(new Block(stats));
} else
return new UnaryExpression(targetOb, NodeType.AddressOf, tObType.GetReferenceType(), targetOb.SourceContext);
}
示例3: PType
//.........这里部分代码省略.........
Get();
c = SystemTypes.Int32;
break;
}
case 14: {
Get();
c = SystemTypes.Int64;
break;
}
case 15: {
Get();
c = SystemTypes.UInt8;
break;
}
case 16: {
Get();
c = SystemTypes.UInt16;
break;
}
case 17: {
Get();
c = SystemTypes.UInt32;
break;
}
case 18: {
Get();
c = SystemTypes.UInt64;
break;
}
case 19: {
Get();
c = SystemTypes.Single;
break;
}
case 20: {
Get();
c = SystemTypes.Double;
break;
}
case 21: {
Get();
Expect(22);
PType(out modifier);
Expect(23);
PType(out modified);
Expect(24);
c = OptionalModifier.For(modifier,modified);
break;
}
case 25: {
Get();
Expect(22);
string id;
Ident(out id);
Expect(24);
c = LookupTypeParameter(id);
break;
}
case 26: {
Get();
Expect(22);
string id;
Ident(out id);
Expect(24);
c = LookupMethodTypeParameter(id);
break;
}
case 1: case 28: case 35: {
PTypeRef(out c);
break;
}
default: SynErr(109); break;
}
if (StartOf(1)) {
if (la.kind == 27) {
Get();
c = c.GetReferenceType();
} else if (la.kind == 28) {
Get();
Expect(29);
c = c.GetArrayType(1);
while (la.kind == 28) {
Get();
Expect(29);
c = c.GetArrayType(1);
}
} else if (la.kind == 22) {
Get();
PType(out c);
while (la.kind == 23) {
Get();
PType(out c);
}
Expect(24);
} else {
Get();
c = c.GetPointerType();
}
}
}
示例4: StandardExplicitCoercionHelper
//.........这里部分代码省略.........
//savedErrorHandler.HandleError(source, Error.CannotCoerceNullToNonNullType, savedErrorHandler.GetTypeName(targetType));
return ExplicitNonNullCoercion(source, originalTargetType);
}
if (targetType is ITypeParameter && sourceType == SystemTypes.Object && this.useGenerics)
return new BinaryExpression(source, new Literal(targetType, SystemTypes.Type), NodeType.UnboxAny);
if (!targetType.IsValueType || targetType.Template == SystemTypes.GenericBoxed)
return new Literal(null, targetType, source.SourceContext);
TypeAlias tAlias = targetType as TypeAlias;
if (tAlias != null){
source = this.ExplicitCoercion(source, tAlias.AliasedType, typeViewer);
if (source == null) return null;
Method coercion = this.UserDefinedExplicitCoercionMethod(source, tAlias.AliasedType, targetType, false, originalTargetType, typeViewer);
if (coercion != null){
ExpressionList args = new ExpressionList(this.ImplicitCoercion(source, coercion.Parameters[0].Type, typeViewer));
return new MethodCall(new MemberBinding(null, coercion), args, NodeType.Call, coercion.ReturnType);
}
}
return null;
}
//Explicit reference coercions
if (TypeViewer.GetTypeView(typeViewer, sourceType).IsAssignableTo(targetType)){
//Handling for non null types
if (targetIsNonNullType && !sourceIsNonNullType && !sourceType.IsValueType) {
//savedErrorHandler.HandleError(source, Error.CoercionToNonNullTypeMightFail, savedErrorHandler.GetTypeName(targetType));
return ExplicitNonNullCoercion(source, originalTargetType);
}
if (targetType == SystemTypes.Object && sourceType.Template == SystemTypes.GenericIEnumerable)
return this.CoerceStreamToObject(source, sourceType, typeViewer);
if (sourceType.IsValueType && !targetType.IsValueType){
if (sourceType.NodeType == NodeType.TypeUnion){
Debug.Assert(targetType == SystemTypes.Object);
return this.CoerceTypeUnionToObject(source, typeViewer);
}
if (sourceType is TupleType){
if (targetType == SystemTypes.Object)
return this.TupleCoercion(source, sourceType, targetType, true, typeViewer);
}else if (this.GetStreamElementType(sourceType, typeViewer) != sourceType)
return this.ExplicitCoercion(this.CoerceStreamToObject(source, sourceType, typeViewer), targetType, typeViewer);
return new BinaryExpression(source, new MemberBinding(null, sourceType), NodeType.Box, targetType);
}else if (this.useGenerics && sourceType is ITypeParameter){
source = new BinaryExpression(source, new MemberBinding(null, sourceType), NodeType.Box, sourceType);
if (targetType == SystemTypes.Object) return source;
return new BinaryExpression(source, new MemberBinding(null, targetType), NodeType.UnboxAny, targetType);
}else
return source;
}
//Special case for typed streams
Expression streamCoercion = this.StreamCoercion(source, sourceType, targetType, true, originalTargetType, typeViewer);
if (streamCoercion != null) return streamCoercion;
//Down casts
if (!targetType.IsPointerType && !sourceType.IsPointerType && TypeViewer.GetTypeView(typeViewer, targetType).IsAssignableTo(sourceType)){
if (!sourceType.IsValueType){
if (targetType.NodeType == NodeType.TypeUnion)
return this.CoerceObjectToTypeUnion(source, (TypeUnion)targetType, typeViewer);
if (source.NodeType == NodeType.Literal && ((Literal)source).Value == null)
return source;
if (targetType.IsValueType){
Expression e = new AddressDereference(new BinaryExpression(source, new MemberBinding(null, targetType), NodeType.Unbox, targetType.GetReferenceType()), targetType);
e.Type = targetType;
return e;
}else{
NodeType op = this.useGenerics && (targetType is ClassParameter || targetType is TypeParameter) ? NodeType.UnboxAny : NodeType.Castclass;
Expression e = new BinaryExpression(source, new MemberBinding(null, targetType), op, source.SourceContext);
e.Type = originalTargetType;
//Handling for non null types
if (targetIsNonNullType && !sourceIsNonNullType){
//savedErrorHandler.HandleError(source, Error.CoercionToNonNullTypeMightFail, savedErrorHandler.GetTypeName(targetType));
return ExplicitNonNullCoercion(e, originalTargetType);
}
return e;
}
}
}
//Special case for casts to and from interfaces
if ((sourceType.NodeType == NodeType.Interface && !targetType.IsSealed) ||
(targetType.NodeType == NodeType.Interface && !(sourceType.IsSealed || (sourceType is Pointer) ||
(sourceType is ArrayType && this.GetStreamElementType(targetType, typeViewer) == targetType)))){
Expression e = new BinaryExpression(source, new MemberBinding(null, targetType), NodeType.Castclass, source.SourceContext);
e.Type = targetType;
return e;
}
//Explicit numeric coercions + explicit enumeration coercions + explicit constant expression coercions
Expression primitiveConversion = this.ExplicitPrimitiveCoercion(source, sourceType, targetType);
if (primitiveConversion != null) return primitiveConversion;
//Special case for decimal
if (targetType == SystemTypes.Decimal && this.ImplicitCoercionFromTo(sourceType, targetType, typeViewer))
return this.ImplicitCoercion(source, targetType, typeViewer);
//Special case for delegates
if (targetType is DelegateNode)
return this.CoerceToDelegate(source, sourceType, (DelegateNode)targetType, true, typeViewer);
//Special case for type union
if (targetType.NodeType == NodeType.TypeUnion)
return this.CoerceToTypeUnion(source, sourceType, (TypeUnion)targetType, typeViewer);
//Special case for Type intersection target type
if (targetType.NodeType == NodeType.TypeIntersection)
return this.CoerceToTypeIntersection(source, sourceType, (TypeIntersection)targetType, false, typeViewer);
//Tuple coercion
return this.TupleCoercion(source, sourceType, targetType, true, typeViewer);
}
示例5: Unbox
private Expression Unbox(Expression x, TypeNode type) {
if (type.IsValueType) {
BinaryExpression be = new BinaryExpression(x, new Literal(type, SystemTypes.Type), NodeType.Unbox);
be.Type = type.GetReferenceType();
return new AddressDereference(be, type);
}else if (this.useGenerics && type is ITypeParameter){
BinaryExpression be = new BinaryExpression(x, new Literal(type, SystemTypes.Type), NodeType.UnboxAny);
be.Type = type;
return be;
}else{
BinaryExpression be = new BinaryExpression(x, new Literal(type, SystemTypes.Type), NodeType.Castclass);
be.Type = type;
return be;
}
}
示例6: ParseTypeCheck
private static Expression/*!*/ ParseTypeCheck(Expression operand, TypeNode type, NodeType typeOfCheck)
{
TypeNode etype = type;
if (typeOfCheck == NodeType.Unbox) etype = type.GetReferenceType();
Expression expr = new BinaryExpression(operand, new Literal(type, CoreSystemTypes.Type), typeOfCheck, etype);
return expr;
}
示例7: GetMethodFromDef
internal Method/*!*/ GetMethodFromDef(int index, TypeNode declaringType)
{
TypeNodeList savedCurrentMethodTypeParameters = this.currentMethodTypeParameters;
TypeNodeList savedCurrentTypeParameters = this.currentTypeParameters;
MethodRow[] methodDefs = this.tables.MethodTable;
MethodRow meth = methodDefs[index - 1];
if (meth.Method != null) return meth.Method;
if (declaringType == null)
{
int indx = index;
MethodPtrRow[] methodPtrs = this.tables.MethodPtrTable;
int n = methodPtrs.Length, i = 0, j = n - 1;
bool sorted = (this.sortedTablesMask >> (int)TableIndices.MethodPtr) % 2 == 1;
if (sorted)
{
while (i < j)
{
int k = (i + j) / 2;
if (methodPtrs[k].Method < index)
i = k + 1;
else
j = k;
}
while (i > 0 && methodPtrs[i - 1].Method == index) i--;
}
for (; i < n; i++)
{
if (methodPtrs[i].Method == index)
{
indx = i + 1; break;
}
}
TypeDefRow[] typeDefs = this.tables.TypeDefTable;
n = typeDefs.Length; i = 0; j = n - 1;
sorted = (this.sortedTablesMask >> (int)TableIndices.TypeDef) % 2 == 1;
if (sorted)
{
while (i < j)
{
int k = (i + j) / 2;
if (typeDefs[k].MethodList < indx)
i = k + 1;
else
j = k;
}
j = i;
while (j < n - 1 && typeDefs[j + 1].MethodList == indx) j++;
}
for (; j >= 0; j--)
{
if (typeDefs[j].MethodList <= indx)
{
declaringType = this.GetTypeFromDef(j + 1);
break;
}
}
}
Method.MethodBodyProvider provider = new Method.MethodBodyProvider(this.GetMethodBody);
Identifier name = tables.GetIdentifier(meth.Name);
Method method;
if ((((MethodFlags)meth.Flags) & MethodFlags.SpecialName) != 0 &&
(((MethodFlags)meth.Flags) & MethodFlags.SpecialName) != 0)
{
if (name.Name == ".ctor")
method = methodDefs[index - 1].Method = new InstanceInitializer(provider, index);
else if (name.Name == ".cctor")
method = methodDefs[index - 1].Method = new StaticInitializer(provider, index);
else
method = methodDefs[index - 1].Method = new Method(provider, index);
}
else
method = methodDefs[index - 1].Method = new Method(provider, index);
method.ProvideMethodAttributes = new Method.MethodAttributeProvider(this.GetMethodAttributes);
//method.Attributes = this.GetCustomAttributesFor((index << 5)|0); //TODO: get attributes lazily
method.Flags = (MethodFlags)meth.Flags;
method.ImplFlags = (MethodImplFlags)meth.ImplFlags;
method.Name = name;
if (declaringType != null && declaringType.IsGeneric)
{
if (declaringType.Template != null)
this.currentTypeParameters = declaringType.ConsolidatedTemplateArguments;
else
this.currentTypeParameters = declaringType.ConsolidatedTemplateParameters;
}
tables.GetSignatureLength(meth.Signature);
MemoryCursor sigReader = this.tables.GetNewCursor();
method.CallingConvention = (CallingConventionFlags)sigReader.ReadByte();
if (method.IsGeneric = (method.CallingConvention & CallingConventionFlags.Generic) != 0)
{
int numTemplateParameters = sigReader.ReadCompressedInt();
this.currentMethodTypeParameters = new TypeNodeList();
this.currentMethodTypeParameters = method.TemplateParameters = this.GetTypeParametersFor((index << 1) | 1, method);
this.GetTypeParameterConstraints((index << 1) | 1, method.TemplateParameters);
}
int numParams = sigReader.ReadCompressedInt();
method.ReturnType = this.ParseTypeSignature(sigReader);
if (declaringType != null && declaringType.IsValueType)
method.ThisParameter = new This(declaringType.GetReferenceType());
else
//.........这里部分代码省略.........