Skip to content

Commit 1be7713

Browse files
committed
Solution structure updates - draft
1 parent 00e03aa commit 1be7713

102 files changed

Lines changed: 498 additions & 88 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

BlazorExpress.ChartJS.Demo.RCL/Components/Shared/Extensions/TypeExtensions.cs

Lines changed: 0 additions & 86 deletions
This file was deleted.

BlazorExpress.ChartJS.Demo.RCL/Components/Shared/Enums/DocType.cs renamed to BlazorExpress.ChartJS.Demo.RCL/Enums/DocType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
public enum DocType
44
{
5+
None,
56
Enum,
67
Events,
78
Methods,

BlazorExpress.ChartJS.Demo.RCL/Components/Shared/Enums/LanguageCode.cs renamed to BlazorExpress.ChartJS.Demo.RCL/Enums/LanguageCode.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,3 @@ public enum LanguageCode
6565
/// </summary>
6666
YAML
6767
}
68-
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.ComponentModel;
2+
3+
namespace BlazorExpress.ChartJS.Demo.RCL;
4+
5+
public enum PageLinkCategory
6+
{
7+
[Description("All")]
8+
All,
9+
10+
[Description("Getting Started")]
11+
GettingStarted,
12+
13+
[Description("Features")]
14+
Features,
15+
16+
[Description("Icons")]
17+
Icons,
18+
19+
[Description("Elements")]
20+
Elements,
21+
22+
[Description("Form")]
23+
Form,
24+
25+
[Description("Components")]
26+
Components,
27+
28+
[Description("Layout")]
29+
Layout
30+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace BlazorExpress.ChartJS.Demo.RCL;
2+
3+
public enum PageLinkStatus
4+
{
5+
None,
6+
New,
7+
Updated
8+
}

BlazorExpress.ChartJS.Demo.RCL/Components/Shared/Extensions/EnumExtensions.cs renamed to BlazorExpress.ChartJS.Demo.RCL/Extensions/EnumExtensions.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
namespace BlazorExpress.ChartJS.Demo.RCL;
22

3+
/// <summary>
4+
/// Extension methods for <see cref="Enum" />.
5+
/// </summary>
36
public static class EnumExtensions
47
{
58
public static string? ToLanguageCssClass(this LanguageCode languageCode) =>
@@ -17,4 +20,20 @@ public static class EnumExtensions
1720
LanguageCode.YAML => "language-yaml",
1821
_ => null
1922
};
23+
24+
public static string? ToLanguageName(this LanguageCode languageCode) =>
25+
languageCode switch
26+
{
27+
LanguageCode.AspNet => "ASP.NET",
28+
LanguageCode.CSharp => "C#",
29+
LanguageCode.JavaScript => "JS",
30+
LanguageCode.JSON => "Json",
31+
LanguageCode.JSONP => "Jsonp",
32+
LanguageCode.Markdown => "Markdown",
33+
LanguageCode.PowerShell => "PowerShell",
34+
LanguageCode.Razor => "Razor",
35+
LanguageCode.Text => "Text",
36+
LanguageCode.YAML => "Yaml",
37+
_ => null
38+
};
2039
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System.ComponentModel;
2+
using System.Reflection;
3+
4+
namespace BlazorExpress.ChartJS.Demo.RCL;
5+
6+
/// <summary>
7+
/// Extension methods for <see cref="MethodInfo" />.
8+
/// </summary>
9+
public static class MethodInfoExtensions
10+
{
11+
/// <summary>
12+
/// Get added version of a method.
13+
/// </summary>
14+
/// <param name="type"></param>
15+
/// <param name="methodName"></param>
16+
/// <returns>string</returns>
17+
public static string GetMethodAddedVersion(this MethodInfo methodInfo)
18+
{
19+
var addedVersionAttribute = methodInfo.GetCustomAttributes(typeof(AddedVersionAttribute), false).FirstOrDefault() as AddedVersionAttribute;
20+
return addedVersionAttribute?.Version ?? string.Empty;
21+
}
22+
23+
/// <summary>
24+
/// Get method description.
25+
/// </summary>
26+
/// <param name="type"></param>
27+
/// <param name="methodName"></param>
28+
/// <returns>string</returns>
29+
public static string GetMethodDescription(this MethodInfo methodInfo)
30+
{
31+
var descriptionAttribute = methodInfo.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault() as DescriptionAttribute;
32+
return descriptionAttribute?.Description ?? string.Empty;
33+
}
34+
35+
public static string GetMethodParameters(this MethodInfo methodInfo)
36+
{
37+
var parameters = methodInfo.GetParameters();
38+
if (parameters.Length == 0)
39+
return string.Empty;
40+
41+
var parametersWithType = new HashSet<string>();
42+
foreach (var parameter in parameters)
43+
parametersWithType.Add($"{parameter.ParameterType.GetCSharpTypeName()} {parameter.Name}");
44+
45+
return string.Join(",", parametersWithType);
46+
}
47+
48+
/// <summary>
49+
/// Get method return type.
50+
/// </summary>
51+
/// <param name="type"></param>
52+
/// <param name="methodName"></param>
53+
/// <returns>string</returns>
54+
public static string GetMethodReturnType(this MethodInfo methodInfo)
55+
=> methodInfo.ReturnType.GetCSharpTypeName();
56+
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
using System.ComponentModel;
2+
using System.Reflection;
3+
4+
namespace BlazorExpress.ChartJS.Demo.RCL;
5+
6+
/// <summary>
7+
/// Extension methods for <see cref="PropertyInfo" />.
8+
/// </summary>
9+
public static class PropertyInfoExtenstions
10+
{
11+
/// <summary>
12+
/// Get event callback return type.
13+
/// </summary>
14+
/// <param name="propertyInfo"></param>
15+
/// <returns>Returns list of component event callbacks.</returns>
16+
public static string GetEventCallbackReturnType(this PropertyInfo propertyInfo)
17+
{
18+
HashSet<string> arguments = new();
19+
if (propertyInfo.PropertyType.IsGenericType)
20+
{
21+
Type[] genericArguments = propertyInfo.PropertyType.GetGenericArguments();
22+
if (genericArguments.Length > 0)
23+
{
24+
foreach (Type genericArgument in genericArguments)
25+
arguments.Add(genericArgument.GetCSharpTypeName());
26+
}
27+
}
28+
29+
return arguments.Count > 0 ? $"EventCallback<{string.Join(",", arguments)}>" : "EventCallback";
30+
}
31+
32+
/// <summary>
33+
/// Get parameter type name.
34+
/// </summary>
35+
/// <param name="propertyInfo"></param>
36+
/// <returns>string</returns>
37+
public static string GetParameterTypeName(this PropertyInfo propertyInfo)
38+
{
39+
var parameterTypeNameAttribute = propertyInfo.GetCustomAttributes(typeof(ParameterTypeNameAttribute), false).FirstOrDefault() as ParameterTypeNameAttribute;
40+
return parameterTypeNameAttribute?.TypeName ?? null!;
41+
}
42+
43+
/// <summary>
44+
/// Get added version of a property.
45+
/// </summary>
46+
/// <param name="propertyInfo"></param>
47+
/// <returns>string</returns>
48+
public static string GetPropertyAddedVersion(this PropertyInfo propertyInfo)
49+
{
50+
var addedVersionAttribute = propertyInfo.GetCustomAttributes(typeof(AddedVersionAttribute), false).FirstOrDefault() as AddedVersionAttribute;
51+
return addedVersionAttribute?.Version!;
52+
}
53+
54+
/// <summary>
55+
/// Get default value of a property.
56+
/// </summary>
57+
/// <param name="propertyInfo"></param>
58+
/// <returns>string</returns>
59+
public static string GetPropertyDefaultValue(this PropertyInfo propertyInfo)
60+
{
61+
var defaultValueAttribute = propertyInfo.GetCustomAttributes(typeof(DefaultValueAttribute), false).FirstOrDefault() as DefaultValueAttribute;
62+
return defaultValueAttribute?.Value?.ToString() ?? "null";
63+
}
64+
65+
/// <summary>
66+
/// Get property description.
67+
/// </summary>
68+
/// <param name="propertyInfo"></param>
69+
/// <returns>string</returns>
70+
public static string GetPropertyDescription(this PropertyInfo propertyInfo)
71+
{
72+
var descriptionAttribute = propertyInfo.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault() as DescriptionAttribute;
73+
return descriptionAttribute?.Description ?? string.Empty;
74+
}
75+
76+
/// <summary>
77+
/// Get property type name.
78+
/// </summary>
79+
/// <param name="propertyInfo"></param>
80+
/// <returns>string</returns>
81+
public static string GetPropertyTypeName(this PropertyInfo propertyInfo)
82+
{
83+
var propertyTypeName = propertyInfo.Name;
84+
if (string.IsNullOrWhiteSpace(propertyTypeName))
85+
return string.Empty;
86+
87+
if (propertyTypeName.Contains(StringConstants.PropertyTypeNameInt16, StringComparison.InvariantCulture))
88+
propertyTypeName = StringConstants.PropertyTypeNameInt16CSharpTypeKeyword;
89+
90+
else if (propertyTypeName.Contains(StringConstants.PropertyTypeNameInt32, StringComparison.InvariantCulture))
91+
propertyTypeName = StringConstants.PropertyTypeNameInt32CSharpTypeKeyword;
92+
93+
else if (propertyTypeName.Contains(StringConstants.PropertyTypeNameInt64, StringComparison.InvariantCulture))
94+
propertyTypeName = StringConstants.PropertyTypeNameInt64CSharpTypeKeyword;
95+
96+
else if (propertyTypeName.Contains(StringConstants.PropertyTypeNameChar, StringComparison.InvariantCulture))
97+
propertyTypeName = StringConstants.PropertyTypeNameCharCSharpTypeKeyword;
98+
99+
else if (propertyTypeName.Contains(StringConstants.PropertyTypeNameStringComparison, StringComparison.InvariantCulture))
100+
propertyTypeName = StringConstants.PropertyTypeNameStringComparisonCSharpTypeKeyword;
101+
102+
else if (propertyTypeName.Contains(StringConstants.PropertyTypeNameString, StringComparison.InvariantCulture))
103+
propertyTypeName = StringConstants.PropertyTypeNameStringCSharpTypeKeyword;
104+
105+
else if (propertyTypeName.Contains(StringConstants.PropertyTypeNameSingle, StringComparison.InvariantCulture)) // float
106+
propertyTypeName = StringConstants.PropertyTypeNameSingleCSharpTypeKeyword;
107+
108+
else if (propertyTypeName.Contains(StringConstants.PropertyTypeNameDecimal, StringComparison.InvariantCulture))
109+
propertyTypeName = StringConstants.PropertyTypeNameDecimalCSharpTypeKeyword;
110+
111+
else if (propertyTypeName.Contains(StringConstants.PropertyTypeNameDouble, StringComparison.InvariantCulture))
112+
propertyTypeName = StringConstants.PropertyTypeNameDoubleCSharpTypeKeyword;
113+
114+
else if (propertyTypeName.Contains(StringConstants.PropertyTypeNameDateOnly, StringComparison.InvariantCulture))
115+
propertyTypeName = StringConstants.PropertyTypeNameDateOnlyCSharpTypeKeyword;
116+
117+
else if (propertyTypeName.Contains(StringConstants.PropertyTypeNameDateTime, StringComparison.InvariantCulture))
118+
propertyTypeName = StringConstants.PropertyTypeNameDateTimeCSharpTypeKeyword;
119+
120+
else if (propertyTypeName.Contains(StringConstants.PropertyTypeNameBoolean, StringComparison.InvariantCulture))
121+
propertyTypeName = StringConstants.PropertyTypeNameBooleanCSharpTypeKeyword;
122+
123+
//else if (propertyType!.IsEnum)
124+
// propertyTypeName = StringConstants.PropertyTypeNameEnumCSharpTypeKeyword;
125+
126+
else if (propertyTypeName.Contains(StringConstants.PropertyTypeNameGuid, StringComparison.InvariantCulture))
127+
propertyTypeName = StringConstants.PropertyTypeNameGuidCSharpTypeKeyword;
128+
129+
return propertyTypeName;
130+
}
131+
132+
/// <summary>
133+
/// Determines whether the specified property is an EventCallback or EventCallback&lt;T&gt;.
134+
/// </summary>
135+
/// <param name="propertyInfo"></param>
136+
/// <returns>bool</returns>
137+
/// <exception cref="ArgumentNullException"></exception>
138+
public static bool IsEventCallbackProperty(this PropertyInfo propertyInfo)
139+
{
140+
if (propertyInfo == null)
141+
{
142+
throw new ArgumentNullException(nameof(propertyInfo));
143+
}
144+
145+
// Check for EventCallback
146+
if (propertyInfo.PropertyType == typeof(EventCallback))
147+
{
148+
return true;
149+
}
150+
151+
// Check for EventCallback<T>
152+
if (propertyInfo.PropertyType.IsGenericType &&
153+
propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(EventCallback<>))
154+
{
155+
return true;
156+
}
157+
158+
return false;
159+
}
160+
161+
/// <summary>
162+
/// Returns true if the property is required. Otherwise, false.
163+
/// </summary>
164+
/// <param name="propertyInfo"></param>
165+
/// <returns>bool</returns>
166+
public static bool IsPropertyRequired(this PropertyInfo propertyInfo)
167+
{
168+
var editorRequiredAttribute = propertyInfo.GetCustomAttributes(typeof(EditorRequiredAttribute), false).FirstOrDefault() as EditorRequiredAttribute;
169+
return editorRequiredAttribute is not null;
170+
}
171+
}

0 commit comments

Comments
 (0)