Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [X] Add compiled converters - Add compiled converters for Flex enums - and for FlexBasis - and for for FlowDirection - Also moves Flowdirection converter attribute from the property to the Type, and fix the Design assembly accordingly - fixes #6547 * Update src/Core/src/Layouts/FlexEnums.cs Co-authored-by: campersau <buchholz.bastian@googlemail.com> Co-authored-by: campersau <buchholz.bastian@googlemail.com>
- Loading branch information
1 parent
4b64fd9
commit 3e37211
Showing
12 changed files
with
103 additions
and
91 deletions.
There are no files selected for viewing
68 changes: 0 additions & 68 deletions
68
src/Controls/docs/Microsoft.Maui.Controls/FlowDirectionConverter.xml
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
src/Controls/src/Build.Tasks/CompiledConverters/EnumTypeConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Maui.Controls.Build.Tasks; | ||
using Microsoft.Maui.Controls.Xaml; | ||
using Mono.Cecil.Cil; | ||
|
||
namespace Microsoft.Maui.Controls.XamlC | ||
{ | ||
class EnumTypeConverter<TEnum> : ICompiledTypeConverter where TEnum: struct | ||
{ | ||
public IEnumerable<Instruction> ConvertFromString(string value, ILContext context, BaseNode node) | ||
{ | ||
if (!string.IsNullOrEmpty(value)) | ||
{ | ||
value = value.Trim(); | ||
if (Enum.TryParse(value, out TEnum enumValue)) | ||
{ | ||
yield return Instruction.Create(OpCodes.Ldc_I4, (int)(object)enumValue); | ||
yield break; | ||
} | ||
} | ||
throw new BuildException(BuildExceptionCode.Conversion, node, null, value, typeof(TEnum)); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/Controls/src/Build.Tasks/CompiledConverters/FlexBasisTypeConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using Microsoft.Maui.Controls.Build.Tasks; | ||
using Microsoft.Maui.Controls.Xaml; | ||
using Microsoft.Maui.Layouts; | ||
using Mono.Cecil.Cil; | ||
|
||
namespace Microsoft.Maui.Controls.XamlC | ||
{ | ||
class FlexBasisTypeConverter : ICompiledTypeConverter | ||
{ | ||
public IEnumerable<Instruction> ConvertFromString(string value, ILContext context, BaseNode node) | ||
{ | ||
var module = context.Body.Method.Module; | ||
if (!string.IsNullOrEmpty(value)) | ||
{ | ||
value = value.Trim(); | ||
if (value == "Auto") | ||
{ | ||
yield return Instruction.Create(OpCodes.Ldsfld, | ||
module.ImportFieldReference(("Microsoft.Maui", "Microsoft.Maui.Layouts", "FlexBasis"), | ||
"Auto", | ||
isStatic: true)); | ||
yield break; | ||
} | ||
if (value.EndsWith("%", StringComparison.OrdinalIgnoreCase) | ||
&& float.TryParse(value.Substring(0, value.Length - 1), NumberStyles.Number, CultureInfo.InvariantCulture, out float relflex)) | ||
{ | ||
yield return Instruction.Create(OpCodes.Ldc_R4, (float)(relflex / 100)); | ||
yield return Instruction.Create(OpCodes.Ldc_I4_1); //isRelative: true | ||
yield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference(("Microsoft.Maui", "Microsoft.Maui.Layouts", "FlexBasis"), parameterTypes: new[] { | ||
("mscorlib", "System", "Single"), | ||
("mscorlib", "System", "Boolean")})); | ||
yield break; | ||
} | ||
if (float.TryParse(value, NumberStyles.Number, CultureInfo.InvariantCulture, out float flex)) | ||
{ | ||
yield return Instruction.Create(OpCodes.Ldc_R4, flex); | ||
yield return Instruction.Create(OpCodes.Ldc_I4_0); //isRelative: false | ||
yield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference(("Microsoft.Maui", "Microsoft.Maui.Layouts", "FlexBasis"), parameterTypes: new[] { | ||
("mscorlib", "System", "Single"), | ||
("mscorlib", "System", "Boolean")})); | ||
yield break; | ||
} | ||
} | ||
throw new BuildException(BuildExceptionCode.Conversion, node, null, value, typeof(FlexBasis)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters