Esempio n. 1
0
		internal ResolveResult ResolveAttribute(AXmlAttribute attribute, int offset = -1, CancellationToken cancellationToken = default(CancellationToken))
		{
			IMember member = null, underlying = null;
			IType type = null;
			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);
		}
Esempio n. 2
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);
		}
Esempio n. 3
0
		ResolveResult ResolveAttributeValue(IMember propertyOrEvent, AXmlAttribute attribute, CancellationToken cancellationToken)
		{
			IUnresolvedTypeDefinition typeDefinition = parseInfo.UnresolvedFile.TypeDefinition;
			if (typeDefinition != null) {
				IType type = typeDefinition.Resolve(new SimpleTypeResolveContext(compilation.MainAssembly));
				if (propertyOrEvent is IEvent) {
					var memberLookup = new MemberLookup(type.GetDefinition(), compilation.MainAssembly);
					var rr = memberLookup.Lookup(new ThisResolveResult(type), attribute.Value, EmptyList<IType>.Instance, false);
					if (rr is MethodGroupResolveResult) {
						Conversion conversion = CSharpConversions.Get(compilation).ImplicitConversion(rr, propertyOrEvent.ReturnType);
						IMethod method = conversion.Method;
						if (method == null)
							method = ((MethodGroupResolveResult)rr).Methods.FirstOrDefault();
						if (method != null)
							return new MemberResolveResult(null, method);
					}
					return rr;
				}
				if (propertyOrEvent.Name == "Name") {
					IField field = type.GetFields(f => f.Name == attribute.Value).FirstOrDefault();
					if (field != null)
						return new MemberResolveResult(null, field);
				}
				if (propertyOrEvent.ReturnType.Kind == TypeKind.Enum) {
					IField field = propertyOrEvent.ReturnType.GetFields(f => f.Name == attribute.Value).FirstOrDefault();
					if (field != null)
						return new MemberResolveResult(null, field);
				}
				// TODO might be a markup extension
				return new UnknownMemberResolveResult(type, attribute.Value, EmptyList<IType>.Instance);
			}
			return ErrorResolveResult.UnknownError;
		}
 public override void VisitAttribute(AXmlAttribute attribute)
 {
     if (textSource.GetText(attribute.NameSegment) != attribute.Name)
         throw new InvalidOperationException();
     base.VisitAttribute(attribute);
 }
Esempio n. 5
0
		/// <summary> Visit AXmlAttribute </summary>
		public virtual void VisitAttribute(AXmlAttribute attribute)
		{
			
		}
Esempio n. 6
0
 /// <summary> Visit AXmlAttribute </summary>
 public virtual void VisitAttribute(AXmlAttribute attribute)
 {
 }