当前位置: 首页>>代码示例>>C#>>正文


C# TypeReferenceExpression类代码示例

本文整理汇总了C#中TypeReferenceExpression的典型用法代码示例。如果您正苦于以下问题:C# TypeReferenceExpression类的具体用法?C# TypeReferenceExpression怎么用?C# TypeReferenceExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TypeReferenceExpression类属于命名空间,在下文中一共展示了TypeReferenceExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateMethod

        private static void GenerateMethod()
        {
            Method method = new Method();
            method.Name = "MyNewProc";
            method.MethodType = MethodTypeEnum.Void;
            Param newParam = new Param();
            TypeReferenceExpression newTypeReferenceExpression = new TypeReferenceExpression();
            newTypeReferenceExpression.Name = CodeRush.Language.GetSimpleTypeName("System.Int32");
            newParam.MemberTypeReference = newTypeReferenceExpression;
            newParam.Name = "MyKillerParameter";

            method.Parameters.Add(newParam);

            MethodCall statement = new MethodCall();
            statement.Name = "Start";
            //UnaryIncrement newUnaryIncrement = new UnaryIncrement();
            //ElementReferenceExpression elementReferenceExpression = new ElementReferenceExpression(newParam.Name);
            //newUnaryIncrement.Expression = elementReferenceExpression;
            //statement.AddDetailNode(newUnaryIncrement);
            //int MyKillerParameter = 0;
            //MyKillerParameter++;

            method.AddNode(statement);
            string newCode = CodeRush.Language.GenerateElement(method);
            TextDocument activeTextDocument = CodeRush.Documents.ActiveTextDocument;
            if (activeTextDocument == null)
                return;

            activeTextDocument.InsertText(activeTextDocument.ActiveView.Caret.SourcePoint, newCode);
        }
开发者ID:modulexcite,项目名称:CR_OptionsInverter,代码行数:30,代码来源:PlugIn1.cs

示例2: Run

		public void Run (RefactoringContext context)
		{
			var switchStatement = GetSwitchStatement (context);
			
			var result = context.Resolve (switchStatement.Expression);
			var type = result.Type;
			var newSwitch = (SwitchStatement)switchStatement.Clone ();
			
			var target = new TypeReferenceExpression (context.CreateShortType (result.Type.Resolve (context.TypeResolveContext)));
			foreach (var field in type.GetFields (context.TypeResolveContext)) {
				if (field.IsSynthetic || !field.IsConst)
					continue;
				newSwitch.SwitchSections.Add (new SwitchSection () {
					CaseLabels = {
						new CaseLabel (new MemberReferenceExpression (target.Clone (), field.Name))
					},
					Statements = {
						new BreakStatement ()
					}
				});
			}
			
			newSwitch.SwitchSections.Add (new SwitchSection () {
				CaseLabels = {
					new CaseLabel ()
				},
				Statements = {
					new ThrowStatement (new ObjectCreateExpression (context.CreateShortType ("System", "ArgumentOutOfRangeException")))
				}
			});
			
			using (var script = context.StartScript ()) {
				script.Replace (switchStatement, newSwitch);
			}
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:35,代码来源:GenerateSwitchLabels.cs

示例3: VisitObjectCreateExpression

		public override object VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data)
		{
			if (objectCreateExpression.Arguments.Count() == 2) {
				Expression obj = objectCreateExpression.Arguments.First();
				Expression func = objectCreateExpression.Arguments.Last();
				Annotation annotation = func.Annotation<Annotation>();
				if (annotation != null) {
					IdentifierExpression methodIdent = (IdentifierExpression)((InvocationExpression)func).Arguments.Single();
					MethodReference method = methodIdent.Annotation<MethodReference>();
					if (method != null) {
						if (HandleAnonymousMethod(objectCreateExpression, obj, method))
							return null;
						// Perform the transformation to "new Action(obj.func)".
						obj.Remove();
						methodIdent.Remove();
						if (!annotation.IsVirtual && obj is ThisReferenceExpression) {
							// maybe it's getting the pointer of a base method?
							if (method.DeclaringType != context.CurrentType) {
								obj = new BaseReferenceExpression();
							}
						}
						if (!annotation.IsVirtual && obj is NullReferenceExpression && !method.HasThis) {
							// We're loading a static method.
							// However it is possible to load extension methods with an instance, so we compare the number of arguments:
							bool isExtensionMethod = false;
							TypeReference delegateType = objectCreateExpression.Type.Annotation<TypeReference>();
							if (delegateType != null) {
								TypeDefinition delegateTypeDef = delegateType.Resolve();
								if (delegateTypeDef != null) {
									MethodDefinition invokeMethod = delegateTypeDef.Methods.FirstOrDefault(m => m.Name == "Invoke");
									if (invokeMethod != null) {
										isExtensionMethod = (invokeMethod.Parameters.Count + 1 == method.Parameters.Count);
									}
								}
							}
							if (!isExtensionMethod) {
								obj = new TypeReferenceExpression { Type = AstBuilder.ConvertType(method.DeclaringType) };
							}
						}
						// now transform the identifier into a member reference
						MemberReferenceExpression mre = new MemberReferenceExpression();
						mre.Target = obj;
						mre.MemberName = methodIdent.Identifier;
						methodIdent.TypeArguments.MoveTo(mre.TypeArguments);
						mre.AddAnnotation(method);
						objectCreateExpression.Arguments.Clear();
						objectCreateExpression.Arguments.Add(mre);
						return null;
					}
				}
			}
			return base.VisitObjectCreateExpression(objectCreateExpression, data);
		}
