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


C# ObjectCreateExpression类代码示例

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


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

示例1: VisitObjectCreateExpression

            public override object VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data)
            {
                var type = objectCreateExpression.Type as SimpleType;
                if (type != null && type.TypeArguments.Count > 0)
                    UnlockWith(objectCreateExpression);

                return base.VisitObjectCreateExpression(objectCreateExpression, data);
            }
开发者ID:clausjoergensen,项目名称:strokes,代码行数:8,代码来源:CreateGenericObject.cs

示例2: VisitObjectCreateExpression

            public override object VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data)
            {
                if(objectCreateExpression.Initializer.Elements.Count > 0)
                {
                    UnlockWith(objectCreateExpression.Initializer);
                }

                return base.VisitObjectCreateExpression(objectCreateExpression, data);
            }
开发者ID:clausjoergensen,项目名称:strokes,代码行数:9,代码来源:InstantiateObjectWithInitAchievement.cs

示例3: ArgumentsInfo

        public ArgumentsInfo(IEmitter emitter, ObjectCreateExpression objectCreateExpression)
        {
            this.Emitter = emitter;
            this.Expression = objectCreateExpression;

            var arguments = objectCreateExpression.Arguments.ToList();
            this.ResolveResult = emitter.Resolver.ResolveNode(objectCreateExpression, emitter) as InvocationResolveResult;

            this.BuildArgumentsList(arguments);
            this.BuildTypedArguments(objectCreateExpression.Type);
        }
开发者ID:RashmiPankaj,项目名称:Bridge,代码行数:11,代码来源:ArgumentsInfo.cs

示例4: GetActions

			IEnumerable<CodeAction> GetActions(ObjectCreateExpression objectCreateExpression,
			                                   PrimitiveExpression firstParam, PrimitiveExpression secondParam)
			{
				yield return new CodeAction(context.TranslateString("Swap parameters"), script =>  {
					var newOCE = objectCreateExpression.Clone() as ObjectCreateExpression;
					newOCE.Arguments.Clear();
					newOCE.Arguments.Add(secondParam.Clone());
					newOCE.Arguments.Add(firstParam.Clone());
					script.Replace(objectCreateExpression, newOCE);
				});
			}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:11,代码来源:IncorrectExceptionParameterOrderingIssue.cs

示例5: 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

示例6: VisitObjectCreateExpression

			public override void VisitObjectCreateExpression (ObjectCreateExpression objectCreateExpression)
			{
				base.VisitObjectCreateExpression (objectCreateExpression);
				if (objectCreateExpression.Initializer.IsNull || objectCreateExpression.Initializer.Elements.Count > 0)
					return;

				AddIssue (objectCreateExpression.Initializer, ctx.TranslateString ("Remove redundant empty initializer"),
					script => {
						var expr = (ObjectCreateExpression)objectCreateExpression.Clone ();
						expr.Initializer = ArrayInitializerExpression.Null;
						script.Replace (objectCreateExpression, expr);
					});
			}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:13,代码来源:RedundantObjectOrCollectionInitializerIssue.cs

示例7: AssignmentInCollectionInitializer

		public void AssignmentInCollectionInitializer()
		{
			Expression expr = new ObjectCreateExpression {
				Type = new SimpleType("List"),
				Initializer = new ArrayInitializerExpression(
					new ArrayInitializerExpression(
						new AssignmentExpression(new IdentifierExpression("a"), new PrimitiveExpression(1))
					)
				)
			};
			
			AssertOutput("new List {\n${\n$$a = 1\n$}\n}", expr);
		}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:13,代码来源:CSharpOutputVisitorTests.cs

示例8: VisitObjectCreateExpression

			public override void VisitObjectCreateExpression (ObjectCreateExpression objectCreateExpression)
			{
				base.VisitObjectCreateExpression (objectCreateExpression);

				if (objectCreateExpression.Initializer.IsNull ||
					objectCreateExpression.Arguments.Count > 0 ||
					objectCreateExpression.LParToken.IsNull)
					return;

				AddIssue (objectCreateExpression.LParToken.StartLocation, objectCreateExpression.RParToken.EndLocation,
					ctx.TranslateString ("Remove redundant empty argument list"), script => {
						var expr = new ObjectCreateExpression (objectCreateExpression.Type.Clone ()) {
							Initializer = (ArrayInitializerExpression)objectCreateExpression.Initializer.Clone ()
						};
						script.Replace (objectCreateExpression, expr);
					});
			}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:17,代码来源:RedundantObjectCreationArgumentListIssue.cs

