예제 #1
0
    	public override void LeaveMemberReferenceExpression(MemberReferenceExpression node)
    	{
    		var property = node.Entity as IProperty;
    		if (property == null || node.IsTargetOfAssignment())
    			return;

    		var getter = CodeBuilder.CreatePropertyGet(node.Target, property);

    		// preserve duck typing...
    		if (property.IsDuckTyped)
    			ReplaceCurrentNode(
    				CodeBuilder.CreateCast(
    					TypeSystemServices.DuckType, getter));
    		else
    			ReplaceCurrentNode(getter);
    	}
예제 #2
0
        protected virtual void ProcessMemberReferenceExpression(MemberReferenceExpression node)
        {
            var entity = ResolveMember(node);
            if (null == entity)
                return;

            EnsureRelatedNodeWasVisited(node, entity);
            if (EntityType.Namespace == entity.EntityType)
                MarkRelatedImportAsUsed(node);

            var member = entity as IMember;
            if (member != null)
            {
                if (!AssertTargetContext(node, member))
                {
                    Error(node);
                    return;
                }

                if (EntityType.Method != member.EntityType)
                    BindExpressionType(node, GetInferredType(member));
                else
                    BindExpressionType(node, member.Type);
            }

            // TODO: check for generic methods with no generic args here
            if (EntityType.Property == entity.EntityType)
            {
                IProperty property = (IProperty)entity;
                if (property.IsIndexedProperty())
                {
                    if (!AstUtil.IsTargetOfSlicing(node)
                        && (!property.IsExtension || property.GetParameters().Length > 1))
                    {
                        Error(node, CompilerErrorFactory.PropertyRequiresParameters(MemberAnchorFor(node), entity));
                        return;
                    }
                }
                if (IsWriteOnlyProperty(property) && !IsBeingAssignedTo(node))
                {
                    Error(node, CompilerErrorFactory.PropertyIsWriteOnly(MemberAnchorFor(node), entity));
                }
            }
            else if (EntityType.Event == entity.EntityType)
            {
                if (!AstUtil.IsTargetOfMethodInvocation(node) &&
                    !AstUtil.IsLhsOfInPlaceAddSubtract(node))
                {
                    if (CurrentType == member.DeclaringType)
                    {
                        InternalEvent ev = (InternalEvent)entity;
                        node.Name = ev.BackingField.Name;
                        node.Entity = ev.BackingField;
                        BindExpressionType(node, ev.BackingField.Type);
                        return;
                    }
                    else if (!node.IsTargetOfAssignment()
                             || !IsNull(((BinaryExpression)node.ParentNode).Right))
                    {
                        Error(node, CompilerErrorFactory.EventIsNotAnExpression(node, entity));
                    }
                    else //event=null
                    {
                        EnsureInternalEventInvocation((IEvent) entity, node);
                    }
                }
            }

            Bind(node, entity);
            PostProcessReferenceExpression(node);
        }
예제 #3
0
		override public void LeaveMemberReferenceExpression(MemberReferenceExpression node)
		{
			if (!TypeSystemServices.IsQuackBuiltin(node)) return;
			
			if (node.IsTargetOfAssignment()
				|| AstUtil.IsTargetOfSlicing(node)) return;

			MethodInvocationExpression mie = CodeBuilder.CreateMethodInvocation(
				node.LexicalInfo,
				GetGetPropertyMethod(),
				node.Target,
				CodeBuilder.CreateStringLiteral(node.Name));
			Replace(mie);
		}