开发者ID:stgwilli,项目名称:ILSpy,代码行数:53,代码来源:DelegateConstruction.cs

示例4: GetActions

        public override IEnumerable<CodeAction> GetActions(RefactoringContext context)
        {
            var switchStatement = GetSwitchStatement(context);
            if (switchStatement == null) {
                yield break;
            }
            var result = context.Resolve(switchStatement.Expression);
            if (result.Type.Kind != TypeKind.Enum) {
                yield break;
            }
            yield return new CodeAction (context.TranslateString("Create switch labels"), script => {
                var type = result.Type;
                var newSwitch = (SwitchStatement)switchStatement.Clone();

                var target = new TypeReferenceExpression (context.CreateShortType(result.Type));
                foreach (var field in type.GetFields ()) {
                    if (field.IsSynthetic || !field.IsConst) {
                        continue;
                    }
                    newSwitch.SwitchSections.Add(new SwitchSection () {
                        CaseLabels = {
                            new CaseLabel (new MemberReferenceExpression (target.Clone(), field.Name))
                        },
                        Statements = {
                            new BreakStatement ()
                        }
                    });
                }

                newSwitch.SwitchSections.Add(new SwitchSection () {
                    CaseLabels = {
                        new CaseLabel ()
                    },
                    Statements = {
                        new ThrowStatement (new ObjectCreateExpression (context.CreateShortType("System", "ArgumentOutOfRangeException")))
                    }
                });

                script.Replace(switchStatement, newSwitch);
            }, switchStatement);
        }
开发者ID:porcus,项目名称:NRefactory,代码行数:41,代码来源:GenerateSwitchLabelsAction.cs

示例5: VisitTypeReferenceExpression

 public void VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression)
 {
     typeReferenceExpression.Type.AcceptVisitor(this);
 }
开发者ID:CompilerKit,项目名称:CodeWalk,代码行数:4,代码来源:AstCsToJson.cs

示例6: VisitTypeReferenceExpression

		public void VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression)
		{
			StartNode(typeReferenceExpression);
			typeReferenceExpression.Type.AcceptVisitor(this);
			EndNode(typeReferenceExpression);
		}
开发者ID:x-strong,项目名称:ILSpy,代码行数:6,代码来源:CSharpOutputVisitor.cs

示例7: ConvertProperty

        Expression ConvertProperty(InvocationExpression invocation)
        {
            if (invocation.Arguments.Count != 2)
                return NotSupported(invocation);

            Match m = getMethodFromHandlePattern.Match(invocation.Arguments.ElementAt(1));
            if (!m.Success)
                return NotSupported(invocation);

            MethodReference mr = m.Get<AstNode>("method").Single().Annotation<MethodReference>();
            if (mr == null)
                return null;

            Expression target = invocation.Arguments.ElementAt(0);
            Expression convertedTarget;
            if (target is NullReferenceExpression) {
                if (m.Has("declaringType"))
                    convertedTarget = new TypeReferenceExpression(m.Get<AstType>("declaringType").Single().Clone());
                else
                    convertedTarget = new TypeReferenceExpression(AstBuilder.ConvertType(mr.DeclaringType));
            } else {
                convertedTarget = Convert(target);
                if (convertedTarget == null)
                    return null;
            }

            return convertedTarget.Member(GetPropertyName(mr)).WithAnnotation(mr);
        }
开发者ID:ropean,项目名称:Usable,代码行数:28,代码来源:ExpressionTreeConverter.cs

示例8: ConvertCall

        Expression ConvertCall(InvocationExpression invocation)
        {
            if (invocation.Arguments.Count < 2)
                return NotSupported(invocation);

            Expression target;
            int firstArgumentPosition;

            Match m = getMethodFromHandlePattern.Match(invocation.Arguments.ElementAt(0));
            if (m.Success) {
                target = null;
                firstArgumentPosition = 1;
            } else {
                m = getMethodFromHandlePattern.Match(invocation.Arguments.ElementAt(1));
                if (!m.Success)
                    return NotSupported(invocation);
                target = invocation.Arguments.ElementAt(0);
                firstArgumentPosition = 2;
            }

            MethodReference mr = m.Get<AstNode>("method").Single().Annotation<MethodReference>();
            if (mr == null)
                return null;

            Expression convertedTarget;
            if (target == null || target is NullReferenceExpression) {
                // static method
                if (m.Has("declaringType"))
                    convertedTarget = new TypeReferenceExpression(m.Get<AstType>("declaringType").Single().Clone());
                else
                    convertedTarget = new TypeReferenceExpression(AstBuilder.ConvertType(mr.DeclaringType));
            } else {
                convertedTarget = Convert(target);
                if (convertedTarget == null)
                    return null;
            }

            MemberReferenceExpression mre = convertedTarget.Member(mr.Name);
            GenericInstanceMethod gim = mr as GenericInstanceMethod;
            if (gim != null) {
                foreach (TypeReference tr in gim.GenericArguments) {
                    mre.TypeArguments.Add(AstBuilder.ConvertType(tr));
                }
            }
            IList<Expression> arguments = null;
            if (invocation.Arguments.Count == firstArgumentPosition + 1) {
                Expression argumentArray = invocation.Arguments.ElementAt(firstArgumentPosition);
                arguments = ConvertExpressionsArray(argumentArray);
            }
            if (arguments == null) {
                arguments = new List<Expression>();
                foreach (Expression argument in invocation.Arguments.Skip(firstArgumentPosition)) {
                    Expression convertedArgument = Convert(argument);
                    if (convertedArgument == null)
                        return null;
                    arguments.Add(convertedArgument);
                }
            }
            MethodDefinition methodDef = mr.Resolve();
            if (methodDef != null && methodDef.IsGetter) {
                PropertyDefinition indexer = AstMethodBodyBuilder.GetIndexer(methodDef);
                if (indexer != null)
                    return new IndexerExpression(mre.Target.Detach(), arguments).WithAnnotation(indexer);
            }
            return new InvocationExpression(mre, arguments).WithAnnotation(mr);
        }
