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


C# TypeDeclaration.InsertChildBefore方法代码示例

本文整理汇总了C#中TypeDeclaration.InsertChildBefore方法的典型用法代码示例。如果您正苦于以下问题:C# TypeDeclaration.InsertChildBefore方法的具体用法?C# TypeDeclaration.InsertChildBefore怎么用?C# TypeDeclaration.InsertChildBefore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TypeDeclaration的用法示例。


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

示例1: VisitTypeDeclaration

			public override void VisitTypeDeclaration (TypeDeclaration typeDeclaration)
			{
				base.VisitTypeDeclaration (typeDeclaration);

				var ctors = typeDeclaration.Members.OfType<ConstructorDeclaration> ().Where (x => (x.Modifiers & Modifiers.Static)==0).ToList ();

				if (ctors.Count == 0)
					return;

				if (ctors.Count > 1) {
					for (int i = 0; i < ctors.Count; i++) {
						var c = ctors [i];
						c.Name = "constructor_" + i;
					}
				}

				//
				// Make sure everyone has a super call
				//
				foreach (var c in ctors) {
					if (c.Initializer.IsNull) {
						c.Initializer = new ConstructorInitializer {
							ConstructorInitializerType = ConstructorInitializerType.Base
						};
					}
				}

				//
				// Move this to a call
				//
				foreach (var c in ctors) {
					if (c.Initializer.ConstructorInitializerType == ConstructorInitializerType.This) {

						var thisInit = c.Initializer;
						var md = GetMethodDef (thisInit);
						var thisCtor = ctors.FirstOrDefault (x => GetMethodDef (x) == (md));

						//
						// Inline this
						//
						var sup = new InvocationExpression (new MemberReferenceExpression (new ThisReferenceExpression (), thisCtor.Name), thisInit.Arguments.Select (x => x.Clone ()));
						c.Body.InsertChildBefore (c.Body.FirstChild, new ExpressionStatement (sup), BlockStatement.StatementRole);

						//
						// Find the new super()
						//
						var subs = new Substitute ();

						ConstructorInitializer baseInit = null;
						if (baseInit == null) {



							subs.Subs = thisCtor.Parameters.Zip (thisInit.Arguments, (x, y) => Tuple.Create (x, y)).ToDictionary (x => x.Item1.Name, x => x.Item2);

							var i = thisCtor.Initializer;
							if (i.ConstructorInitializerType == ConstructorInitializerType.Base) {
								baseInit = (ConstructorInitializer)i.Clone ();
							}
						}

						if (baseInit == null) {
							throw new NotSupportedException ("This initializer to this initializer not supported");
						}

						foreach (var a in baseInit.Arguments) {
							a.AcceptVisitor (subs);
						}

						c.Initializer = baseInit;
					}
				}

				//
				//
				//
				if (ctors.Count == 1) {

					var c = ctors [0];
					var sup = GetBaseInitCall (c, new Substitute ());
					c.Body.InsertChildBefore (c.Body.FirstChild, new ExpressionStatement (sup), BlockStatement.StatementRole);
					ctors [0].Initializer.Remove ();

				} else {

					//
					// Synthesize the 1 constructor
					//
					var newCtor = new ConstructorDeclaration {
						Body = new BlockStatement (),
						Name = "constructor",
					};

					var diffs = GetDiffs (ctors.Select (x => x.Parameters.ToList ()).ToList ());

					newCtor.Parameters.AddRange (diffs.Item1);

					for (int i = 0; i < diffs.Item2.Count; i++) {
						var diff = diffs.Item2 [i];
						var c = ctors [i];
//.........这里部分代码省略.........
开发者ID:RReverser,项目名称:Netjs,代码行数:101,代码来源:CsToTs.cs


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