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


C# XamlBinding.XamlCompletionContext类代码示例

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


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

示例1: Resolve

		public static ResolveResult Resolve(string expression, XamlCompletionContext context)
		{
			return new XamlResolver().Resolve(new ExpressionResult(expression, context), context.ParseInformation, null);
		}
开发者ID:rbrunhuber,项目名称:SharpDevelop,代码行数:4,代码来源:XamlResolver.cs

示例2: DoSetterAndEventSetterCompletion

		void DoSetterAndEventSetterCompletion(XamlCompletionContext context, XamlCompletionItemList completionList) {
			bool isExplicit;
			string element = context.ParentElement.Name.EndsWith("Trigger", StringComparison.Ordinal) ? "Trigger" : context.ParentElement.Name;
			AttributeValue value = MarkupExtensionParser.ParseValue(Utils.LookForTargetTypeValue(context, out isExplicit, element) ?? string.Empty);
			string typeNameString;
			var rr = resolver.ResolveAttributeValue(context, value, out typeNameString);
			IType typeName = rr.Type;

			MemberResolveResult mrr;
			switch (context.Attribute.Name) {
				case "Value":
					AttributeValue propType = MarkupExtensionParser.ParseValue(context.ActiveElement.GetAttributeValue("Property") ?? "");

					if (!propType.IsString)
						break;

					context.Description = XamlContextDescription.AtTag;

					string name = propType.StringValue;

					if (!name.Contains("."))
						name = typeNameString + "." + name;

					mrr = resolver.ResolveExpression(name, context) as MemberResolveResult;

					if (mrr == null || mrr.Member == null)
						break;

					completionList.Items.AddRange(
						generator.MemberCompletion(context, mrr.Member.ReturnType, string.Empty)
					);
					break;
				case "Property":
					completionList.Items.AddRange(
						typeName.GetProperties()
						.Where(p => p.IsPublic && p.CanSet)
						.Select(prop => new XamlCompletionItem(prop))
					);
					break;
				case "Event":
					completionList.Items.AddRange(
						typeName.GetEvents()
						.Where(e => e.IsPublic)
						.Select(evt => new XamlCompletionItem(evt))
					);
					break;
				case "Handler":
					var loc3 = context.Editor.Document.GetLocation(XmlParser.GetActiveElementStartIndex(context.Editor.Document.Text, context.Editor.Caret.Offset));
					AttributeValue evtType = MarkupExtensionParser.ParseValue(context.ActiveElement.GetAttributeValue("Event") ?? "");
					if (!evtType.IsString)
						break;

					string evtName = evtType.StringValue;

					if (!evtName.Contains("."))
						evtName = typeNameString + "." + evtName;

					mrr = resolver.ResolveExpression(evtName, context) as MemberResolveResult;
					if (mrr == null) break;
					var member = mrr.Member as IEvent;
					if (member == null) break;

					completionList.Items.AddRange(generator.FindMatchingEventHandlers(context, member, typeName.Name));
					break;
			}
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:66,代码来源:XamlCodeCompletionBinding.cs

示例3: DoXmlAttributeCompletion

		void DoXmlAttributeCompletion(XamlCompletionContext context, XamlCompletionItemList completionList)
		{
			if (context.Attribute.Name == "xml:space") {
				completionList.Items.AddRange(new[] {
				                              	new XamlCompletionItem("preserve"),
				                              	new XamlCompletionItem("default")
				                              });
			}
			
			if (context.Attribute.Prefix.Equals("xmlns", StringComparison.OrdinalIgnoreCase) ||
			    context.Attribute.Name.Equals("xmlns", StringComparison.OrdinalIgnoreCase)) {
				completionList.Items.AddRange(generator.CreateListForXmlnsCompletion(compilation));
				
				ICompletionListWindow window = context.Editor.ShowCompletionWindow(completionList);
				if (window != null) {
					window.Width = 400;
				}
			}
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:19,代码来源:XamlCodeCompletionBinding.cs

示例4: ResolveCompletionContext

		public static XamlCompletionContext ResolveCompletionContext(ITextEditor editor, char typedValue, int offset)
		{
			var binding = editor.GetService(typeof(XamlTextEditorExtension)) as XamlTextEditorExtension;
			
			if (binding == null)
				throw new InvalidOperationException("Can only use ResolveCompletionContext with a XamlTextEditorExtension.");
			
			var context = new XamlCompletionContext(ResolveContext(editor.FileName, editor.Document, offset)) {
				PressedKey = typedValue,
				Editor = editor
			};
			
			return context;
		}
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:14,代码来源:XamlContextResolver.cs

示例5: CtrlSpace

		bool CtrlSpace(ITextEditor editor, XamlCompletionContext context)
		{
			if (context.Description == XamlContextDescription.InComment
			    || context.Description == XamlContextDescription.InCData
			    || context.ActiveElement == null) {
				return false;
			}
			if (!context.InAttributeValueOrMarkupExtension) {
				XamlCompletionItemList list = generator.CreateListForContext(context);
				string starter = editor.GetWordBeforeCaretExtended().TrimStart('/');
				if (context.Description != XamlContextDescription.None && !string.IsNullOrEmpty(starter)) {
					if (starter.Contains(".")) {
						list.PreselectionLength = starter.Length - starter.IndexOf('.') - 1;
					} else {
						list.PreselectionLength = starter.Length;
					}
				}
				editor.ShowCompletionWindow(list);
				return true;
			}
			// DO NOT USE generator.CreateListForContext here!!! results in endless recursion!!!!
			if (context.Attribute != null) {
				if (!DoMarkupExtensionCompletion(context)) {
					var completionList = new XamlCompletionItemList(context);
					completionList.PreselectionLength = editor.GetWordBeforeCaretExtended().Length;
					if ((context.ActiveElement.Name == "Setter" || context.ActiveElement.Name == "EventSetter") && (context.Attribute.Name == "Property" || context.Attribute.Name == "Value")) {
						DoSetterAndEventSetterCompletion(context, completionList);
						editor.ShowCompletionWindow(completionList);
					} else if ((context.ActiveElement.Name.EndsWith("Trigger", StringComparison.Ordinal) || context.ActiveElement.Name == "Condition") && context.Attribute.Name == "Value") {
						DoTriggerCompletion(context, completionList);
						editor.ShowCompletionWindow(completionList);
					} else if (!DoAttributeCompletion(context, completionList)) {
						DoXmlAttributeCompletion(context, completionList);
					}
					return completionList.Items.Any();
				}
				return true;
			}
			return false;
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:40,代码来源:XamlCodeCompletionBinding.cs

示例6: CreateEventCompletion

		IEnumerable<ICompletionItem> CreateEventCompletion(XamlCompletionContext context, ITypeDefinition td)
		{
			IMethod invoker = td.GetMethods(method => method.Name == "Invoke").FirstOrDefault();
			if (invoker != null && context.ActiveElement != null) {
				var item = context.ActiveElement;
				var resolver = new XamlAstResolver(compilation, context.ParseInformation);
				var mrr = resolver.ResolveAttribute(context.Attribute) as MemberResolveResult;
				IEvent evt;
				if (mrr == null || (evt = mrr.Member as IEvent) == null)
					return EmptyList<ICompletionItem>.Instance;
				int offset = XmlEditor.XmlParser.GetActiveElementStartIndex(context.Editor.Document.Text, context.Editor.Caret.Offset);
				
				if (offset == -1)
					return Enumerable.Empty<ICompletionItem>();
				
				var loc = context.Editor.Document.GetLocation(offset);
				
				string name = context.ActiveElement.GetAttributeValue("Name");
				if (string.IsNullOrEmpty(name))
					name = context.ActiveElement.GetAttributeValue(XamlConst.XamlNamespace, "Name");
				
				return FindMatchingEventHandlers(context, evt, (string.IsNullOrEmpty(name) ? item.Name : name));
			}
			
			return EmptyList<ICompletionItem>.Instance;
		}
开发者ID:hefnerliu,项目名称:SharpDevelop,代码行数:26,代码来源:CompletionDataGenerator.cs

示例7: GetAllTypes

		IEnumerable<ICompletionItem> GetAllTypes(XamlCompletionContext context)
		{
			var items = GetClassesFromContext(context);
			
			foreach (var ns in items) {
				foreach (var c in ns.Value) {
					if (c.Kind == TypeKind.Class && !c.IsDerivedFrom(KnownTypeCode.Attribute))
						yield return new XamlCompletionItem(ns.Key, c);
				}
			}
		}
开发者ID:hefnerliu,项目名称:SharpDevelop,代码行数:11,代码来源:CompletionDataGenerator.cs

示例8: CreateAttributeList

		IList<ICompletionItem> CreateAttributeList(XamlCompletionContext context, bool includeEvents)
		{
			if (context.ParseInformation == null)
				return EmptyList<ICompletionItem>.Instance;
			AXmlElement lastElement = context.ActiveElement;
			IUnresolvedFile file = context.ParseInformation.UnresolvedFile;
			XamlResolver resolver = new XamlResolver(compilation);
			IType type = resolver.ResolveType(lastElement.Namespace, lastElement.LocalName.Trim('.'));
			
			var list = new List<ICompletionItem>();
			
			string xamlPrefix = context.XamlNamespacePrefix;
			string xKey = string.IsNullOrEmpty(xamlPrefix) ? "" : xamlPrefix + ":";
			
			if (context.Description == XamlContextDescription.InTag)
				list.AddRange(XamlConst.GetAllowedItems(context).Select(item => new XamlCompletionItem(item)));
			
			if (string.Equals(lastElement.Prefix, context.XamlNamespacePrefix, StringComparison.OrdinalIgnoreCase) && XamlConst.IsBuiltin(lastElement.LocalName))
				return list;
			
			if (lastElement.LocalName.EndsWith(".", StringComparison.OrdinalIgnoreCase) || context.PressedKey == '.') {
				if (type.Kind == TypeKind.Unknown)
					return EmptyList<ICompletionItem>.Instance;
				
				if (context.ParentElement != null
				    && context.ParentElement.LocalName.StartsWith(lastElement.LocalName.TrimEnd('.'), StringComparison.OrdinalIgnoreCase)) {
					AddAttributes(type, list, includeEvents);
				}
				AddAttachedProperties(type.GetDefinition(), list);
			} else {
				if (type.Kind != TypeKind.Unknown) {
					AddAttributes(type, list, includeEvents);
					list.AddRange(GetListOfAttached(context, null, includeEvents, true));
				}
			}
			
			return list;
		}
开发者ID:hefnerliu,项目名称:SharpDevelop,代码行数:38,代码来源:CompletionDataGenerator.cs

示例9: MemberCompletion

		public IEnumerable<ICompletionItem> MemberCompletion(XamlCompletionContext context, IType type, string textPrefix = "")
		{
			ITextEditor editor = context.Editor;
			compilation = SD.ParserService.GetCompilationForFile(editor.FileName);
			
			string xamlPrefix = context.XamlNamespacePrefix;
			string xKey = string.IsNullOrEmpty(xamlPrefix) ? "" : xamlPrefix + ":";
			
			if (type.Name == typeof(System.Nullable<>).Name) {
				yield return new XamlCompletionItem("{" + xKey + "Null}");
				type = type.TypeArguments.FirstOrDefault();
				if (type == null) yield break;
			}
			
			ITypeDefinition definition = type.GetDefinition();
			
			if (definition == null) yield break;
			
			definition.IsCollectionType();
			
			switch (definition.KnownTypeCode) {
				case KnownTypeCode.Array:
				case KnownTypeCode.ICollection:
				case KnownTypeCode.ICollectionOfT:
				case KnownTypeCode.IEnumerable:
				case KnownTypeCode.IEnumerableOfT:
					yield return new XamlCompletionItem("{" + xKey + "Array}");
					break;
			}
			
			switch (definition.Kind) {
				case TypeKind.Class:
					IType typeName;
					bool isExplicit, showFull = false;
					switch (definition.FullName) {
						case "System.String":
							// return nothing
							break;
						case "System.Type":
							foreach (var item in CreateElementList(context, true))
								yield return item;
							break;
						case "System.Windows.PropertyPath":
							foreach (var item in CreatePropertyPathCompletion(context))
								yield return item;
							break;
						case "System.Windows.DependencyProperty":
							typeName = GetType(context, out isExplicit);
							
							bool isReadOnly = context.ActiveElement.Name.EndsWith("Trigger", StringComparison.Ordinal);
							
							if (!isExplicit && ((context.ValueStartOffset > 0) ? context.RawAttributeValue.Substring(0, context.ValueStartOffset) : "").Contains("."))
								showFull = true;
							
							if (typeName != null) {
								foreach (var item in typeName.GetDependencyProperties(true, !isExplicit, !isReadOnly, showFull))
									yield return item;
							}
							break;
						case "System.Windows.RoutedEvent":
							typeName = GetType(context, out isExplicit);
							
							if (!isExplicit && ((context.ValueStartOffset > 0) ? context.RawAttributeValue.Substring(0, context.ValueStartOffset) : "").Contains("."))
								showFull = true;
							
							if (typeName != null) {
								foreach (var item in typeName.GetRoutedEvents(true, !isExplicit, showFull))
									yield return item;
							}
							break;
						case "System.Windows.Media.FontFamily":
							foreach (var font in Fonts.SystemFontFamilies)
								yield return new XamlCompletionItem(font.FamilyNames.First().Value) { Image = ClassBrowserIconService.Const };
							break;
						default:
							if (context.Description == XamlContextDescription.InMarkupExtension) {
								foreach (IField f in definition.Fields)
									yield return new XamlCompletionItem(textPrefix + f.Name, f);
								foreach (IProperty p in definition.GetProperties(pr => pr.IsPublic && pr.IsStatic && pr.CanGet))
									yield return new XamlCompletionItem(textPrefix + p.Name, p);
							}
							break;
					}
					break;
				case TypeKind.Enum:
					foreach (IField f in definition.Fields)
						yield return new XamlCompletionItem(textPrefix + f.Name, f);
					foreach (IProperty p in definition.Properties.Where(pr => pr.IsPublic && pr.IsStatic && pr.CanGet))
						yield return new XamlCompletionItem(textPrefix + p.Name, p);
					break;
				case TypeKind.Struct:
					switch (definition.FullName) {
						case "System.Boolean":
							yield return new DefaultCompletionItem("True") { Image = ClassBrowserIconService.Const };
							yield return new DefaultCompletionItem("False") { Image = ClassBrowserIconService.Const };
							break;
						case "System.Windows.GridLength":
							yield return new XamlCompletionItem("Auto") { Image = ClassBrowserIconService.Const };
							yield return new XamlCompletionItem("*") { Image = ClassBrowserIconService.Const };
							break;
//.........这里部分代码省略.........
开发者ID:hefnerliu,项目名称:SharpDevelop,代码行数:101,代码来源:CompletionDataGenerator.cs

示例10: GetAllowedItems

		/// <summary>
		/// Returns the list of allow XAML2009 completion items.
		/// </summary>
		public static IEnumerable<string> GetAllowedItems(XamlCompletionContext context)
		{
			string xamlPrefix = context.XamlNamespacePrefix;
			string xKey = string.IsNullOrEmpty(xamlPrefix) ? "" : xamlPrefix + ":";
			var compilation = SD.ParserService.GetCompilationForFile(context.Editor.FileName);
			var resolver = new XamlAstResolver(compilation, context.ParseInformation);
			// TODO : add support for x:Key as attribute element (XAML 2009 only)
			
			switch (context.Description) {
				case XamlContextDescription.AtTag:
					if (context.ParentElement != null && string.Equals(context.ParentElement.Name, xKey + "Members", StringComparison.OrdinalIgnoreCase)) {
						yield return xKey + "Member";
						yield return xKey + "Property";
					} else if (context.ParentElement == context.RootElement && context.RootElement.Attributes.Any(attr => string.Equals(attr.Name, xKey + "Class", StringComparison.OrdinalIgnoreCase))) {
						yield return xKey + "Code";
						yield return xKey + "Members";
					} else {
						if (context.ParentElement != null && string.Equals(context.ParentElement.Name, xKey + "Code", StringComparison.OrdinalIgnoreCase))
							yield break;
						yield return xKey + "Array";
						yield return xKey + "Boolean";
						yield return xKey + "Byte";
						yield return xKey + "Char";
						yield return xKey + "Decimal";
						yield return xKey + "Dictionary";
						yield return xKey + "Double";
						yield return xKey + "Int16";
						yield return xKey + "Int32";
						yield return xKey + "Int64";
						yield return xKey + "List";
						yield return xKey + "Object";
						yield return xKey + "Reference";
						yield return xKey + "Single";
						yield return xKey + "String";
						yield return xKey + "TimeSpan";
						yield return xKey + "Uri";
						if (context.RootElement.Attributes.Any(attr => string.Equals(attr.Name, xKey + "Class", StringComparison.OrdinalIgnoreCase)))
							yield return xKey + "Members";
					}
					break;
				case XamlContextDescription.InTag:
					yield return xKey + "Uid";
					if (context.InRoot) {
						yield return xKey + "Class";
						yield return xKey + "ClassModifier";
						yield return xKey + "Subclass";
						yield return xKey + "Name";
					} else {
						var resourceDictionaryType = compilation.FindType(typeof(ResourceDictionary));
						if (context.ActiveElement != null && string.Equals(context.ActiveElement.Name, xKey + "Array", StringComparison.OrdinalIgnoreCase)) {
							yield return "Type";
						} else if (context.ActiveElement != null && string.Equals(context.ActiveElement.Name, xKey + "Member", StringComparison.OrdinalIgnoreCase)) {
							yield return "Name";
						} else if (context.ActiveElement != null && string.Equals(context.ActiveElement.Name, xKey + "Property", StringComparison.OrdinalIgnoreCase)) {
							yield return "Name";
							yield return "Type";
						} else if (context.RootElement.Attributes.Any(attr => string.Equals(attr.Name, xKey + "Class", StringComparison.OrdinalIgnoreCase))) {
							yield return xKey + "FieldModifier";
							yield return xKey + "Name";
						} else {
							yield return xKey + "Name";
						}
						
						if (context.ParentElement != null) {
							var rr = resolver.ResolveElement(context.ParentElement);
							if (rr != null) {
								if (rr.Type.Equals(resourceDictionaryType)) {
									yield return xKey + "Key";
									yield return xKey + "Shared";
								} else if (rr.Type.TypeParameterCount > 0) {
									yield return xKey + "TypeArguments";
								}
							}
						}
					}
					break;
			}
			yield break;
		}
开发者ID:fanyjie,项目名称:SharpDevelop,代码行数:82,代码来源:XamlConst.cs

示例11: CreateElementList

		public IList<ICompletionItem> CreateElementList(XamlCompletionContext context, bool includeAbstract)
		{
			if (context.ParseInformation == null)
				return EmptyList<ICompletionItem>.Instance;
			
			List<ICompletionItem> result = new List<ICompletionItem>();
			AXmlElement last = context.ParentElement;
			ITextEditor editor = context.Editor;
			compilation = SD.ParserService.GetCompilationForFile(editor.FileName);
			IUnresolvedFile file = context.ParseInformation.UnresolvedFile;
			
			foreach (string item in XamlConst.GetAllowedItems(context)) {
				result.Add(new XamlCompletionItem(item));
			}
			
			IType rt = null;

			if (last != null) {
				if (string.Equals(last.Prefix, context.XamlNamespacePrefix, StringComparison.OrdinalIgnoreCase)) {
					if (string.Equals(last.LocalName, "Members", StringComparison.OrdinalIgnoreCase))
						return result;
					if (string.Equals(last.LocalName, "Code", StringComparison.OrdinalIgnoreCase))
						return result;
				}
				// If we have an element that is not a property or an incomplete
				// definition => interpret element as a type.
				XamlResolver resolver = new XamlResolver(compilation);
				int dotIndex = last.LocalName.IndexOf(".", StringComparison.Ordinal) + 1;
				if (dotIndex < 1 || dotIndex == last.LocalName.Length) {
					rt = resolver.ResolveType(last.Namespace, last.LocalName.Trim('.'));
					string contentPropertyName = GetContentPropertyName(rt.GetDefinition());
					// If the type has a content property specified, use its type for completion.
					if (!string.IsNullOrEmpty(contentPropertyName)) {
						IProperty p = rt.GetProperties(m => m.Name == contentPropertyName).FirstOrDefault();
						if (p != null) {
							rt = p.ReturnType;
						}
					}
				} else {
					string typeName = last.LocalName.Substring(0, dotIndex - 1);
					string memberName = last.LocalName.Substring(dotIndex);
					rt = resolver.ResolveType(last.Namespace, typeName);
					IMember member = rt.GetMembers(m => m.Name == memberName).FirstOrDefault();
					if (member != null) {
						rt = member.ReturnType;
					}
				}
			}
			
			bool parentAdded = false;
			var utd = file.GetInnermostTypeDefinition(editor.Caret.Location);
			ITypeDefinition currentTypeDef = null;
			if (utd != null) {
				currentTypeDef = utd.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly)).GetDefinition();
			}
			MemberLookup memberLookup = new MemberLookup(currentTypeDef, compilation.MainAssembly);
			
			IList<ITypeDefinition> possibleTypesInCollection = EmptyList<ITypeDefinition>.Instance;
			if (rt != null && Extensions.IsListType(rt)) {
				possibleTypesInCollection = rt.GetMethods(m => m.Parameters.Count == 1 && "Add".Equals(m.Name, StringComparison.Ordinal))
					.Select(m => m.Parameters[0].Type.GetDefinition())
					.Where(t => t != null)
					.ToList();
			}
			
			var items = GetClassesFromContext(context);
			
			foreach (var ns in items) {
				foreach (ITypeDefinition td in ns.Value) {
					if (td.Kind != TypeKind.Class && (!includeAbstract || td.Kind != TypeKind.Interface))
						continue;
					if (td.IsStatic || (!includeAbstract && td.IsAbstract) || td.IsDerivedFrom(KnownTypeCode.Attribute))
						continue;
					if (td.Kind == TypeKind.Class && !td.GetConstructors().Any(m => memberLookup.IsAccessible(m, false)))
						continue;
					if (possibleTypesInCollection.Count > 0 && !possibleTypesInCollection.Any(td.IsDerivedFrom))
						continue;
					string fullName = td.Name;
					if (!string.IsNullOrEmpty(ns.Key))
						fullName = ns.Key + ":" + fullName;
					XamlCompletionItem item = new XamlCompletionItem(fullName, td);
					parentAdded = parentAdded || (last != null && item.Text == last.Name);
					result.Add(item);
				}
			}
			
			// TODO reimplement this if it is really necessary.
//			if (!parentAdded && last != null && !last.Name.Contains(".")) {
//				IClass itemClass = cu.CreateType(last.Namespace, last.LocalName.Trim('.')).GetUnderlyingClass();
//				if (itemClass != null)
//					result.Add(new XamlCodeCompletionItem(itemClass, last.Prefix));
//			}
			
			return result;
		}
开发者ID:hefnerliu,项目名称:SharpDevelop,代码行数:95,代码来源:CompletionDataGenerator.cs

示例12: DoSetterAndEventSetterCompletion

		static void DoSetterAndEventSetterCompletion(XamlCompletionContext context, XamlCompletionItemList completionList) {
			bool isExplicit;
			string element = context.ParentElement.Name.EndsWith("Trigger") ? "Trigger" : context.ParentElement.Name;
			AttributeValue value = MarkupExtensionParser.ParseValue(CompletionDataHelper.LookForTargetTypeValue(context, out isExplicit, element) ?? string.Empty);
			
			IReturnType typeName = null;
			string typeNameString = null;
			
			if (!value.IsString) {
				typeNameString = CompletionDataHelper.GetTypeNameFromTypeExtension(value.ExtensionValue, context);
				typeName = CompletionDataHelper.ResolveType(typeNameString, context);
			} else {
				typeNameString = value.StringValue;
				typeName = CompletionDataHelper.ResolveType(value.StringValue, context);
			}
			
			if (typeName != null) {
				switch (context.Attribute.Name) {
					case "Value":
						AttributeValue propType = MarkupExtensionParser.ParseValue(context.ActiveElement.GetAttributeValue("Property") ?? "");

						if (!propType.IsString)
							break;
						
						context.Description = XamlContextDescription.AtTag;
						
						string name = propType.StringValue;
						
						if (!name.Contains("."))
							name = typeNameString + "." + name;
						
						var member = XamlResolver.Resolve(name, context) as MemberResolveResult;
						
						if (member == null || member.ResolvedMember == null)
							break;
						
						completionList.Items.AddRange(
							CompletionDataHelper.MemberCompletion(context, member.ResolvedMember.ReturnType, string.Empty)
						);
						break;
					case "Property":
						completionList.Items.AddRange(
							typeName.GetProperties()
							.Where(p => p.IsPublic && p.CanSet)
							.Select(prop => new XamlCodeCompletionItem(prop))
						);
						break;
					case "Event":
						completionList.Items.AddRange(
							typeName.GetEvents()
							.Where(e => e.IsPublic)
							.Select(evt => new XamlCodeCompletionItem(evt))
						);
						break;
					case "Handler":
						var loc3 = context.Editor.Document.OffsetToPosition(XmlParser.GetActiveElementStartIndex(context.Editor.Document.Text, context.Editor.Caret.Offset));
						AttributeValue evtType = MarkupExtensionParser.ParseValue(context.ActiveElement.GetAttributeValue("Event") ?? "");
						if (!evtType.IsString)
							break;
						
						string evtName = evtType.StringValue;
						
						if (!evtName.Contains("."))
							evtName = typeNameString + "." + evtName;
						
						var evtMember = XamlResolver.Resolve(evtName, context) as MemberResolveResult;
						
						if (evtMember == null || evtMember.ResolvedMember == null || !(evtMember.ResolvedMember is IEvent) || evtMember.ResolvedMember.ReturnType == null)
							break;
						
						IClass c = (evtMember.ResolvedMember as IEvent).ReturnType.GetUnderlyingClass();
						
						if (c == null)
							break;
						
						IMethod invoker = c.Methods.FirstOrDefault(m => m.Name == "Invoke");
						
						if (invoker == null)
							break;
						
						completionList.Items.AddRange(
							CompletionDataHelper.AddMatchingEventHandlers(context, invoker).Add(new NewEventCompletionItem(evtMember.ResolvedMember as IEvent, typeName.Name))
						);
						break;
				}
			}
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:87,代码来源:XamlCodeCompletionBinding.cs

示例13: DoTriggerCompletion

		static void DoTriggerCompletion(XamlCompletionContext context, XamlCompletionItemList completionList) {
			bool isExplicit;
			AttributeValue value = MarkupExtensionParser.ParseValue(CompletionDataHelper.LookForTargetTypeValue(context, out isExplicit, "Trigger") ?? string.Empty);
			
			IReturnType typeName = null;
			string typeNameString = null;
			
			if (!value.IsString) {
				typeNameString = CompletionDataHelper.GetTypeNameFromTypeExtension(value.ExtensionValue, context);
				typeName = CompletionDataHelper.ResolveType(typeNameString, context);
			} else {
				typeNameString = value.StringValue;
				typeName = CompletionDataHelper.ResolveType(value.StringValue, context);
			}
			
			if (typeName != null) {
				switch (context.Attribute.Name) {
					case "Value":
						AttributeValue propType = MarkupExtensionParser.ParseValue(context.ActiveElement.GetAttributeValue("Property") ?? "");
						if (!propType.IsString)
							break;
						
						string name = propType.StringValue;
						
						if (!name.Contains("."))
							name = typeNameString + "." + name;
						
						context.Description = XamlContextDescription.AtTag;
						
						var member = XamlResolver.Resolve(name, context) as MemberResolveResult;
						
						if (member == null || member.ResolvedMember == null)
							break;
						
						completionList.Items.AddRange(
							CompletionDataHelper.MemberCompletion(context, member.ResolvedMember.ReturnType, string.Empty)
						);
						break;
				}
			}
		}
开发者ID:Bombadil77,项目名称:SharpDevelop,代码行数:41,代码来源:XamlCodeCompletionBinding.cs

示例14: ResolveMember

		public static MemberResolveResult ResolveMember(string expression, XamlCompletionContext context)
		{
			if (context.ParseInformation == null || string.IsNullOrEmpty(context.Editor.Document.Text))
				return null;
			
			var expressionResult = new ExpressionResult(expression, context);
			
			XamlResolver resolver = new XamlResolver();
			resolver.resolveExpression = expression;
			resolver.caretLine = expressionResult.Region.BeginLine;
			resolver.caretColumn = expressionResult.Region.BeginColumn;
			resolver.callingClass = context.ParseInformation.CompilationUnit.GetInnermostClass(resolver.caretLine, resolver.caretColumn);
			resolver.context = context;
			
			return resolver.ResolveNamedAttribute(expression);
		}
开发者ID:rbrunhuber,项目名称:SharpDevelop,代码行数:16,代码来源:XamlResolver.cs

示例15: CreateListOfMarkupExtensions

		public IEnumerable<ICompletionItem> CreateListOfMarkupExtensions(XamlCompletionContext context)
		{
			var markupExtensionType = compilation.FindType(typeof(System.Windows.Markup.MarkupExtension))
				.GetDefinition();
			if (markupExtensionType == null)
				yield break;
			string text;
			foreach (var ns in GetClassesFromContext(context)) {
				foreach (var definition in ns.Value.Where(td => td.IsDerivedFrom(markupExtensionType))) {
					text = definition.Name;
					if (text.EndsWith("Extension", StringComparison.Ordinal))
						text = text.Remove(text.Length - "Extension".Length);
					string prefix = ns.Key;
					if (prefix.Length > 0) {
						text = prefix + ":" + text;
					}
					yield return new XamlCompletionItem(text, definition);
				}
			}
			
			text = "Reference";
			if (context.XamlNamespacePrefix != "") {
				text = context.XamlNamespacePrefix + ":" + text;
			}
			yield return new XamlCompletionItem(text);
		}
开发者ID:hefnerliu,项目名称:SharpDevelop,代码行数:26,代码来源:CompletionDataGenerator.cs


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