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


C# TypeDeclaration.Clone方法代码示例

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


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

示例1: Set

			static TypeCode Set (DocumentRef doc, TypeDeclaration rtypedecl, CSharpAstResolver resolver)
			{
				var rawCode = GetCommentlessCode (rtypedecl);

				var typedecl = (TypeDeclaration)rtypedecl.Clone ();

				var ns = rtypedecl.Parent as NamespaceDeclaration;
				var nsName = ns == null ? "" : ns.FullName;

				var name = rtypedecl.Name;

				var usings =
					resolver.RootNode.Descendants.
					OfType<UsingDeclaration> ().
					Select (x => x.ToString ().Trim ()).
					ToList ();

				//
				// Find dependencies
				//
				var deps = new List<String> ();
				foreach (var d in rtypedecl.Descendants.OfType<SimpleType> ()) {
					deps.Add (d.Identifier);
				}

				//
				// Find watches and instrument
				//
				var watches = new List<WatchVariable> ();
				foreach (var d in typedecl.Descendants.OfType<VariableInitializer> ()) {
					var endLoc = d.EndLocation;
					var p = d.Parent;
					if (p == null || p.Parent == null)
						continue;
					var nc = p.GetNextSibling (x => x is Comment && x.StartLocation.Line == endLoc.Line);
					if (nc == null || !nc.ToString ().StartsWith ("//="))
						continue;
					var id = Guid.NewGuid ().ToString ();
					var instrument = GetWatchInstrument (id, new IdentifierExpression (d.Name));
					p.Parent.InsertChildBefore (nc, instrument, BlockStatement.StatementRole);
					watches.Add (new WatchVariable {
						Id = id,
						Expression = d.Name,
						ExplicitExpression = "",
						FilePath = doc.FullPath,
						FileLine = nc.StartLocation.Line,
						FileColumn = nc.StartLocation.Column,
					});
				}
				foreach (var d in typedecl.Descendants.OfType<AssignmentExpression> ()) {
					var endLoc = d.EndLocation;
					var p = d.Parent;
					if (p == null || p.Parent == null)
						continue;
					var nc = p.GetNextSibling (x => x is Comment && x.StartLocation.Line == endLoc.Line);
					if (nc == null || !nc.ToString ().StartsWith ("//="))
						continue;
					var id = Guid.NewGuid ().ToString ();
					var instrument = GetWatchInstrument (id, (Expression)d.Left.Clone ());
					p.Parent.InsertChildBefore (nc, instrument, BlockStatement.StatementRole);
					watches.Add (new WatchVariable {
						Id = id,
						Expression = d.Left.ToString (),
						ExplicitExpression = "",
						FilePath = doc.FullPath,
						FileLine = nc.StartLocation.Line,
						FileColumn = nc.StartLocation.Column,
					});
				}
				foreach (var d in typedecl.Descendants.OfType<Comment> ().Where (x => x.CommentType == CommentType.SingleLine)) {
					var m = WatchVariable.CommentContentRe.Match (d.Content);
					if (!m.Success || string.IsNullOrWhiteSpace (m.Groups [1].Value))
						continue;

					var p = d.Parent as BlockStatement;
					if (p == null)
						continue;
					
					var exprText = m.Groups [1].Value.Trim ();
					var parser = new CSharpParser();
					var syntaxTree = parser.Parse("class C { void F() { var __r = " + exprText + "; } }");

					if (syntaxTree.Errors.Count > 0)
						continue;
					var t = syntaxTree.Members.OfType<TypeDeclaration> ().First ();
					var expr = t.Descendants.OfType<VariableInitializer> ().First ().Initializer;
						
					var id = Guid.NewGuid ().ToString ();
					var instrument = GetWatchInstrument (id, expr.Clone ());
					p.InsertChildBefore (d, instrument, BlockStatement.StatementRole);
					watches.Add (new WatchVariable {
						Id = id,
						Expression = exprText,
						ExplicitExpression = m.Groups[1].Value,
						FilePath = doc.FullPath,
						FileLine = d.StartLocation.Line,
						FileColumn = d.StartLocation.Column,
					});
				}

//.........这里部分代码省略.........
开发者ID:mono,项目名称:Continuous,代码行数:101,代码来源:ContinuousEnv.MonoDevelop.cs

示例2: GetCommentlessCode

			static string GetCommentlessCode (TypeDeclaration rtypedecl)
			{
				var t = (TypeDeclaration)rtypedecl.Clone ();
				var cs = t.Descendants.OfType<Comment> ().ToList ();
				foreach (var c in cs) {
					var m = WatchVariable.CommentContentRe.Match (c.Content);
					if (m.Success) {
						c.Content = m.Groups[1].Value + m.Groups[2].Value;
					} else {
						c.Remove ();
					}
				}
				return t.ToString ();
			}
开发者ID:mono,项目名称:Continuous,代码行数:14,代码来源:ContinuousEnv.MonoDevelop.cs


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