Skip to content

Commit

Permalink
2.0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Jurioli committed Jan 25, 2022
1 parent e19a0f9 commit a5a514a
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 29 deletions.
Binary file removed Blazor.WebForm.Components.2.0.0.6.nupkg
Binary file not shown.
Binary file added Blazor.WebForm.Components.2.0.0.7.nupkg
Binary file not shown.
28 changes: 1 addition & 27 deletions Blazor.WebForm.Components/Base/ControlComponentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI;
Expand Down Expand Up @@ -336,32 +335,6 @@ public override Task SetParametersAsync(ParameterView parameters)
return base.SetParametersAsync(parameters);
}

private TControl CaptureReferenceControl(Expression<Func<TControl>> func)
{
if (func.Body is MemberExpression expression)
{
if (expression.Member is FieldInfo field)
{
if (!field.IsStatic
&& expression.Expression is ConstantExpression constant
&& field.GetValue(constant.Value) == null)
{
field.SetValue(constant.Value, this.Control);
}
}
else if (expression.Member is PropertyInfo property)
{
if (property.CanRead && property.CanWrite
&& expression.Expression is ConstantExpression constant
&& property.GetValue(constant.Value) == null)
{
property.SetValue(constant.Value, this.Control);
}
}
}
return func.Compile().Invoke();
}

protected override void OnAfterRender(bool firstRender)
{
_parameters = null;
Expand Down Expand Up @@ -453,6 +426,7 @@ protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
(this.Control as IHandleUnload).Unload();
_disposed = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -60,6 +62,33 @@ private static List<string> InitReserveParameters(this IControlParameterViewComp
return reserveParameters;
}

internal static TControl CaptureReferenceControl<TControl>(this IControlParameterViewComponent component, Expression<Func<TControl>> func)
where TControl : Control
{
if (func.Body is MemberExpression expression)
{
if (expression.Member is FieldInfo field)
{
if (!field.IsStatic
&& expression.Expression is ConstantExpression constant
&& field.GetValue(constant.Value) == null)
{
field.SetValue(constant.Value, component.Control);
}
}
else if (expression.Member is PropertyInfo property)
{
if (property.CanRead && property.CanWrite
&& expression.Expression is ConstantExpression constant
&& property.GetValue(constant.Value) == null)
{
property.SetValue(constant.Value, component.Control);
}
}
}
return func.Compile().Invoke();
}

private static bool HasPropertyBindEvent(IReadOnlyDictionary<string, object> attributes, string propertyName)
{
if (attributes != null && attributes.ContainsKey($"{propertyName}Changed"))
Expand Down
4 changes: 2 additions & 2 deletions Blazor.WebForm.Components/Blazor.WebForm.Components.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>Blazor.WebForm.Components.pfx</AssemblyOriginatorKeyFile>
<Version>2.0.0.6</Version>
<Version>2.0.0.7</Version>
<RootNamespace>asp</RootNamespace>
<Copyright>Jurio li</Copyright>
<AssemblyName>Blazor.WebForm.Components</AssemblyName>
Expand All @@ -17,7 +17,7 @@

<ItemGroup>
<PackageReference Include="Applied" Version="1.2.1.6" />
<PackageReference Include="Blazor.WebForm.UI" Version="2.0.0.6" />
<PackageReference Include="Blazor.WebForm.UI" Version="2.0.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="6.0.1" />
</ItemGroup>

Expand Down
12 changes: 12 additions & 0 deletions Blazor.WebForm.Components/Inner/Base/ControlPropertyComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

Expand Down Expand Up @@ -43,6 +44,9 @@ protected TControl Control
// }
//}

[Parameter]
public Expression<Func<TControl>> _ref { get; set; }

[Parameter]
public string ID
{
Expand Down Expand Up @@ -199,6 +203,14 @@ public override Task SetParametersAsync(ParameterView parameters)
{
if (_firstSet)
{
if (parameters.TryGetValue(nameof(this._ref), out Expression<Func<TControl>> func) && func != null)
{
TControl control = this.CaptureReferenceControl(func);
if (control != null)
{
this._control = control;
}
}
_firstSet = false;
}
else
Expand Down

0 comments on commit a5a514a

Please sign in to comment.