Пример #1
0
        internal ResolveResult ResolveElement(AXmlElement element, CancellationToken cancellationToken = default(CancellationToken))
        {
            string namespaceName = element.Namespace;
            string name          = element.LocalName;

            if (name.Contains("."))
            {
                string propertyName = name.Substring(name.IndexOf('.') + 1);
                name = name.Substring(0, name.IndexOf('.'));
                ITypeReference reference  = XamlUnresolvedFile.CreateTypeReference(namespaceName, name);
                IType          type       = reference.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly));
                IMember        member     = FindMember(type, propertyName);
                IMember        underlying = null;
                if (member == null)
                {
                    member = FindAttachedMember(type, propertyName, out underlying);
                }
                if (member == null)
                {
                    return(new UnknownMemberResolveResult(type, propertyName, EmptyList <IType> .Instance));
                }
                if (underlying != null)
                {
                    return(new AttachedMemberResolveResult(new TypeResolveResult(type), underlying, member));
                }
                return(new MemberResolveResult(new TypeResolveResult(type), member));
            }
            else
            {
                ITypeReference reference = XamlUnresolvedFile.CreateTypeReference(namespaceName, name);
                IType          type      = reference.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly));
                return(new TypeResolveResult(type));
            }
        }
Пример #2
0
        public ParseInformation Parse(FileName fileName, ITextSource fileContent, bool fullParseInformationRequested,
                                      IProject parentProject, CancellationToken cancellationToken)
        {
            AXmlParser             parser = new AXmlParser();
            AXmlDocument           document;
            IncrementalParserState newParserState;

            if (fileContent.Version is OnDiskTextSourceVersion)
            {
                document       = parser.Parse(fileContent, cancellationToken);
                newParserState = null;
            }
            else
            {
                document = parser.ParseIncremental(parserState, fileContent, out newParserState, cancellationToken);
            }
            parserState = newParserState;
            XamlUnresolvedFile unresolvedFile = XamlUnresolvedFile.Create(fileName, fileContent, document);
            ParseInformation   parseInfo;

            if (fullParseInformationRequested)
            {
                parseInfo = new XamlFullParseInformation(unresolvedFile, document, fileContent.CreateSnapshot());
            }
            else
            {
                parseInfo = new ParseInformation(unresolvedFile, fileContent.Version, false);
            }
            AddTagComments(document, parseInfo, fileContent);
            return(parseInfo);
        }
		public XamlFullParseInformation(XamlUnresolvedFile unresolvedFile, AXmlDocument document, ITextSource text)
			: base(unresolvedFile, text.Version, true)
		{
			if (unresolvedFile == null)
				throw new ArgumentNullException("unresolvedFile");
			if (document == null)
				throw new ArgumentNullException("document");
			if (text == null)
				throw new ArgumentNullException("text");
			this.document = document;
			this.text = text;
		}
Пример #4
0
		public static XamlUnresolvedFile Create(FileName fileName, ITextSource fileContent, AXmlDocument document)
		{
			XamlUnresolvedFile file = new XamlUnresolvedFile(fileName);
			ReadOnlyDocument textDocument = new ReadOnlyDocument(fileContent, fileName);
			
			file.errors.AddRange(document.SyntaxErrors.Select(err => new Error(ErrorType.Error, err.Description, textDocument.GetLocation(err.StartOffset))));
			var visitor = new XamlDocumentVisitor(file, textDocument);
			visitor.VisitDocument(document);
			if (visitor.TypeDefinition != null)
				file.topLevel = new[] { visitor.TypeDefinition };
			else
				file.topLevel = new IUnresolvedTypeDefinition[0];
			
			return file;
		}
 public XamlFullParseInformation(XamlUnresolvedFile unresolvedFile, AXmlDocument document, ITextSource text)
     : base(unresolvedFile, text.Version, true)
 {
     if (unresolvedFile == null)
     {
         throw new ArgumentNullException("unresolvedFile");
     }
     if (document == null)
     {
         throw new ArgumentNullException("document");
     }
     if (text == null)
     {
         throw new ArgumentNullException("text");
     }
     this.document = document;
     this.text     = text;
 }
Пример #6
0
        public static XamlUnresolvedFile Create(FileName fileName, ITextSource fileContent, AXmlDocument document)
        {
            XamlUnresolvedFile file         = new XamlUnresolvedFile(fileName);
            ReadOnlyDocument   textDocument = new ReadOnlyDocument(fileContent, fileName);

            file.errors.AddRange(document.SyntaxErrors.Select(err => new Error(ErrorType.Error, err.Description, textDocument.GetLocation(err.StartOffset))));
            var visitor = new XamlDocumentVisitor(file, textDocument);

            visitor.VisitDocument(document);
            if (visitor.TypeDefinition != null)
            {
                file.topLevel = new[] { visitor.TypeDefinition }
            }
            ;
            else
            {
                file.topLevel = new IUnresolvedTypeDefinition[0];
            }

            return(file);
        }
Пример #7
0
        internal ResolveResult ResolveAttribute(AXmlAttribute attribute, int offset = -1, CancellationToken cancellationToken = default(CancellationToken))
        {
            IMember member = null, underlying = null;
            IType   type = null;

            if (attribute.Namespace == XamlConst.XamlNamespace)
            {
                switch (attribute.LocalName)
                {
                case "Name":
                    IUnresolvedTypeDefinition typeDefinition = parseInfo.UnresolvedFile.TypeDefinition;
                    if (typeDefinition != null)
                    {
                        type = typeDefinition.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly));
                        IField field = type.GetFields(f => f.Name == attribute.Value).FirstOrDefault();
                        if (field != null)
                        {
                            return(new MemberResolveResult(null, field));
                        }
                    }
                    break;

                case "Class":
                    type = compilation.FindType(new FullTypeName(attribute.Value));
                    return(new TypeResolveResult(type));
                }
            }
            if (attribute.ParentElement == null)
            {
                return(ErrorResolveResult.UnknownError);
            }

            string propertyName = attribute.LocalName;

            if (propertyName.Contains("."))
            {
                string namespaceName = string.IsNullOrEmpty(attribute.Namespace) ? attribute.ParentElement.LookupNamespace("") : attribute.Namespace;
                string name          = propertyName.Substring(0, propertyName.IndexOf('.'));
                propertyName = propertyName.Substring(propertyName.IndexOf('.') + 1);
                ITypeReference reference = XamlUnresolvedFile.CreateTypeReference(namespaceName, name);
                type   = reference.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly));
                member = FindMember(type, propertyName);
                if (member == null)
                {
                    member = FindAttachedMember(type, propertyName, out underlying);
                }
            }
            else
            {
                ITypeReference reference = XamlUnresolvedFile.CreateTypeReference(attribute.ParentElement.Namespace, attribute.ParentElement.LocalName);
                type   = reference.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly));
                member = FindMember(type, propertyName);
            }
            if (member == null)
            {
                return(new UnknownMemberResolveResult(type, propertyName, EmptyList <IType> .Instance));
            }
            if (offset > -1 && attribute.ValueSegment.Contains(offset, 1))
            {
                return(ResolveAttributeValue(member, attribute, cancellationToken));
            }
            if (underlying != null)
            {
                return(new AttachedMemberResolveResult(new TypeResolveResult(underlying.DeclaringType), underlying, member));
            }
            else
            {
                return(new MemberResolveResult(new TypeResolveResult(member.DeclaringType), member));
            }
        }
 public IType ResolveType(string @namespace, string type)
 {
     return(XamlUnresolvedFile.CreateTypeReference(@namespace, type).Resolve(resolveContext));
 }