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


C# ITypeDefinition.GetSourceProject方法代码示例

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


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

示例1: AddAttribute

		public static void AddAttribute (ITypeDefinition cls, string name, params object[] parameters)
		{
			bool isOpen;
			string fileName = cls.Region.FileName;
			var buffer = TextFileProvider.Instance.GetTextEditorData (fileName, out isOpen);
			
			var attr = new CodeAttributeDeclaration (name);
			foreach (var parameter in parameters) {
				attr.Arguments.Add (new CodeAttributeArgument (new CodePrimitiveExpression (parameter)));
			}
			
			var type = new CodeTypeDeclaration ("temp");
			type.CustomAttributes.Add (attr);
			
			var provider = ((DotNetProject)cls.GetSourceProject ()).LanguageBinding.GetCodeDomProvider ();
			var sw = new StringWriter ();
			provider.GenerateCodeFromType (type, sw, new CodeGeneratorOptions ());
			string code = sw.ToString ();
			int start = code.IndexOf ('[');
			int end = code.LastIndexOf (']');
			code = code.Substring (start, end - start + 1) + Environment.NewLine;

			int pos = buffer.LocationToOffset (cls.Region.BeginLine, cls.Region.BeginColumn);

			code = buffer.GetLineIndent (cls.Region.BeginLine) + code;
			buffer.Insert (pos, code);
			if (!isOpen) {
				File.WriteAllText (fileName, buffer.Text);
				buffer.Dispose ();
			}
			
		}
开发者ID:dodev,项目名称:monodevelop,代码行数:32,代码来源:CodeGenerationService.cs

示例2: ConvertType

		NSObjectTypeInfo ConvertType (TypeSystemService.ProjectContentWrapper dom, ITypeDefinition type)
		{
			string objcName = null;
			bool isModel = false;
			bool registeredInDesigner = true;
			foreach (var att in type.Attributes) {
				var attType = att.AttributeType;
				if (attType.Equals (dom.Compilation.LookupType (typeNamespace, registerAttType)))  {
					if (type.GetProjectContent () != null) {
						registeredInDesigner &=
							MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (att.Region.FileName);
					}
					
					//type registered with an explicit type name are up to the user to provide a valid name
					var posArgs = att.PositionalArguments;
					if (posArgs.Count == 1 || posArgs.Count == 2)
						objcName = posArgs[0].ConstantValue as string;
					//non-nested types in the root namespace have names accessible from obj-c
					else if (string.IsNullOrEmpty (type.Namespace) && type.Name.IndexOf ('.') < 0)
						objcName = type.Name;
				}
				if (attType.Equals (dom.Compilation.LookupType (typeNamespace, modelAttType))) {
					isModel = true;
				}
			}
			if (string.IsNullOrEmpty (objcName))
				return null;
			string baseType = type.DirectBaseTypes.First ().FullName;
			if (baseType == "System.Object")
				baseType = null;
			var info = new NSObjectTypeInfo (objcName, type.FullName, null, baseType, isModel,
					type.GetSourceProject () != null, registeredInDesigner);
			
			if (info.IsUserType) {
				UpdateTypeMembers (dom, info, type);
				info.DefinedIn = type.Parts.Select (p => (string) p.Region.FileName).ToArray ();
			}
			
			return info;
		}
开发者ID:nocache,项目名称:monodevelop,代码行数:40,代码来源:NSObjectInfoService.cs


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