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


C# Stetic.GetObjectBindInfo方法代码示例

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


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

示例1: GenerateSteticCodeStructure

		static string GenerateSteticCodeStructure (DotNetProject project, Stetic.ProjectItemInfo item, Stetic.Component component, Stetic.ComponentNameEventArgs args, bool saveToFile, bool overwrite)
		{
			// Generate a class which contains fields for all bound widgets of the component
			
			string name = item != null ? item.Name : component.Name;
			string fileName = GetBuildCodeFileName (project, name);
			
			string ns = "";
			int i = name.LastIndexOf ('.');
			if (i != -1) {
				ns = name.Substring (0, i);
				name = name.Substring (i + 1);
			}
			
			if (saveToFile && !overwrite && File.Exists (fileName))
				return fileName;
			
			if (item != null)
				component = item.Component;
			
			CodeCompileUnit cu = new CodeCompileUnit ();
			
			if (project.UsePartialTypes) {
				CodeNamespace cns = new CodeNamespace (ns);
				cu.Namespaces.Add (cns);
				
				CodeTypeDeclaration type = new CodeTypeDeclaration (name);
				type.IsPartial = true;
				type.Attributes = MemberAttributes.Public;
				type.TypeAttributes = System.Reflection.TypeAttributes.Public;
				cns.Types.Add (type);
				
				foreach (Stetic.ObjectBindInfo binfo in component.GetObjectBindInfo ()) {
					// When a component is being renamed, we have to generate the 
					// corresponding field using the old name, since it will be renamed
					// later using refactory
					string nname = args != null && args.NewName == binfo.Name ? args.OldName : binfo.Name;
					type.Members.Add (
						new CodeMemberField (
							binfo.TypeName,
							nname
						)
					);
				}
			} else {
				if (!saveToFile)
					return fileName;
				CodeNamespace cns = new CodeNamespace ();
				cns.Comments.Add (new CodeCommentStatement ("Generated code for component " + component.Name));
				cu.Namespaces.Add (cns);
			}
			
			CodeDomProvider provider = project.LanguageBinding.GetCodeDomProvider ();
			if (provider == null)
				throw new UserException ("Code generation not supported for language: " + project.LanguageName);
			
			TextWriter fileStream;
			if (saveToFile)
				fileStream = new StreamWriter (fileName);
			else
				fileStream = new StringWriter ();
			
			try {
				var pol = project.Policies.Get<TextStylePolicy> ();
				var options = new CodeGeneratorOptions () {
					IndentString = pol.TabsToSpaces? new string (' ', pol.TabWidth) : "\t",
					BlankLinesBetweenMembers = true,
				};
				
				provider.GenerateCodeFromCompileUnit (cu, fileStream, options);
			} finally {
				fileStream.Close ();
			}

			if (ProjectDomService.HasDom (project)) {
				// Only update the parser database if the project is actually loaded in the IDE.
				if (saveToFile) {
					ProjectDomService.Parse (project, fileName);
					FileService.NotifyFileChanged (fileName);
				} else
					ProjectDomService.Parse (project, fileName, ((StringWriter)fileStream).ToString ());
			}

			return fileName;
		}
开发者ID:Poiros,项目名称:monodevelop,代码行数:85,代码来源:GuiBuilderService.cs


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