diff --git a/samples/ThirdPartyControlsSample/Elements/AlohaKit/Button.generated.cs b/samples/ThirdPartyControlsSample/Elements/AlohaKit/AlhButton.generated.cs
similarity index 98%
rename from samples/ThirdPartyControlsSample/Elements/AlohaKit/Button.generated.cs
rename to samples/ThirdPartyControlsSample/Elements/AlohaKit/AlhButton.generated.cs
index d90aef7c..f34874e4 100644
--- a/samples/ThirdPartyControlsSample/Elements/AlohaKit/Button.generated.cs
+++ b/samples/ThirdPartyControlsSample/Elements/AlohaKit/AlhButton.generated.cs
@@ -18,9 +18,9 @@
namespace BlazorBindings.Maui.Elements.AlohaKit
{
- public partial class Button : BlazorBindings.Maui.Elements.GraphicsView
+ public partial class AlhButton : BlazorBindings.Maui.Elements.GraphicsView
{
- static Button()
+ static AlhButton()
{
RegisterAdditionalHandlers();
}
diff --git a/samples/ThirdPartyControlsSample/Elements/AlohaKit/CheckBox.generated.cs b/samples/ThirdPartyControlsSample/Elements/AlohaKit/AlhCheckBox.generated.cs
similarity index 98%
rename from samples/ThirdPartyControlsSample/Elements/AlohaKit/CheckBox.generated.cs
rename to samples/ThirdPartyControlsSample/Elements/AlohaKit/AlhCheckBox.generated.cs
index 8368d3b8..31bb85cc 100644
--- a/samples/ThirdPartyControlsSample/Elements/AlohaKit/CheckBox.generated.cs
+++ b/samples/ThirdPartyControlsSample/Elements/AlohaKit/AlhCheckBox.generated.cs
@@ -16,9 +16,9 @@
namespace BlazorBindings.Maui.Elements.AlohaKit
{
- public partial class CheckBox : BlazorBindings.Maui.Elements.GraphicsView
+ public partial class AlhCheckBox : BlazorBindings.Maui.Elements.GraphicsView
{
- static CheckBox()
+ static AlhCheckBox()
{
RegisterAdditionalHandlers();
}
diff --git a/samples/ThirdPartyControlsSample/Elements/AlohaKit/ProgressBar.generated.cs b/samples/ThirdPartyControlsSample/Elements/AlohaKit/AlhProgressBar.generated.cs
similarity index 97%
rename from samples/ThirdPartyControlsSample/Elements/AlohaKit/ProgressBar.generated.cs
rename to samples/ThirdPartyControlsSample/Elements/AlohaKit/AlhProgressBar.generated.cs
index 538dca8a..a8baa6ba 100644
--- a/samples/ThirdPartyControlsSample/Elements/AlohaKit/ProgressBar.generated.cs
+++ b/samples/ThirdPartyControlsSample/Elements/AlohaKit/AlhProgressBar.generated.cs
@@ -17,9 +17,9 @@
namespace BlazorBindings.Maui.Elements.AlohaKit
{
- public partial class ProgressBar : BlazorBindings.Maui.Elements.GraphicsView
+ public partial class AlhProgressBar : BlazorBindings.Maui.Elements.GraphicsView
{
- static ProgressBar()
+ static AlhProgressBar()
{
RegisterAdditionalHandlers();
}
diff --git a/samples/ThirdPartyControlsSample/Elements/AlohaKit/Slider.generated.cs b/samples/ThirdPartyControlsSample/Elements/AlohaKit/AlhSlider.generated.cs
similarity index 98%
rename from samples/ThirdPartyControlsSample/Elements/AlohaKit/Slider.generated.cs
rename to samples/ThirdPartyControlsSample/Elements/AlohaKit/AlhSlider.generated.cs
index f7163527..b1d1f031 100644
--- a/samples/ThirdPartyControlsSample/Elements/AlohaKit/Slider.generated.cs
+++ b/samples/ThirdPartyControlsSample/Elements/AlohaKit/AlhSlider.generated.cs
@@ -16,9 +16,9 @@
namespace BlazorBindings.Maui.Elements.AlohaKit
{
- public partial class Slider : BlazorBindings.Maui.Elements.GraphicsView
+ public partial class AlhSlider : BlazorBindings.Maui.Elements.GraphicsView
{
- static Slider()
+ static AlhSlider()
{
RegisterAdditionalHandlers();
}
diff --git a/samples/ThirdPartyControlsSample/Pages/AlohaKitPage.razor b/samples/ThirdPartyControlsSample/Pages/AlohaKitPage.razor
index 569cd972..2db1c4aa 100644
--- a/samples/ThirdPartyControlsSample/Pages/AlohaKitPage.razor
+++ b/samples/ThirdPartyControlsSample/Pages/AlohaKitPage.razor
@@ -13,7 +13,7 @@
-
+
@**@
@@ -37,22 +37,22 @@
-
+
-
+
-
-
+
+
-
+
-
-
+
+
-@code {
+ @code {
int ratingValue = 3;
string RatingDescription => ratingValue switch
{
diff --git a/samples/ThirdPartyControlsSample/Properties/Elements.cs b/samples/ThirdPartyControlsSample/Properties/Elements.cs
index af43d142..8cd0933b 100644
--- a/samples/ThirdPartyControlsSample/Properties/Elements.cs
+++ b/samples/ThirdPartyControlsSample/Properties/Elements.cs
@@ -6,15 +6,15 @@
[assembly: GenerateComponent(typeof(Rating))]
[assembly: GenerateComponent(typeof(BusyIndicator))]
[assembly: GenerateComponent(typeof(Avatar))]
-[assembly: GenerateComponent(typeof(AlohaKit.Controls.Button))]
-[assembly: GenerateComponent(typeof(AlohaKit.Controls.CheckBox))]
-[assembly: GenerateComponent(typeof(AlohaKit.Controls.ProgressBar))]
+[assembly: GenerateComponent(typeof(AlohaKit.Controls.Button), Aliases = new[] { "Button:AlhButton" })]
+[assembly: GenerateComponent(typeof(AlohaKit.Controls.CheckBox), Aliases = new[] { "CheckBox:AlhCheckBox" })]
+[assembly: GenerateComponent(typeof(AlohaKit.Controls.ProgressBar), Aliases = new[] { "ProgressBar:AlhProgressBar" })]
[assembly: GenerateComponent(typeof(NumericUpDown))]
[assembly: GenerateComponent(typeof(ProgressRadial))]
[assembly: GenerateComponent(typeof(ToggleSwitch),
Exclude = new[] { nameof(ToggleSwitch.Toggled) },
PropertyChangedEvents = new[] { nameof(ToggleSwitch.IsOn) })]
-[assembly: GenerateComponent(typeof(AlohaKit.Controls.Slider))]
+[assembly: GenerateComponent(typeof(AlohaKit.Controls.Slider), Aliases = new[] { "Slider:AlhSlider" })]
[assembly: GenerateComponent(typeof(PulseIcon))]
// CommunityToolkit
diff --git a/src/BlazorBindings.Maui.ComponentGenerator/ComponentWrapperGenerator.cs b/src/BlazorBindings.Maui.ComponentGenerator/ComponentWrapperGenerator.cs
index c3f92506..6e6343bc 100644
--- a/src/BlazorBindings.Maui.ComponentGenerator/ComponentWrapperGenerator.cs
+++ b/src/BlazorBindings.Maui.ComponentGenerator/ComponentWrapperGenerator.cs
@@ -24,22 +24,24 @@ public partial class ComponentWrapperGenerator
//}
var typeToGenerate = generatedInfo.TypeSymbol;
- var componentName = typeToGenerate.Name;
+ var componentName = generatedInfo.TypeAlias ?? typeToGenerate.Name;
var componentNamespace = GetComponentNamespace(typeToGenerate);
var baseType = GetBaseTypeOfInterest(typeToGenerate);
- var componentBaseName = componentNamespace == GetComponentNamespace(baseType)
- ? baseType.Name
- : $"{GetComponentNamespace(baseType)}.{baseType.Name}";
+ var componentBaseName = generatedInfo.BaseTypeInfo?.TypeAlias ?? baseType.Name;
+
+ if (componentNamespace != GetComponentNamespace(baseType))
+ componentBaseName = $"{GetComponentNamespace(baseType)}.{componentBaseName}";
// header
var headerText = generatedInfo.FileHeader;
// usings
var usings = GetDefaultUsings(typeToGenerate, componentNamespace);
- var componentNamespacePrefix = GetNamespacePrefix(typeToGenerate, usings);
var generatedType = new GeneratedTypeInfo(compilation, generatedInfo, componentName, componentBaseName, typeToGenerate, usings);
+ var mauiTypeName = generatedType.GetTypeNameAndAddNamespace(typeToGenerate);
+
// props
var valueProperties = GeneratedPropertyInfo.GetValueProperties(generatedType);
var contentProperties = GeneratedPropertyInfo.GetContentProperties(generatedType);
@@ -130,7 +132,7 @@ namespace {componentNamespace}
{staticConstructorBody.Trim()}
}}
{propertyDeclarations}
- public new {componentNamespacePrefix}{componentName} NativeControl => ({componentNamespacePrefix}{componentName})((BindableObject)this).NativeControl;
+ public new {mauiTypeName} NativeControl => ({mauiTypeName})((BindableObject)this).NativeControl;
{createNativeElement}
{handleParameter}{renderAdditionalElementContent}
@@ -168,32 +170,6 @@ private static List GetDefaultUsings(INamedTypeSymbol typeToGene
return usings;
}
- private static string GetNamespacePrefix(INamedTypeSymbol type, List usings)
- {
- // Check if there's a 'using' already. If so, check if it has an alias. If not, add a new 'using'.
- var namespaceAlias = string.Empty;
- var namespaceName = type.ContainingNamespace.GetFullName();
-
- var existingUsing = usings.FirstOrDefault(u => u.Namespace == namespaceName);
- if (existingUsing == null)
- {
- usings.Add(new UsingStatement { Namespace = namespaceName, IsUsed = true, });
- return string.Empty;
- }
- else
- {
- existingUsing.IsUsed = true;
- if (existingUsing.Alias != null)
- {
- return existingUsing.Alias + ".";
- }
- else
- {
- return string.Empty;
- }
- }
- }
-
internal static string GetXmlDocContents(ISymbol symbol, string indent)
{
var xmlDocString = symbol.GetDocumentationCommentXml();
diff --git a/src/BlazorBindings.Maui.ComponentGenerator/GenerateComponentData.cs b/src/BlazorBindings.Maui.ComponentGenerator/GenerateComponentData.cs
index ff56bece..8ed03d63 100644
--- a/src/BlazorBindings.Maui.ComponentGenerator/GenerateComponentData.cs
+++ b/src/BlazorBindings.Maui.ComponentGenerator/GenerateComponentData.cs
@@ -9,6 +9,7 @@ public class GenerateComponentSettings
private bool _isForcedGeneric;
public string FileHeader { get; set; }
+ public string TypeAlias { get; set; }
public INamedTypeSymbol TypeSymbol { get; set; }
public HashSet Exclude { get; set; }
public HashSet Include { get; set; }
diff --git a/src/BlazorBindings.Maui.ComponentGenerator/Program.cs b/src/BlazorBindings.Maui.ComponentGenerator/Program.cs
index c1713e48..f7c5340b 100644
--- a/src/BlazorBindings.Maui.ComponentGenerator/Program.cs
+++ b/src/BlazorBindings.Maui.ComponentGenerator/Program.cs
@@ -74,17 +74,27 @@ private static GenerateComponentSettings[] GetTypesToGenerate(Compilation compil
.Where(a => a.AttributeClass?.ToDisplayString() == "BlazorBindings.Maui.ComponentGenerator.GenerateComponentAttribute")
.Select(a =>
{
+ var typeSymbol = a.ConstructorArguments.FirstOrDefault().Value as INamedTypeSymbol;
+
+ var propertiesAliases = GetNamedArgumentValues(a, "Aliases")
+ .Select(v => v.Split(':'))
+ .ToDictionary(v => v[0], v => v[1]);
+
+ // Type alias has type name as a key.
+ propertiesAliases.Remove(typeSymbol.Name, out var typeAlias);
+
return new GenerateComponentSettings
{
FileHeader = FileHeader,
- TypeSymbol = a.ConstructorArguments.FirstOrDefault().Value as INamedTypeSymbol,
+ TypeAlias = typeAlias,
+ TypeSymbol = typeSymbol,
Exclude = GetNamedArgumentValues(a, "Exclude").ToHashSet(),
Include = GetNamedArgumentValues(a, "Include").ToHashSet(),
ContentProperties = GetNamedArgumentValues(a, "ContentProperties").ToHashSet(),
PropertyChangedEvents = GetNamedArgumentValues(a, "PropertyChangedEvents"),
GenericProperties = GetNamedArgumentValues(a, "GenericProperties").Select(v => v.Split(':')).ToDictionary(v => v[0],
v => v.ElementAtOrDefault(1) is string genericArgName ? compilation.GetTypeByMetadataName(genericArgName) : null),
- Aliases = GetNamedArgumentValues(a, "Aliases").Select(v => v.Split(':')).ToDictionary(v => v[0], v => v[1]),
+ Aliases = propertiesAliases,
IsGeneric = (a.NamedArguments.FirstOrDefault(a => a.Key == "IsGeneric").Value.Value as bool?) ?? false
};
})