示例9: VisitObjectCreateExpression

			public override void VisitObjectCreateExpression (ObjectCreateExpression objectCreateExpression)
			{
				base.VisitObjectCreateExpression (objectCreateExpression);

				if (objectCreateExpression.Initializer.IsNull ||
					objectCreateExpression.Arguments.Count > 0 ||
					objectCreateExpression.LParToken.IsNull)
					return;

				AddIssue (objectCreateExpression.LParToken.StartLocation, objectCreateExpression.RParToken.EndLocation,
					ctx.TranslateString ("Remove redundant empty argument list"), script => {
						var l1 = objectCreateExpression.LParToken.GetPrevNode ().EndLocation;
						var l2 = objectCreateExpression.RParToken.GetNextNode ().StartLocation;
						var o1 = script.GetCurrentOffset (l1);
						var o2 = script.GetCurrentOffset (l2);

						script.Replace (o1, o2 - o1, " ");
					});
			}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:19,代码来源:RedundantObjectCreationArgumentListIssue.cs

示例10: GetAllValidTypesFromObjectCreation

		static IEnumerable<IType> GetAllValidTypesFromObjectCreation(CSharpAstResolver resolver, ObjectCreateExpression invoke, AstNode parameter)
		{
			int index = GetArgumentIndex(invoke.Arguments, parameter);
			if (index < 0)
				yield break;

			var targetResult = resolver.Resolve(invoke.Type);
			if (targetResult is TypeResolveResult) {
				var type = ((TypeResolveResult)targetResult).Type;
				if (type.Kind == TypeKind.Delegate && index == 0) {
					yield return type;
					yield break;
				}
				foreach (var constructor in type.GetConstructors ()) {
					if (index < constructor.Parameters.Count)
						yield return constructor.Parameters [index].Type;
				}
			}
		}
开发者ID:RHE24,项目名称:SharpDevelop,代码行数:19,代码来源:TypeGuessing.cs

示例11: ArgumentsInfo

        public ArgumentsInfo(IEmitter emitter, ObjectCreateExpression objectCreateExpression)
        {
            this.Emitter = emitter;
            this.Expression = objectCreateExpression;

            var arguments = objectCreateExpression.Arguments.ToList();
            var rr = emitter.Resolver.ResolveNode(objectCreateExpression, emitter);
            var drr = rr as DynamicInvocationResolveResult;
            if (drr != null)
            {
                var group = drr.Target as MethodGroupResolveResult;

                if (group != null && group.Methods.Count() > 1)
                {
                    throw new EmitterException(objectCreateExpression, "Cannot compile this dynamic invocation because there are two or more method overloads with the same parameter count. To work around this limitation, assign the dynamic value to a non-dynamic variable before use or call a method with different parameter count");
                }
            }

            this.ResolveResult = rr as InvocationResolveResult;
            this.BuildArgumentsList(arguments);
            this.BuildTypedArguments(objectCreateExpression.Type);
        }
开发者ID:suyongquan88,项目名称:Bridge,代码行数:22,代码来源:ArgumentsInfo.cs

示例12: VisitObjectCreateExpression

			public override void VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression)
			{
				var type = context.Resolve(objectCreateExpression.Type) as TypeResolveResult;
				if (type == null)
					return;
				var parameters = objectCreateExpression.Arguments;
				if (parameters.Count != 2)
					return;
				var firstParam = parameters.FirstOrNullObject() as PrimitiveExpression;
				var secondParam = parameters.LastOrNullObject() as PrimitiveExpression;
				if (firstParam == null || firstParam.Value.GetType() != typeof(string) ||
					secondParam == null || firstParam.Value.GetType() != typeof(string))
					return;
				var leftLength = (firstParam.Value as string).Length;
				var rightLength = (secondParam.Value as string).Length;

				Func<int, int, bool> func;
				if (!rules.TryGetValue(type.Type.FullName, out func))
					return;
				if (!func(leftLength, rightLength))
					AddIssue(objectCreateExpression,
					         context.TranslateString("The parameters are in the wrong order"),
					         GetActions(objectCreateExpression, firstParam, secondParam));
			}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:24,代码来源:IncorrectExceptionParameterOrderingIssue.cs

示例13: HandleAnonymousMethod

		bool HandleAnonymousMethod(ObjectCreateExpression objectCreateExpression, Expression target, MethodReference methodRef)
		{
			// Anonymous methods are defined in the same assembly, so there's no need to Resolve().
			MethodDefinition method = methodRef as MethodDefinition;
			if (method == null || !method.Name.StartsWith("<", StringComparison.Ordinal))
				return false;
			if (!(method.IsCompilerGenerated() || IsPotentialClosure(method.DeclaringType)))
				return false;
			
			// Decompile the anonymous method:
			
			DecompilerContext subContext = context.Clone();
			subContext.CurrentMethod = method;
			BlockStatement body = AstMethodBodyBuilder.CreateMethodBody(method, subContext);
			TransformationPipeline.RunTransformationsUntil(body, v => v is DelegateConstruction, subContext);
			body.AcceptVisitor(this, null);
			
			AnonymousMethodExpression ame = new AnonymousMethodExpression();
			bool isLambda = false;
			if (method.Parameters.All(p => string.IsNullOrEmpty(p.Name))) {
				ame.HasParameterList = false;
			} else {
				ame.HasParameterList = true;
				ame.Parameters.AddRange(AstBuilder.MakeParameters(method.Parameters));
				if (ame.Parameters.All(p => p.ParameterModifier == ParameterModifier.None)) {
					isLambda = (body.Statements.Count == 1 && body.Statements.Single() is ReturnStatement);
				}
			}
			
			// Replace all occurrences of 'this' in the method body with the delegate's target:
			foreach (AstNode node in body.Descendants) {
				if (node is ThisReferenceExpression)
					node.ReplaceWith(target.Clone());
				
			}
			if (isLambda) {
				LambdaExpression lambda = new LambdaExpression();
				ame.Parameters.MoveTo(lambda.Parameters);
				Expression returnExpr = ((ReturnStatement)body.Statements.Single()).Expression;
				returnExpr.Remove();
				lambda.Body = returnExpr;
				objectCreateExpression.ReplaceWith(lambda);
			} else {
				ame.Body = body;
				objectCreateExpression.ReplaceWith(ame);
			}
			return true;
		}
