Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/System.Xaml/System/Xaml/Context/XamlParserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,12 @@ public XamlType CurrentPreviousChildType
set { _stack.CurrentFrame.PreviousChildType = value; }
}

public bool CurrentContentPropertyAssigned
{
get { return _stack.CurrentFrame.ContentPropertyAssigned; }
set { _stack.CurrentFrame.ContentPropertyAssigned = value; }
}

public bool CurrentMemberIsWriteVisible()
{
Type allowProtectedForType = null;
Expand Down
4 changes: 3 additions & 1 deletion src/System.Xaml/System/Xaml/Context/XamlParserFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ public override void Reset()
InCollectionFromMember = false;
InImplicitArray = false;
InContainerDirective = false;
ContentPropertyAssigned = false;
TypeNamespace = null;
LongestConstructorOfCurrentMarkupExtensionType = null;
EscapeCharacterMapForMarkupExtension = null;
BracketModeParseParameters = null;
}

public XamlType PreviousChildType { get; set; }
public bool ContentPropertyAssigned { get; set; }
public int CtorArgCount { get; set; }
public bool ForcedToUseConstructor { get; set; }
public bool InCollectionFromMember { get; set; }
Expand Down
8 changes: 7 additions & 1 deletion src/System.Xaml/System/Xaml/Parser/XamlPullParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ private XamlNode Logic_StartContentProperty(XamlMember property)
property = XamlLanguage.UnknownContent;
}
_context.CurrentMember = property;
_context.CurrentContentPropertyAssigned = true;
var startProperty = new XamlNode(XamlNodeType.StartMember, property);
// SetLineInfo(startProperty); // No line number info for objects from members.
return startProperty;
Expand Down Expand Up @@ -1131,7 +1132,6 @@ private bool Logic_IsDiscardableWhitespace(XamlText text)
// Theoretically we'd also like to support all type-convertible CPs.
// However, for non-string CPs, 3.0 only surfaced whitespace as text if
// the CP hadn't already been set. For string, it surfaced it in all cases.
// So to avoid a breaking change, we only surface string right now.
if (prop.Type == XamlLanguage.String)
{
return false;
Expand All @@ -1140,6 +1140,12 @@ private bool Logic_IsDiscardableWhitespace(XamlText text)
{
return false;
}
if (!_context.CurrentContentPropertyAssigned
&& _context.CurrentType.TypeConverter != null
&& !_context.CurrentForcedToUseConstructor)
{
return false;
}
}
// ...it's in a type-convertible element
else if (_context.CurrentType.TypeConverter != null && !_context.CurrentForcedToUseConstructor)
Expand Down
49 changes: 49 additions & 0 deletions src/Test/TestCases.Workflows/XamlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,55 @@ public void XamlWorkflowWithInputsOutputs()
outputs["myOutput"].ShouldBe(1);
}

#if !WINDOWS
// The net6.0-windows build uses the WPF System.Xaml, which drops
// whitespace-only argument values; only the local System.Xaml keeps them.
[Theory]
[InlineData(" ")]
[InlineData(" ")]
[InlineData("\t")]
public void WhitespaceOnlyArgumentValueIsPreserved(string value)
{
var xamlString = $@"
<Activity x:Class='WFTemplate'
xmlns='http://schemas.microsoft.com/netfx/2009/xaml/activities'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>
<x:Members>
<x:Property Name='myOutput' Type='OutArgument(x:String)' />
</x:Members>
<Assign>
<Assign.To>
<OutArgument x:TypeArguments='x:String'>[myOutput]</OutArgument>
</Assign.To>
<Assign.Value>
<InArgument x:TypeArguments='x:String' xml:space='preserve'>{value}</InArgument>
</Assign.Value>
</Assign>
</Activity>";
var outputs = InvokeWorkflow(xamlString);
outputs["myOutput"].ShouldBe(value);
}
#endif

[Fact]
public void WhitespaceAroundExpressionElementIsIgnoredWhenSpaceIsPreserved()
{
var xamlString = @"
<Activity x:Class='WFTemplate' xml:space='preserve'
xmlns='http://schemas.microsoft.com/netfx/2009/xaml/activities'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
xmlns:mca='clr-namespace:Microsoft.CSharp.Activities;assembly=System.Activities'>
<Sequence>
<WriteLine>
<InArgument x:TypeArguments='x:String'>
<mca:CSharpValue x:TypeArguments='x:String'>""constant""</mca:CSharpValue>
</InArgument>
</WriteLine>
</Sequence>
</Activity>";
Load(xamlString).ShouldNotBeNull();
}

[Fact]
public void XamlWorkflowWithInputObject()
{
Expand Down