Skip to content
Merged
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
8 changes: 8 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# LinqToXsdCore Release Notes

## Version 3.4.15
Nuget packages:
* https://www.nuget.org/packages/LinqToXsdCore/3.4.15
* https://www.nuget.org/packages/XObjectsCore/3.4.15
* [#88](https://github.com/mamift/LinqToXsdCore/pull/88).
* Fixes a bug which threw an exception when accessing the property getter for an element or attribute whose type is an enum type where the enum value shares the same name with a C# keyword, and thus the string value (ToString) returns a word prefixed with the '@' symbol.
* Fixes an issue with publishing new [XObjectsCodeGen](https://www.nuget.org/packages/XObjectsCodeGen) nuget releases.

## Version 3.4.14
Nuget packages:
* https://www.nuget.org/packages/LinqToXsdCore/3.4.14
Expand Down
2 changes: 1 addition & 1 deletion Version.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>3.4.14</Version>
<Version>3.4.15</Version>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
<Version Condition=" '$(VersionSuffix)' != '' ">$(Version)-$(VersionSuffix)</Version>
</PropertyGroup>
Expand Down
1 change: 0 additions & 1 deletion XObjectsCode/XObjectsCodeGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
<Description>The $(MSBuildProjectName) provides code generation facilities, and is consumed by the LinqToXsdCore command line tool; use the LinqToXsdCore tool to generate code, and link to the XObjectsCore nuget package to consume the generated code in your shipping app or library. Original Authors: Microsoft Corporation.</Description>
<Version>3.2.6</Version>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
<Version Condition=" '$(VersionSuffix)' != '' ">$(Version)-$(VersionSuffix)</Version>
<LangVersion>preview</LangVersion>
Expand Down
16 changes: 15 additions & 1 deletion XObjectsCore/API/XTypedServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,21 @@ public static string ParseValue(XAttribute attribute, XmlSchemaDatatype datatype

var strValue = ParseValue<string>(attribute.Value, attribute.Parent, datatype);
var enumFacet = typeDef.RestrictionFacets.GetEnumFacet(strValue);
return enumFacet != null ? enumFacet.Member : strValue;
if (enumFacet == null)
{
return strValue;
}

string enumFacetMemberValue = enumFacet.Member;

// some enum values can be C# keywords, and to allow compilation, an '@' symbol is added to the name;
// but when converting back, the '@' symbol needs to be removed so the Enum.Parse method can succeed
if (enumFacetMemberValue.Length > 0 && enumFacetMemberValue[0] == '@')
{
return enumFacetMemberValue.Substring(1, enumFacetMemberValue.Length - 1);
}

return enumFacetMemberValue;
}
// Kept for backward compatibility with code generated in previous versions.
// Current generator does not use this method anymore, as attributes with default properties
Expand Down
2 changes: 1 addition & 1 deletion XObjectsTests/LinqToXsdConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Xml.Schema.Linq.Tests;
public class LinqToXsdConfigurationTests
{
[Test]
public void TestSetDefaultVisibility()
public void TestSetDefaultVisibility_EnumValueIsInternal()
{
var config = new Configuration();
var ns1 = new Namespace() {
Expand Down
39 changes: 38 additions & 1 deletion XObjectsTests/WssApiUseTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Microsoft.Schemas.SharePoint;
Expand Down Expand Up @@ -67,5 +68,41 @@ public void TestUseOfDesignerTypeEnum2()
const string expectedValue = nameof(parametersType.ParameterLocalType.DesignerTypeEnum.DataSourceFieldNames);
Assert.IsTrue(underlyingValue.Value == expectedValue);
}

/// <summary>
/// The purpose of this test is to ensure when getting the value of <see cref="Feature.Hidden"/> (which is an enum type), no exceptions occur when parsing and returning
/// the enum string value (which is what happens under the hood with the XObjects API as it invokes <see cref="Enum.Parse(System.Type,System.string)"/>).
/// <para>lower case 'false' does clash with C# keyword.</para>
Comment thread
mamift marked this conversation as resolved.
/// </summary>
[Test]
public void TrueFalseTest_EnumValueClashesWithCSharpKeyword()
{
var newF = new Feature(new FeatureDefinition() {
Hidden = TRUEFALSE.@false
});

var isHidden = newF.Hidden;

Assert.NotNull(isHidden);
Assert.AreEqual(isHidden, TRUEFALSE.@false);
}
Comment thread
mamift marked this conversation as resolved.

/// <summary>
/// The purpose of this test is to ensure when getting the value of <see cref="Feature.Hidden"/> (which is an enum type), no exceptions occur when parsing and returning
/// the enum string value (which is what happens under the hood with the XObjects API as it invokes <see cref="Enum.Parse(System.Type,System.string)"/>).
/// <para>Upper case 'TRUE' does not clash with C# keyword.</para>
/// </summary>
[Test]
public void TrueFalseTest_EnumValueIsNotCSharpKeyword()
{
var newF = new Feature(new FeatureDefinition() {
Hidden = TRUEFALSE.TRUE
});

var isHidden = newF.Hidden;

Assert.NotNull(isHidden);
Assert.AreEqual(isHidden, TRUEFALSE.TRUE);
Comment thread
mamift marked this conversation as resolved.
}
}
}
Loading