public ResolveResult ResolveAttributeValue(XamlContext context, AttributeValue value, out string typeNameString) { typeNameString = value.IsString ? value.StringValue : GetTypeNameFromTypeExtension(value.ExtensionValue, context); return ResolveExpression(typeNameString, context); }
public ResolveResult ResolveAttributeValue(string expression, XamlContext context) { if (!context.InAttributeValueOrMarkupExtension) return ErrorResolveResult.UnknownError; if (context.AttributeValue.IsString) return ResolveExpression(expression, context); MarkupExtensionInfo info = Utils.GetMarkupExtensionAtPosition(context.AttributeValue.ExtensionValue, context.ValueStartOffset); object data = Utils.GetMarkupDataAtPosition(info, context.ValueStartOffset); IType extensionType = ResolveExpression(info.ExtensionType, context).Type; if (extensionType.Kind == TypeKind.Unknown) extensionType = ResolveExpression(info.ExtensionType + "Extension", context).Type; if (data is KeyValuePair<string, AttributeValue>) { var kv = (KeyValuePair<string, AttributeValue>)data; if (kv.Value.StartOffset >= context.ValueStartOffset) { IProperty member = extensionType.GetProperties(p => p.Name == expression).FirstOrDefault(); if (member != null) return new MemberResolveResult(new TypeResolveResult(extensionType), member); return new UnknownMemberResolveResult(extensionType, expression, EmptyList<IType>.Instance); } else { } } return ResolveExpression(expression, context); }
public ResolveResult Resolve(ExpressionResult expressionResult, ParseInformation parseInfo, string fileContent) { if (parseInfo == null || (string.IsNullOrEmpty(fileContent) && !(expressionResult.Context is XamlContext))) return null; this.resolveExpression = expressionResult.Expression; this.caretLine = expressionResult.Region.BeginLine; this.caretColumn = expressionResult.Region.BeginColumn; this.callingClass = parseInfo.CompilationUnit.GetInnermostClass(caretLine, caretColumn); this.context = expressionResult.Context as XamlContext ?? CompletionDataHelper.ResolveContext(fileContent, parseInfo.CompilationUnit.FileName, Utils.GetOffsetFromFilePos(fileContent, caretLine, caretColumn)); switch (this.context.Description) { case XamlContextDescription.AtTag: case XamlContextDescription.None: return ResolveElementName(resolveExpression); case XamlContextDescription.InTag: return ResolveAttribute(resolveExpression) ?? ResolveElementName(resolveExpression); case XamlContextDescription.InAttributeValue: MemberResolveResult mrr = ResolveAttribute(context.Attribute.Name); if (mrr != null) { var rr = ResolveAttributeValue(mrr.ResolvedMember, resolveExpression) ?? mrr; return rr; } break; case XamlContextDescription.InMarkupExtension: return ResolveMarkupExtension(resolveExpression); } return null; }
public static string GetNamespacePrefix(string namespaceUri, XamlContext context) { var item = context.XmlnsDefinitions.FirstOrDefault(i => i.Value.XmlNamespace == namespaceUri); if (item.Key != null) return item.Key; return string.Empty; }
internal List <ICompletionItem> GetListOfAttached(XamlContext context, ITypeDefinition attachedType, bool events, bool properties) { List <ICompletionItem> result = new List <ICompletionItem>(); if (attachedType != null) { if (attachedType.Kind == TypeKind.Class && !attachedType.IsDerivedFrom(KnownTypeCode.Attribute)) { if (properties) { AddAttachedProperties(attachedType, result); } if (events) { AddAttachedEvents(attachedType, result); } } } else { foreach (var ns in context.XmlnsDefinitions) { string key = string.IsNullOrEmpty(ns.Key) ? "" : ns.Key + ":"; foreach (ITypeDefinition td in ns.Value.GetContents(compilation)) { if (td.Kind != TypeKind.Class) { continue; } if (td.HasAttached(properties, events)) { result.Add(new XamlCompletionItem(td)); } } } } return(result); }
public ResolveResult ResolveAttributeValue(string expression, XamlContext context) { if (!context.InAttributeValueOrMarkupExtension) { return(ErrorResolveResult.UnknownError); } if (context.AttributeValue.IsString) { return(ResolveExpression(expression, context)); } MarkupExtensionInfo info = Utils.GetMarkupExtensionAtPosition(context.AttributeValue.ExtensionValue, context.ValueStartOffset); object data = Utils.GetMarkupDataAtPosition(info, context.ValueStartOffset); IType extensionType = ResolveExpression(info.ExtensionType, context).Type; if (extensionType.Kind == TypeKind.Unknown) { extensionType = ResolveExpression(info.ExtensionType + "Extension", context).Type; } if (data is KeyValuePair <string, AttributeValue> ) { var kv = (KeyValuePair <string, AttributeValue>)data; if (kv.Value.StartOffset >= context.ValueStartOffset) { IProperty member = extensionType.GetProperties(p => p.Name == expression).FirstOrDefault(); if (member != null) { return(new MemberResolveResult(new TypeResolveResult(extensionType), member)); } return(new UnknownMemberResolveResult(extensionType, expression, EmptyList <IType> .Instance)); } else { } } return(ResolveExpression(expression, context)); }
public ResolveResult ResolveExpression(string expression, XamlContext context) { string prefix, memberName; string name = ParseName(expression, out prefix, out memberName); string namespaceUrl = context.ActiveElement.LookupNamespace(prefix); if (string.IsNullOrEmpty(memberName)) { IType type = ResolveType(namespaceUrl, context.ActiveElement.LocalName); IMember member = type.GetMembers(m => m.Name == name).FirstOrDefault(); if (member == null) { type = ResolveType(namespaceUrl, name); return new TypeResolveResult(type); } else { return new MemberResolveResult(new TypeResolveResult(type), member); } } else { IType type = ResolveType(namespaceUrl, name); IMember member = type.GetMembers(m => m.Name == memberName).FirstOrDefault(); if (member == null) return new UnknownMemberResolveResult(type, memberName, EmptyList<IType>.Instance); return new MemberResolveResult(new TypeResolveResult(type), member); } }
public static string LookForTargetTypeValue(XamlContext context, out bool isExplicit, params string[] elementName) { var ancestors = context.Ancestors; isExplicit = false; for (int i = 0; i < ancestors.Count; i++) { if (ancestors[i].LocalName == "Style" && XamlConst.WpfXamlNamespaces.Contains(ancestors[i].Namespace)) { isExplicit = true; return(ancestors[i].GetAttributeValue("TargetType") ?? string.Empty); } if (ancestors[i].Name.EndsWithAny(elementName.Select(s => "." + s + "s"), StringComparison.Ordinal) && !ancestors[i].Name.StartsWith("Style.", StringComparison.Ordinal)) { return(ancestors[i].Name.Remove(ancestors[i].Name.IndexOf('.'))); } } return(null); }
public ResolveResult Resolve(ExpressionResult expressionResult, ParseInformation parseInfo, string fileContent) { if (parseInfo == null || (string.IsNullOrEmpty(fileContent) && !(expressionResult.Context is XamlContext))) { return(null); } this.resolveExpression = expressionResult.Expression; this.caretLine = expressionResult.Region.BeginLine; this.caretColumn = expressionResult.Region.BeginColumn; this.callingClass = parseInfo.CompilationUnit.GetInnermostClass(caretLine, caretColumn); this.context = expressionResult.Context as XamlContext ?? CompletionDataHelper.ResolveContext(fileContent, parseInfo.CompilationUnit.FileName, Utils.GetOffsetFromFilePos(fileContent, caretLine, caretColumn)); switch (this.context.Description) { case XamlContextDescription.AtTag: case XamlContextDescription.None: return(ResolveElementName(resolveExpression)); case XamlContextDescription.InTag: return(ResolveAttribute(resolveExpression) ?? ResolveElementName(resolveExpression)); case XamlContextDescription.InAttributeValue: MemberResolveResult mrr = ResolveAttribute(context.Attribute.Name); if (mrr != null) { var rr = ResolveAttributeValue(mrr.ResolvedMember, resolveExpression) ?? mrr; return(rr); } break; case XamlContextDescription.InMarkupExtension: return(ResolveMarkupExtension(resolveExpression)); } return(null); }
public HighlightingInfo(string token, int startOffset, int endOffset, int lineOffset, XamlContext context) { if (token == null) { throw new ArgumentNullException("token"); } if (startOffset < 0) { throw new ArgumentOutOfRangeException("startOffset", startOffset, "Value must be greater 0"); } if (endOffset < 0) { throw new ArgumentOutOfRangeException("endOffset", endOffset, "Value must be greater 0"); } if (lineOffset < 0) { throw new ArgumentOutOfRangeException("lineOffset", lineOffset, "Value must be greater 0"); } if (context == null) { throw new ArgumentNullException("context"); } this.token = token; this.startOffset = startOffset; this.endOffset = endOffset; this.lineOffset = lineOffset; this.context = context; }
public static XamlContext ResolveContext(ITextBuffer fileContent, string fileName, int offset) { //using (new DebugTimerObject("ResolveContext")) { XamlParser parser = string.IsNullOrEmpty(fileName) ? new XamlParser() : ParserService.GetParser(fileName) as XamlParser; ParseInformation info = string.IsNullOrEmpty(fileName) ? null : ParserService.GetParseInformation(fileName); using (parser.ParseAndLock(fileContent)) { AXmlDocument document = parser.LastDocument; AXmlObject currentData = document.GetChildAtOffset(offset); string attribute = string.Empty, attributeValue = string.Empty; bool inAttributeValue = false; AttributeValue value = null; bool isRoot = false; bool wasAXmlElement = false; int offsetFromValueStart = -1; List<AXmlElement> ancestors = new List<AXmlElement>(); Dictionary<string, string> xmlns = new Dictionary<string, string>(); List<string> ignored = new List<string>(); string xamlNamespacePrefix = string.Empty; var item = currentData; while (item != document) { if (item is AXmlElement) { AXmlElement element = item as AXmlElement; ancestors.Add(element); foreach (var attr in element.Attributes) { if (attr.IsNamespaceDeclaration) { string prefix = (attr.Name == "xmlns") ? "" : attr.LocalName; if (!xmlns.ContainsKey(prefix)) xmlns.Add(prefix, attr.Value); } if (attr.LocalName == "Ignorable" && attr.Namespace == MarkupCompatibilityNamespace) ignored.AddRange(attr.Value.Split(' ', '\t')); if (string.IsNullOrEmpty(xamlNamespacePrefix) && attr.Value == XamlNamespace) xamlNamespacePrefix = attr.LocalName; } if (!wasAXmlElement && item.Parent is AXmlDocument) isRoot = true; wasAXmlElement = true; } item = item.Parent; } XamlContextDescription description = XamlContextDescription.None; AXmlElement active = null; AXmlElement parent = null; if (currentData.Parent is AXmlTag) { AXmlTag tag = currentData.Parent as AXmlTag; if (tag.IsStartOrEmptyTag) description = XamlContextDescription.InTag; else if (tag.IsComment) description = XamlContextDescription.InComment; else if (tag.IsCData) description = XamlContextDescription.InCData; active = tag.Parent as AXmlElement; } if (currentData is AXmlAttribute) { AXmlAttribute a = currentData as AXmlAttribute; int valueStartOffset = a.StartOffset + (a.Name ?? "").Length + (a.EqualsSign ?? "").Length + 1; attribute = a.Name; attributeValue = a.Value; value = MarkupExtensionParser.ParseValue(attributeValue); inAttributeValue = offset >= valueStartOffset && offset < a.EndOffset; if (inAttributeValue) { offsetFromValueStart = offset - valueStartOffset; description = XamlContextDescription.InAttributeValue; if (value != null && !value.IsString) description = XamlContextDescription.InMarkupExtension; if (attributeValue.StartsWith("{}", StringComparison.Ordinal) && attributeValue.Length > 2) description = XamlContextDescription.InAttributeValue; } else description = XamlContextDescription.InTag; } if (currentData is AXmlTag) { AXmlTag tag = currentData as AXmlTag; if (tag.IsStartOrEmptyTag || tag.IsEndTag) description = XamlContextDescription.AtTag; else if (tag.IsComment) description = XamlContextDescription.InComment; else if (tag.IsCData) description = XamlContextDescription.InCData; active = tag.Parent as AXmlElement; } if (active != ancestors.FirstOrDefault()) parent = ancestors.FirstOrDefault(); else parent = ancestors.Skip(1).FirstOrDefault(); if (active == null) active = parent; var xAttribute = currentData as AXmlAttribute; var context = new XamlContext() { Description = description, ActiveElement = (active == null) ? null : active.ToWrapper(), ParentElement = (parent == null) ? null : parent.ToWrapper(), Ancestors = ancestors.Select(ancestor => ancestor.ToWrapper()).ToList(), Attribute = (xAttribute != null) ? xAttribute.ToWrapper() : null, InRoot = isRoot, AttributeValue = value, RawAttributeValue = attributeValue, ValueStartOffset = offsetFromValueStart, XmlnsDefinitions = xmlns, ParseInformation = info, IgnoredXmlns = ignored.AsReadOnly(), XamlNamespacePrefix = xamlNamespacePrefix }; return context; } //} }
public static XamlContext ResolveContext(FileName fileName, ITextSource fileContent, int offset) { XamlFullParseInformation info = SD.ParserService.Parse(fileName, fileContent) as XamlFullParseInformation; if (info == null) throw new Exception("need full parse info!"); AXmlDocument document = info.Document; AXmlObject currentData = document.GetChildAtOffset(offset); string attributeName = string.Empty, attributeValue = string.Empty; AttributeValue value = null; bool isRoot = false; bool wasAXmlElement = false; int offsetFromValueStart = -1; List<AXmlElement> ancestors = new List<AXmlElement>(); Dictionary<string, XamlNamespace> xmlns = new Dictionary<string, XamlNamespace>(); List<string> ignored = new List<string>(); string xamlNamespacePrefix = string.Empty; var item = currentData; while (item != document) { if (item is AXmlElement) { AXmlElement element = item as AXmlElement; ancestors.Add(element); foreach (var attr in element.Attributes) { if (attr.IsNamespaceDeclaration) { string prefix = (attr.Name == "xmlns") ? "" : attr.LocalName; if (!xmlns.ContainsKey(prefix)) xmlns.Add(prefix, new XamlNamespace(attr.Value)); } if (attr.LocalName == "Ignorable" && attr.Namespace == XamlConst.MarkupCompatibilityNamespace) ignored.AddRange(attr.Value.Split(' ', '\t')); if (string.IsNullOrEmpty(xamlNamespacePrefix) && attr.Value == XamlConst.XamlNamespace) xamlNamespacePrefix = attr.LocalName; } if (!wasAXmlElement && item.Parent is AXmlDocument) isRoot = true; wasAXmlElement = true; } item = item.Parent; } XamlContextDescription description = XamlContextDescription.None; AXmlElement active = null; AXmlElement parent = null; if (currentData is AXmlAttribute) { AXmlAttribute a = currentData as AXmlAttribute; int valueStartOffset = a.ValueSegment.Offset + 1; attributeName = a.Name; attributeValue = a.Value; value = MarkupExtensionParser.ParseValue(attributeValue); if (offset >= valueStartOffset && (offset < a.EndOffset // if length is < 2 one quote is missing || (a.ValueSegment.Length <= 1 && offset <= a.EndOffset))) { offsetFromValueStart = offset - valueStartOffset; description = XamlContextDescription.InAttributeValue; if (value != null && !value.IsString) description = XamlContextDescription.InMarkupExtension; if (attributeValue.StartsWith("{}", StringComparison.Ordinal) && attributeValue.Length > 2) description = XamlContextDescription.InAttributeValue; } else description = XamlContextDescription.InTag; active = a.ParentElement; } else if (currentData is AXmlTag) { AXmlTag tag = currentData as AXmlTag; if (tag.IsStartOrEmptyTag || tag.IsEndTag) { if (tag.NameSegment.EndOffset < offset) description = XamlContextDescription.InTag; else description = XamlContextDescription.AtTag; } else if (tag.IsComment) description = XamlContextDescription.InComment; else if (tag.IsCData) description = XamlContextDescription.InCData; active = tag.Parent as AXmlElement; } if (active != ancestors.FirstOrDefault()) parent = ancestors.FirstOrDefault(); else parent = ancestors.Skip(1).FirstOrDefault(); if (active == null) active = parent; var xAttribute = currentData as AXmlAttribute; var context = new XamlContext() { Description = description, ActiveElement = active, ParentElement = parent, Ancestors = ancestors.AsReadOnly(), Attribute = xAttribute, InRoot = isRoot, AttributeValue = value, RawAttributeValue = attributeValue, ValueStartOffset = offsetFromValueStart, XmlnsDefinitions = xmlns, ParseInformation = info, IgnoredXmlns = ignored.AsReadOnly(), XamlNamespacePrefix = xamlNamespacePrefix }; return context; }
public XamlCompletionContext(XamlContext context) { this.ActiveElement = context.ActiveElement; this.Ancestors = context.Ancestors; this.Attribute = context.Attribute; this.AttributeValue = context.AttributeValue; this.Description = context.Description; this.ParentElement = context.ParentElement; this.ParseInformation = context.ParseInformation; this.RawAttributeValue = context.RawAttributeValue; this.ValueStartOffset = context.ValueStartOffset; this.XmlnsDefinitions = context.XmlnsDefinitions; this.InRoot = context.InRoot; this.IgnoredXmlns = context.IgnoredXmlns; this.XamlNamespacePrefix = context.XamlNamespacePrefix; }
public static string LookForTargetTypeValue(XamlContext context, out bool isExplicit, params string[] elementName) { var ancestors = context.Ancestors; isExplicit = false; for (int i = 0; i < ancestors.Count; i++) { if (ancestors[i].LocalName == "Style" && XamlConst.WpfXamlNamespaces.Contains(ancestors[i].Namespace)) { isExplicit = true; return ancestors[i].GetAttributeValue("TargetType") ?? string.Empty; } if (ancestors[i].Name.EndsWithAny(elementName.Select(s => "." + s + "s"), StringComparison.Ordinal) && !ancestors[i].Name.StartsWith("Style.", StringComparison.Ordinal)) { return ancestors[i].Name.Remove(ancestors[i].Name.IndexOf('.')); } } return null; }
public static ResolveResult Resolve(string expression, XamlContext context) { return new XamlResolver().Resolve(new ExpressionResult(expression, context), context.ParseInformation, null); }
public static XamlContext ResolveContext(FileName fileName, ITextSource fileContent, int offset) { XamlFullParseInformation info = SD.ParserService.Parse(fileName, fileContent) as XamlFullParseInformation; if (info == null) { throw new Exception("need full parse info!"); } AXmlDocument document = info.Document; AXmlObject currentData = document.GetChildAtOffset(offset); string attributeName = string.Empty, attributeValue = string.Empty; AttributeValue value = null; bool isRoot = false; bool wasAXmlElement = false; int offsetFromValueStart = -1; List <AXmlElement> ancestors = new List <AXmlElement>(); Dictionary <string, XamlNamespace> xmlns = new Dictionary <string, XamlNamespace>(); List <string> ignored = new List <string>(); string xamlNamespacePrefix = string.Empty; var item = currentData; AXmlElement root = null; while (item != document) { if (item is AXmlElement) { AXmlElement element = item as AXmlElement; ancestors.Add(element); foreach (var attr in element.Attributes) { if (attr.IsNamespaceDeclaration) { string prefix = (attr.Name == "xmlns") ? "" : attr.LocalName; if (!xmlns.ContainsKey(prefix)) { xmlns.Add(prefix, new XamlNamespace(attr.Value)); } } if (attr.LocalName == "Ignorable" && attr.Namespace == XamlConst.MarkupCompatibilityNamespace) { ignored.AddRange(attr.Value.Split(' ', '\t')); } if (string.IsNullOrEmpty(xamlNamespacePrefix) && attr.Value == XamlConst.XamlNamespace) { xamlNamespacePrefix = attr.LocalName; } } if (element.Parent is AXmlDocument) { root = element; if (!wasAXmlElement) { isRoot = true; } } wasAXmlElement = true; } item = item.Parent; } XamlContextDescription description = XamlContextDescription.None; AXmlElement active = null; AXmlElement parent = null; if (currentData is AXmlAttribute) { AXmlAttribute a = currentData as AXmlAttribute; int valueStartOffset = a.ValueSegment.Offset + 1; attributeName = a.Name; attributeValue = a.Value; value = MarkupExtensionParser.ParseValue(attributeValue); if (offset >= valueStartOffset && (offset < a.EndOffset || // if length is < 2 one quote is missing (a.ValueSegment.Length <= 1 && offset <= a.EndOffset))) { offsetFromValueStart = offset - valueStartOffset; description = XamlContextDescription.InAttributeValue; if (value != null && !value.IsString) { description = XamlContextDescription.InMarkupExtension; } if (attributeValue.StartsWith("{}", StringComparison.Ordinal) && attributeValue.Length > 2) { description = XamlContextDescription.InAttributeValue; } } else { description = XamlContextDescription.InTag; } active = a.ParentElement; } else if (currentData is AXmlTag) { AXmlTag tag = currentData as AXmlTag; if (tag.IsStartOrEmptyTag || tag.IsEndTag) { if (tag.NameSegment.EndOffset < offset) { description = XamlContextDescription.InTag; } else { description = XamlContextDescription.AtTag; } } else if (tag.IsComment) { description = XamlContextDescription.InComment; } else if (tag.IsCData) { description = XamlContextDescription.InCData; } active = tag.Parent as AXmlElement; } if (active != ancestors.FirstOrDefault()) { parent = ancestors.FirstOrDefault(); } else { parent = ancestors.Skip(1).FirstOrDefault(); } if (active == null) { active = parent; } var xAttribute = currentData as AXmlAttribute; var context = new XamlContext() { Description = description, ActiveElement = active, ParentElement = parent, RootElement = root, Ancestors = ancestors.AsReadOnly(), Attribute = xAttribute, InRoot = isRoot, AttributeValue = value, RawAttributeValue = attributeValue, ValueStartOffset = offsetFromValueStart, XmlnsDefinitions = xmlns, ParseInformation = info, IgnoredXmlns = ignored.AsReadOnly(), XamlNamespacePrefix = xamlNamespacePrefix }; return(context); }
public static ResolveResult Resolve(string expression, XamlContext context) { return(new XamlResolver().Resolve(new ExpressionResult(expression, context), context.ParseInformation, null)); }
public XamlCompletionItemList(XamlContext context) { this.context = context; }
void AddClosingTagCompletion(XamlContext context, DefaultCompletionItemList list, XamlAstResolver resolver) { if (context.ParentElement != null && !context.InRoot) { ResolveResult rr = resolver.ResolveElement(context.ParentElement); TypeResolveResult trr = rr as TypeResolveResult; MemberResolveResult mrr = rr as MemberResolveResult; if (trr != null) { if (trr.IsError) return; list.Items.Add(new XamlCompletionItem("/" + context.ParentElement.Name, trr.Type.GetDefinition())); } else if (mrr != null) { if (mrr.IsError) return; list.Items.Add(new XamlCompletionItem("/" + context.ParentElement.Name, mrr.Member)); } } }
IType GetType(XamlContext context, out bool isExplicit) { string targetTypeValue = Utils.LookForTargetTypeValue(context, out isExplicit, "Trigger", "Setter"); AttributeValue value = MarkupExtensionParser.ParseValue(targetTypeValue ?? string.Empty); XamlResolver resolver = new XamlResolver(compilation); return resolver.ResolveAttributeValue(context, value).Type; }
public HighlightingInfo(string token, int startOffset, int endOffset, int lineOffset, XamlContext context) { if (token == null) throw new ArgumentNullException("token"); if (startOffset < 0) throw new ArgumentOutOfRangeException("startOffset", startOffset, "Value must be greater 0"); if (endOffset < 0) throw new ArgumentOutOfRangeException("endOffset", endOffset, "Value must be greater 0"); if (lineOffset < 0) throw new ArgumentOutOfRangeException("lineOffset", lineOffset, "Value must be greater 0"); if (context == null) throw new ArgumentNullException("context"); this.token = token; this.startOffset = startOffset; this.endOffset = endOffset; this.lineOffset = lineOffset; this.context = context; }
IDictionary<string, IEnumerable<ITypeDefinition>> GetClassesFromContext(XamlContext context) { var result = new Dictionary<string, IEnumerable<ITypeDefinition>>(); if (compilation == null) return result; foreach (var ns in context.XmlnsDefinitions) { result.Add(ns.Key, ns.Value.GetContents(compilation)); } return result; }
string GetTypeNameFromTypeExtension(MarkupExtensionInfo info, XamlContext context) { IType type = ResolveExpression(info.ExtensionType, context).Type; if (type.Kind == TypeKind.Unknown) type = ResolveExpression(info.ExtensionType + "Extension", context).Type; if (type.FullName != "System.Windows.Markup.TypeExtension") return string.Empty; var item = info.PositionalArguments.FirstOrDefault(); if (item != null && item.IsString) return item.StringValue; if (info.NamedArguments.TryGetValue("typename", out item)) { if (item.IsString) return item.StringValue; } return string.Empty; }
internal List<ICompletionItem> GetListOfAttached(XamlContext context, ITypeDefinition attachedType, bool events, bool properties) { List<ICompletionItem> result = new List<ICompletionItem>(); if (attachedType != null) { if (attachedType.Kind == TypeKind.Class && !attachedType.IsDerivedFrom(KnownTypeCode.Attribute)) { if (properties) AddAttachedProperties(attachedType, result); if (events) AddAttachedEvents(attachedType, result); } } else { foreach (var ns in context.XmlnsDefinitions) { string key = string.IsNullOrEmpty(ns.Key) ? "" : ns.Key + ":"; foreach (ITypeDefinition td in ns.Value.GetContents(compilation)) { if (td.Kind != TypeKind.Class) continue; if (td.HasAttached(properties, events)) result.Add(new XamlCompletionItem(td)); } } } return result; }
IEnumerable <HighlightingInfo> GetInfo() { int index = -1; XamlContext context = null; do { if (index + 1 >= lineText.Length) { break; } index = lineText.IndexOfAny(index + 1, '=', '.'); if (index > -1) { context = CompletionDataHelper.ResolveContext(snapshot, fileName, offset + index); if (context.ActiveElement == null || context.InAttributeValueOrMarkupExtension || context.InCommentOrCData) { continue; } string propertyName; string token; int startIndex; switch (context.Description) { case XamlContextDescription.AtTag: token = context.ActiveElement.Name; int propertyNameIndex = token.IndexOf('.'); if (propertyNameIndex == -1) { continue; } propertyName = token.Substring(propertyNameIndex + 1); startIndex = lineText.IndexOf(propertyName, index, StringComparison.Ordinal); break; case XamlContextDescription.InTag: if (lineText[index] == '.' || context.Attribute == null) { continue; } token = propertyName = context.Attribute.Name; startIndex = lineText.LastIndexOf(propertyName, index, StringComparison.Ordinal); break; default: continue; } if (startIndex > -1) { yield return(new HighlightingInfo(token, startIndex, startIndex + propertyName.Length, offset, context)); } } } while (index > -1); }
public static IReturnType ResolveType(string typeName, XamlContext context) { if (context.ParseInformation == null) return null; XamlCompilationUnit cu = context.ParseInformation.CompilationUnit as XamlCompilationUnit; if (cu == null) return null; string prefix = ""; int len = typeName.IndexOf(':'); string name = typeName; if (len > 0) { prefix = typeName.Substring(0, len); name = typeName.Substring(len + 1, name.Length - len - 1); } string namespaceName = ""; if (context.XmlnsDefinitions.TryGetValue(prefix, out namespaceName)) { IReturnType rt = cu.CreateType(namespaceName, name); if (rt != null && rt.GetUnderlyingClass() != null) return rt; } return null; }