Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AigioL committed May 28, 2021
1 parent 5e613ec commit 39de79f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 35 deletions.
15 changes: 12 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ dotnet_style_parentheses_in_other_operators = never_if_unnecessary
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity

# 修饰符首选项
dotnet_style_require_accessibility_modifiers = for_non_interface_members
dotnet_style_require_accessibility_modifiers = never

# 表达式级首选项
dotnet_style_coalesce_expression = true
Expand Down Expand Up @@ -100,7 +100,7 @@ csharp_style_expression_bodied_constructors = false
csharp_style_expression_bodied_indexers = true
csharp_style_expression_bodied_lambdas = true
csharp_style_expression_bodied_local_functions = false
csharp_style_expression_bodied_methods = false
csharp_style_expression_bodied_methods = when_on_single_line
csharp_style_expression_bodied_operators = false
csharp_style_expression_bodied_properties = true

Expand All @@ -119,7 +119,7 @@ csharp_prefer_static_local_function = true
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async

# 代码块首选项
csharp_prefer_braces = true
csharp_prefer_braces = false
csharp_prefer_simple_using_statement = true

# 表达式级首选项
Expand Down Expand Up @@ -225,3 +225,12 @@ dotnet_naming_style.以_i_开始.required_prefix = I
dotnet_naming_style.以_i_开始.required_suffix =
dotnet_naming_style.以_i_开始.word_separator =
dotnet_naming_style.以_i_开始.capitalization = pascal_case

# IDE0010: 添加缺失的事例
dotnet_diagnostic.IDE0010.severity = none

# IDE0011: 添加大括号
dotnet_diagnostic.IDE0011.severity = none

# IDE0040: 添加可访问性修饰符
dotnet_diagnostic.IDE0040.severity = none
49 changes: 21 additions & 28 deletions src/Common.CoreLib/DI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public static partial class DI

internal static bool IsInit => value != null;

internal static IServiceProvider Value => value ?? throw new NullReferenceException("init must be called.");

/// <summary>
/// 初始化依赖注入服务组(通过配置服务项的方式)
/// </summary>
Expand Down Expand Up @@ -76,7 +74,7 @@ static DI()
{
IsRunningOnMono = Type.GetType("Mono.Runtime") != null;
var processArchitecture = RuntimeInformation.ProcessArchitecture;
IsX86OrX64 = processArchitecture == Architecture.X64 || processArchitecture == Architecture.X86;
IsX86OrX64 = processArchitecture is Architecture.X64 or Architecture.X86;
IsArm64 = processArchitecture == Architecture.Arm64;
static Platform RuntimeInformationOSPlatform()
{
Expand Down Expand Up @@ -108,7 +106,7 @@ static DeviceIdiom GetDeviceIdiom()

#if !NOT_DI

static Exception GetDIGetFailException(Exception e, Type serviceType) => new($"DI.Get fail, serviceType: {serviceType}", e);
static Exception GetDIGetFailException(Type serviceType) => new($"DI.Get* fail, serviceType: {serviceType}");

/// <summary>
/// 获取依赖注入服务
Expand All @@ -117,57 +115,52 @@ static DeviceIdiom GetDeviceIdiom()
/// <returns></returns>
public static T Get<T>() where T : notnull
{
try
{
return Value.GetRequiredService<T>();
}
catch (NullReferenceException e)
if (value == null)
{
throw GetDIGetFailException(e, typeof(T));
throw GetDIGetFailException(typeof(T));
}
return value.GetRequiredService<T>();
}

/// <inheritdoc cref="Get{T}"/>
public static T? Get_Nullable<T>() where T : notnull
{
try
if (value == null)
{
return Value.GetService<T>();
}
catch (NullReferenceException e)
{
throw GetDIGetFailException(e, typeof(T));
throw GetDIGetFailException(typeof(T));
}
return value.GetService<T>();
}

/// <inheritdoc cref="Get{T}"/>
public static object Get(Type serviceType)
{
try
if (value == null)
{
return Value.GetRequiredService(serviceType);
}
catch (NullReferenceException e)
{
throw GetDIGetFailException(e, serviceType);
throw GetDIGetFailException(serviceType);
}
return value.GetRequiredService(serviceType);
}

/// <inheritdoc cref="Get_Nullable{T}"/>
public static object? Get_Nullable(Type serviceType)
{
try
if (value == null)
{
return Value.GetService(serviceType);
throw GetDIGetFailException(serviceType);
}
catch (NullReferenceException e)
return value.GetService(serviceType);
}

public static IServiceScope CreateScope()
{
if (value == null)
{
throw GetDIGetFailException(e, serviceType);
throw new Exception("DI.CreateScope fail.");
}
return value.CreateScope();
}

public static IServiceScope CreateScope() => Value.CreateScope();

#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ public string BtnSendSmsCodeText
set => this.RaiseAndSetIfChanged(ref _BtnSendSmsCodeText, value);
}

public bool IsUnTimeLimit
{
get => TimeLimit != SMSInterval;
}
public bool IsUnTimeLimit => TimeLimit != SMSInterval;

public bool SendSmsCodeSuccess { get; set; }

Expand Down

0 comments on commit 39de79f

Please sign in to comment.