Skip to content

Commit a5a514a

Browse files
committed
2.0.0.7
1 parent e19a0f9 commit a5a514a

6 files changed

Lines changed: 44 additions & 29 deletions
-89.9 KB
Binary file not shown.
90 KB
Binary file not shown.

Blazor.WebForm.Components/Base/ControlComponentBase.cs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Collections.Generic;
44
using System.Linq;
55
using System.Linq.Expressions;
6-
using System.Reflection;
76
using System.Text;
87
using System.Threading.Tasks;
98
using System.Web.UI;
@@ -336,32 +335,6 @@ public override Task SetParametersAsync(ParameterView parameters)
336335
return base.SetParametersAsync(parameters);
337336
}
338337

339-
private TControl CaptureReferenceControl(Expression<Func<TControl>> func)
340-
{
341-
if (func.Body is MemberExpression expression)
342-
{
343-
if (expression.Member is FieldInfo field)
344-
{
345-
if (!field.IsStatic
346-
&& expression.Expression is ConstantExpression constant
347-
&& field.GetValue(constant.Value) == null)
348-
{
349-
field.SetValue(constant.Value, this.Control);
350-
}
351-
}
352-
else if (expression.Member is PropertyInfo property)
353-
{
354-
if (property.CanRead && property.CanWrite
355-
&& expression.Expression is ConstantExpression constant
356-
&& property.GetValue(constant.Value) == null)
357-
{
358-
property.SetValue(constant.Value, this.Control);
359-
}
360-
}
361-
}
362-
return func.Compile().Invoke();
363-
}
364-
365338
protected override void OnAfterRender(bool firstRender)
366339
{
367340
_parameters = null;
@@ -453,6 +426,7 @@ protected virtual void Dispose(bool disposing)
453426
{
454427
if (!_disposed)
455428
{
429+
(this.Control as IHandleUnload).Unload();
456430
_disposed = true;
457431
}
458432
}

Blazor.WebForm.Components/Base/ControlParameterViewComponentExtensions.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using System.ComponentModel;
66
using System.Globalization;
77
using System.Linq;
8+
using System.Linq.Expressions;
9+
using System.Reflection;
810
using System.Runtime.CompilerServices;
911
using System.Text;
1012
using System.Threading.Tasks;
@@ -60,6 +62,33 @@ private static List<string> InitReserveParameters(this IControlParameterViewComp
6062
return reserveParameters;
6163
}
6264

65+
internal static TControl CaptureReferenceControl<TControl>(this IControlParameterViewComponent component, Expression<Func<TControl>> func)
66+
where TControl : Control
67+
{
68+
if (func.Body is MemberExpression expression)
69+
{
70+
if (expression.Member is FieldInfo field)
71+
{
72+
if (!field.IsStatic
73+
&& expression.Expression is ConstantExpression constant
74+
&& field.GetValue(constant.Value) == null)
75+
{
76+
field.SetValue(constant.Value, component.Control);
77+
}
78+
}
79+
else if (expression.Member is PropertyInfo property)
80+
{
81+
if (property.CanRead && property.CanWrite
82+
&& expression.Expression is ConstantExpression constant
83+
&& property.GetValue(constant.Value) == null)
84+
{
85+
property.SetValue(constant.Value, component.Control);
86+
}
87+
}
88+
}
89+
return func.Compile().Invoke();
90+
}
91+
6392
private static bool HasPropertyBindEvent(IReadOnlyDictionary<string, object> attributes, string propertyName)
6493
{
6594
if (attributes != null && attributes.ContainsKey($"{propertyName}Changed"))

Blazor.WebForm.Components/Blazor.WebForm.Components.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>net6.0</TargetFramework>
55
<SignAssembly>true</SignAssembly>
66
<AssemblyOriginatorKeyFile>Blazor.WebForm.Components.pfx</AssemblyOriginatorKeyFile>
7-
<Version>2.0.0.6</Version>
7+
<Version>2.0.0.7</Version>
88
<RootNamespace>asp</RootNamespace>
99
<Copyright>Jurio li</Copyright>
1010
<AssemblyName>Blazor.WebForm.Components</AssemblyName>
@@ -17,7 +17,7 @@
1717

1818
<ItemGroup>
1919
<PackageReference Include="Applied" Version="1.2.1.6" />
20-
<PackageReference Include="Blazor.WebForm.UI" Version="2.0.0.6" />
20+
<PackageReference Include="Blazor.WebForm.UI" Version="2.0.0.7" />
2121
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="6.0.1" />
2222
</ItemGroup>
2323

Blazor.WebForm.Components/Inner/Base/ControlPropertyComponent.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Linq;
5+
using System.Linq.Expressions;
56
using System.Text;
67
using System.Threading.Tasks;
78

@@ -43,6 +44,9 @@ protected TControl Control
4344
// }
4445
//}
4546

47+
[Parameter]
48+
public Expression<Func<TControl>> _ref { get; set; }
49+
4650
[Parameter]
4751
public string ID
4852
{
@@ -199,6 +203,14 @@ public override Task SetParametersAsync(ParameterView parameters)
199203
{
200204
if (_firstSet)
201205
{
206+
if (parameters.TryGetValue(nameof(this._ref), out Expression<Func<TControl>> func) && func != null)
207+
{
208+
TControl control = this.CaptureReferenceControl(func);
209+
if (control != null)
210+
{
211+
this._control = control;
212+
}
213+
}
202214
_firstSet = false;
203215
}
204216
else

0 commit comments

Comments
 (0)