开发者ID:stgwilli,项目名称:ILSpy,代码行数:48,代码来源:DelegateConstruction.cs

示例14: TransformByteCode


//.........这里部分代码省略.........
						if (dir != null) {
							return new UndocumentedExpression {
								UndocumentedExpressionType = UndocumentedExpressionType.MakeRef,
								Arguments = { dir.Expression.Detach() }
							};
						} else {
							return InlineAssembly(byteCode, args);
						}
					}
				case ILCode.Refanytype:
					return new UndocumentedExpression {
						UndocumentedExpressionType = UndocumentedExpressionType.RefType,
						Arguments = { arg1 }
					}.Member("TypeHandle");
				case ILCode.Refanyval:
					return MakeRef(
						new UndocumentedExpression {
							UndocumentedExpressionType = UndocumentedExpressionType.RefValue,
							Arguments = { arg1, new TypeReferenceExpression(operandAsTypeRef) }
						});
					case ILCode.Newobj: {
						Cecil.TypeReference declaringType = ((MethodReference)operand).DeclaringType;
						if (declaringType is ArrayType) {
							ComposedType ct = AstBuilder.ConvertType((ArrayType)declaringType) as ComposedType;
							if (ct != null && ct.ArraySpecifiers.Count >= 1) {
								var ace = new Ast.ArrayCreateExpression();
								ct.ArraySpecifiers.First().Remove();
								ct.ArraySpecifiers.MoveTo(ace.AdditionalArraySpecifiers);
								ace.Type = ct;
								ace.Arguments.AddRange(args);
								return ace;
							}
						}
						var oce = new Ast.ObjectCreateExpression();
						if (declaringType.IsAnonymousType()) {
							MethodDefinition ctor = ((MethodReference)operand).Resolve();
							if (methodDef != null) {
								oce.Initializer = new ArrayInitializerExpression();
								for (int i = 0; i < args.Count; i++) {
									oce.Initializer.Elements.Add(
										new NamedArgumentExpression {
											Identifier = ctor.Parameters[i].Name,
											Expression = args[i]
										});
								}
							}
							return oce;
						}
						oce.Type = AstBuilder.ConvertType(declaringType);
						oce.Arguments.AddRange(args);
						return oce.WithAnnotation(operand);
					}
					case ILCode.No: return InlineAssembly(byteCode, args);
					case ILCode.Nop: return null;
					case ILCode.Pop: return arg1;
					case ILCode.Readonly: return InlineAssembly(byteCode, args);
				case ILCode.Ret:
					if (methodDef.ReturnType.FullName != "System.Void") {
						return new Ast.ReturnStatement { Expression = arg1 };
					} else {
						return new Ast.ReturnStatement();
					}
					case ILCode.Rethrow: return new Ast.ThrowStatement();
					case ILCode.Sizeof:  return new Ast.SizeOfExpression { Type = operandAsTypeRef };
					case ILCode.Stloc: {
						ILVariable locVar = (ILVariable)operand;
开发者ID:KevinCathcart,项目名称:ILSpy,代码行数:67,代码来源:AstMethodBodyBuilder.cs

示例15: Visit

			public override object Visit (New newExpression)
			{
				var result = new ObjectCreateExpression ();
				var location = LocationsBag.GetLocations (newExpression);
				result.AddChild (new CSharpTokenNode (Convert (newExpression.Location), "new".Length), ObjectCreateExpression.Roles.Keyword);
				
				if (newExpression.TypeRequested != null)
					result.AddChild (ConvertToType (newExpression.TypeRequested), ObjectCreateExpression.Roles.Type);
				if (location != null)
					result.AddChild (new CSharpTokenNode (Convert (location[0]), 1), ObjectCreateExpression.Roles.LPar);
				AddArguments (result, location, newExpression.Arguments);
				
				if (location != null)
					result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), ObjectCreateExpression.Roles.RPar);
				
				return result;
			}
开发者ID:N3X15,项目名称:ILSpy,代码行数:17,代码来源:CSharpParser.cs


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