开发者ID:ropean,项目名称:Usable,代码行数:66,代码来源:ExpressionTreeConverter.cs

示例9: VisitTypeReferenceExpression

 public virtual void VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression)
 {
     if (this.ThrowException)
     {
         throw (Exception)this.CreateException(typeReferenceExpression);
     }
 }
开发者ID:fabriciomurta,项目名称:BridgeUnified,代码行数:7,代码来源:Visitor.Exception.cs

示例10: TransformCall

        static AstNode TransformCall(bool isVirtual, object operand, MethodDefinition methodDef, List<Ast.Expression> args)
        {
            Cecil.MethodReference cecilMethod = ((MethodReference)operand);
            Ast.Expression target;
            List<Ast.Expression> methodArgs = new List<Ast.Expression>(args);
            if (cecilMethod.HasThis) {
                target = methodArgs[0];
                methodArgs.RemoveAt(0);

                // Unpack any DirectionExpression that is used as target for the call
                // (calling methods on value types implicitly passes the first argument by reference)
                if (target is DirectionExpression) {
                    target = ((DirectionExpression)target).Expression;
                    target.Remove(); // detach from DirectionExpression
                }
            } else {
                target = new TypeReferenceExpression { Type = AstBuilder.ConvertType(cecilMethod.DeclaringType) };
            }
            if (target is ThisReferenceExpression && !isVirtual) {
                // a non-virtual call on "this" might be a "base"-call.
                if (cecilMethod.DeclaringType != methodDef.DeclaringType) {
                    // If we're not calling a method in the current class; we must be calling one in the base class.
                    target = new BaseReferenceExpression();
                }
            }

            if (cecilMethod.Name == "Get" && cecilMethod.DeclaringType is ArrayType && methodArgs.Count > 1) {
                return target.Indexer(methodArgs);
            } else if (cecilMethod.Name == "Set" && cecilMethod.DeclaringType is ArrayType && methodArgs.Count > 2) {
                return new AssignmentExpression(target.Indexer(methodArgs.GetRange(0, methodArgs.Count - 1)), methodArgs.Last());
            }

            // Resolve the method to figure out whether it is an accessor:
            Cecil.MethodDefinition cecilMethodDef = cecilMethod.Resolve();
            if (cecilMethodDef != null) {
                if (cecilMethodDef.IsGetter && methodArgs.Count == 0) {
                    foreach (var prop in cecilMethodDef.DeclaringType.Properties) {
                        if (prop.GetMethod == cecilMethodDef)
                            return target.Member(prop.Name).WithAnnotation(prop);
                    }
                } else if (cecilMethodDef.IsGetter) { // with parameters
                    PropertyDefinition indexer = GetIndexer(cecilMethodDef);
                    if (indexer != null)
                        return target.Indexer(methodArgs).WithAnnotation(indexer);
                } else if (cecilMethodDef.IsSetter && methodArgs.Count == 1) {
                    foreach (var prop in cecilMethodDef.DeclaringType.Properties) {
                        if (prop.SetMethod == cecilMethodDef)
                            return new Ast.AssignmentExpression(target.Member(prop.Name).WithAnnotation(prop), methodArgs[0]);
                    }
                } else if (cecilMethodDef.IsSetter && methodArgs.Count > 1) {
                    PropertyDefinition indexer = GetIndexer(cecilMethodDef);
                    if (indexer != null)
                        return new AssignmentExpression(
                            target.Indexer(methodArgs.GetRange(0, methodArgs.Count - 1)).WithAnnotation(indexer),
                            methodArgs[methodArgs.Count - 1]
                        );
                } else if (cecilMethodDef.IsAddOn && methodArgs.Count == 1) {
                    foreach (var ev in cecilMethodDef.DeclaringType.Events) {
                        if (ev.AddMethod == cecilMethodDef) {
                            return new Ast.AssignmentExpression {
                                Left = target.Member(ev.Name).WithAnnotation(ev),
                                Operator = AssignmentOperatorType.Add,
                                Right = methodArgs[0]
                            };
                        }
                    }
                } else if (cecilMethodDef.IsRemoveOn && methodArgs.Count == 1) {
                    foreach (var ev in cecilMethodDef.DeclaringType.Events) {
                        if (ev.RemoveMethod == cecilMethodDef) {
                            return new Ast.AssignmentExpression {
                                Left = target.Member(ev.Name).WithAnnotation(ev),
                                Operator = AssignmentOperatorType.Subtract,
                                Right = methodArgs[0]
                            };
                        }
                    }
                }
            }

            // If the method has multiple signatures and an null argument is present, then we must cast the null to the correct type.  This only needs to be done
            // when the parameter number being passed a null has different types.
            if (methodArgs.Exists(arg => arg is NullReferenceExpression))
            {
                var sameNames = cecilMethodDef.DeclaringType.Methods.Where(m => m.Name == cecilMethodDef.Name && m.Parameters.Count == cecilMethodDef.Parameters.Count).ToList();

                if (sameNames.Count > 1)
                {
                    for (int i = cecilMethod.Parameters.Count - 1; 0 <= i; --i)
                    {
                        var arg = methodArgs[i] as NullReferenceExpression;
                        if (arg != null)
                        {
                            if (sameNames.Count != sameNames.Count(m => m.Parameters[i].ParameterType.FullName == cecilMethodDef.Parameters[i].ParameterType.FullName))
                                methodArgs[i] = arg.CastTo(AstBuilder.ConvertType(cecilMethod.Parameters[i].ParameterType));
                        }
                    }
                }
            }

            // Default invocation
//.........这里部分代码省略.........
开发者ID:richardschneider,项目名称:ILSpy,代码行数:101,代码来源:AstMethodBodyBuilder.cs

示例11: VisitTypeReferenceExpression

		public virtual void VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression)
		{
			DebugExpression(typeReferenceExpression);
			StartNode(typeReferenceExpression);
			typeReferenceExpression.Type.AcceptVisitor(this);
			EndNode(typeReferenceExpression);
		}
