Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
senjyouhara committed Apr 27, 2023
1 parent 9de7775 commit ebb330a
Show file tree
Hide file tree
Showing 25 changed files with 561 additions and 273 deletions.
Binary file modified .vs/ProjectEvaluation/senjyouhara.main.metadata.v5.2
Binary file not shown.
Binary file modified .vs/ProjectEvaluation/senjyouhara.main.projects.v5.2
Binary file not shown.
Binary file modified .vs/Senjyouhara.Main/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .vs/Senjyouhara.Main/v17/.futdcache.v2
Binary file not shown.
46 changes: 24 additions & 22 deletions Senjyouhara.Common/Utils/DelegateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,15 @@
namespace Senjyouhara.Common.Utils
{

public interface IDelegateCommand
public interface IDelegateCommand: ICommand
{
event EventHandler CanExecuteChanged;

bool CanExecute();

void Execute();

}
public interface IDelegateCommand<T>
public interface IDelegateCommand<T> : ICommand
{
event EventHandler CanExecuteChanged;

bool CanExecute(T parameter);

void Execute(T parameter);

}

Expand Down Expand Up @@ -101,22 +94,33 @@ private static bool DefaultCanExecute() //DefaultCanExecute方法
{
return true;
}

public bool CanExecute(object parameter)
{
return this.canExecute != null && this.canExecute();

}

public void Execute(object parameter)
{
this.execute();
}
}

public class DelegateCommand<T> : IDelegateCommand<T>
{
private Action<object> execute; //定义成员
private Action<T> execute; //定义成员

private Func<T, bool> canExecute;//Predicate:述语//定义成员

private event EventHandler CanExecuteChangedInternal;//事件

public DelegateCommand(Action<object> execute) //定义Action,CanExecute
public DelegateCommand(Action<T> execute) //定义Action,CanExecute
: this(execute, DefaultCanExecute)
{
}

public DelegateCommand(Action<object> execute, Func<T, bool> canExecute)//定义
public DelegateCommand(Action<T> execute, Func<T, bool> canExecute)//定义
{
if (execute == null)
{
Expand Down Expand Up @@ -147,16 +151,6 @@ public event EventHandler CanExecuteChanged //CanExecuteChanged事件处
}
}

public bool CanExecute(T parameter) //CanExecute方法
{
return this.canExecute != null && this.canExecute(parameter);
}

public void Execute(T parameter) //Execute方法
{
this.execute(parameter);
}

public void OnCanExecuteChanged() //OnCanExecute方法
{
EventHandler handler = this.CanExecuteChangedInternal;
Expand All @@ -178,6 +172,14 @@ private static bool DefaultCanExecute(T parameter) //DefaultCanExecute方法
return true;
}

public bool CanExecute(object parameter)
{
return this.canExecute != null && this.canExecute((T) parameter);
}

public void Execute(object parameter)
{
this.execute((T)parameter);
}
}
}
5 changes: 4 additions & 1 deletion Senjyouhara.Common/Utils/PatternUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ namespace Senjyouhara.Common.Utils
{
public class PatternUtil
{

public static bool IsMatch(string pattern, string input)
{
return new Regex(pattern).IsMatch(input);
}
public static List<string> GetPatternResult(string pattern, string input)
{
var result = new Regex(pattern).Matches(input);
Expand Down
31 changes: 31 additions & 0 deletions Senjyouhara.Common/Utils/Util.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace Senjyouhara.Common.Utils
{
public class Util
{
public static T DeepCopyByReflect<T>(T obj)
{
//如果是字符串或值类型则直接返回
if (obj == null || (obj is string) || (obj.GetType().IsValueType)) return obj;

object objCopy = null;

MemoryStream stream = new MemoryStream();
BinaryFormatter binFormatter = new BinaryFormatter();
binFormatter.Serialize(stream, obj);
stream.Position = 0;
objCopy = (T)binFormatter.Deserialize(stream);
stream.Close();
return (T)objCopy;
}

}
}
1 change: 0 additions & 1 deletion Senjyouhara.Main/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ protected override async void OnStartup(object sender, StartupEventArgs e)
#else
await DisplayRootViewForAsync<StartLoadingViewModel>();
#endif

}

protected override object GetInstance(Type service, string key)
Expand Down
3 changes: 3 additions & 0 deletions Senjyouhara.Main/Senjyouhara.Main.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<ProjectReference Include="..\Senjyouhara.Common\Senjyouhara.Common.csproj" />
<ProjectReference Include="..\Senjyouhara.UI\Senjyouhara.UI.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.ComponentModel.DataAnnotations" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\loading.png">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
Expand Down
Loading

0 comments on commit ebb330a

Please sign in to comment.