开发者ID:0xd4d,项目名称:NRefactory,代码行数:7,代码来源:CSharpOutputVisitor.cs

示例12: MemberAccess

	void MemberAccess(
#line  1983 "cs.ATG" 
out Expression expr, Expression target) {

#line  1984 "cs.ATG" 
		List<TypeReference> typeList; 

#line  1986 "cs.ATG" 
		if (ShouldConvertTargetExpressionToTypeReference(target)) {
		TypeReference type = GetTypeReferenceFromExpression(target);
		if (type != null) {
			target = new TypeReferenceExpression(type) { StartLocation = t.Location, EndLocation = t.EndLocation };
		}
		}
		
		Expect(15);
		Identifier();

#line  1995 "cs.ATG" 
		expr = new MemberReferenceExpression(target, t.val); expr.StartLocation = t.Location; expr.EndLocation = t.EndLocation; 
		if (
#line  1996 "cs.ATG" 
IsGenericInSimpleNameOrMemberAccess()) {
			TypeArgumentList(
#line  1997 "cs.ATG" 
out typeList, false);

#line  1998 "cs.ATG" 
			((MemberReferenceExpression)expr).TypeArguments = typeList; 
		}
	}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:31,代码来源:Parser.cs

示例13: PrimaryExpr

	void PrimaryExpr(
#line  1862 "cs.ATG" 
out Expression pexpr) {

#line  1864 "cs.ATG" 
		TypeReference type = null;
		Expression expr;
		pexpr = null;
		

#line  1869 "cs.ATG" 
		Location startLocation = la.Location; 
		if (la.kind == 113) {
			lexer.NextToken();

#line  1871 "cs.ATG" 
			pexpr = new PrimitiveExpression(true, "true");  
		} else if (la.kind == 72) {
			lexer.NextToken();

#line  1872 "cs.ATG" 
			pexpr = new PrimitiveExpression(false, "false"); 
		} else if (la.kind == 90) {
			lexer.NextToken();

#line  1873 "cs.ATG" 
			pexpr = new PrimitiveExpression(null, "null");  
		} else if (la.kind == 2) {
			lexer.NextToken();

#line  1874 "cs.ATG" 
			pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };  
		} else if (
#line  1875 "cs.ATG" 
StartOfQueryExpression()) {
			QueryExpression(
#line  1876 "cs.ATG" 
out pexpr);
		} else if (
#line  1877 "cs.ATG" 
IdentAndDoubleColon()) {
			Identifier();

#line  1878 "cs.ATG" 
			type = new TypeReference(t.val); 
			Expect(10);

#line  1879 "cs.ATG" 
			pexpr = new TypeReferenceExpression(type); 
			Identifier();

#line  1880 "cs.ATG" 
			if (type.Type == "global") { type.IsGlobal = true; type.Type = t.val ?? "?"; } else type.Type += "." + (t.val ?? "?"); 
		} else if (StartOf(19)) {
			Identifier();

#line  1884 "cs.ATG" 
			pexpr = new IdentifierExpression(t.val); 
			if (la.kind == 48 || 
#line  1887 "cs.ATG" 
IsGenericInSimpleNameOrMemberAccess()) {
				if (la.kind == 48) {
					ShortedLambdaExpression(
#line  1886 "cs.ATG" 
(IdentifierExpression)pexpr, out pexpr);
				} else {

#line  1888 "cs.ATG" 
					List<TypeReference> typeList; 
					TypeArgumentList(
#line  1889 "cs.ATG" 
out typeList, false);

#line  1890 "cs.ATG" 
					((IdentifierExpression)pexpr).TypeArguments = typeList; 
				}
			}
		} else if (
#line  1892 "cs.ATG" 
IsLambdaExpression()) {
			LambdaExpression(
#line  1893 "cs.ATG" 
out pexpr);
		} else if (la.kind == 20) {
			lexer.NextToken();
			Expr(
#line  1896 "cs.ATG" 
out expr);
			Expect(21);

#line  1896 "cs.ATG" 
			pexpr = new ParenthesizedExpression(expr); 
		} else if (StartOf(35)) {

#line  1899 "cs.ATG" 
			string val = null; 
			switch (la.kind) {
			case 52: {
				lexer.NextToken();

//.........这里部分代码省略.........
开发者ID:mgagne-atman,项目名称:Projects,代码行数:101,代码来源:Parser.cs

示例14: CreateCodeForInterfaceAttribute

 /// <summary>
 /// Gets the code for interface attribute.
 /// </summary>
 /// <returns>
 /// The code for the interface attribute.
 /// </returns>
 public string CreateCodeForInterfaceAttribute()
 {
   var eb = new ElementBuilder();
   var attributeSection = eb.AddAttributeSection(null);
   var attribute = eb.AddAttribute(attributeSection, ContractClassAttributeName);
   var contractClassTypeReference = new TypeReferenceExpression(this.CreateContractClassName());
   eb.AddArgument(attribute, new TypeOfExpression(contractClassTypeReference));
   return eb.GenerateCode(this.TextDocument.Language);
 }
开发者ID:kevinmiles,项目名称:dxcorecommunityplugins,代码行数:15,代码来源:InterfaceUpdater.cs

示例15: VisitTypeReferenceExpression

		public virtual object VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, object data) {
			Debug.Assert((typeReferenceExpression != null));
			Debug.Assert((typeReferenceExpression.TypeReference != null));
			return typeReferenceExpression.TypeReference.AcceptVisitor(this, data);
		}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:5,代码来源:AbstractASTVisitor.cs


注:本文中的TypeReferenceExpression类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。