Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
netcoreplus
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
netcoreplus
Commits
066fa075
Commit
066fa075
authored
May 15, 2019
by
阿星Plus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
😀
提取扩展方法到 Plus.Extensions .移除多余 using
parent
e1abb5b0
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
3709 additions
and
213 deletions
+3709
-213
Extensions.cs
src/Plus.Extensions/Extensions.cs
+3697
-0
PlusCrossCuttingConcerns.cs
src/Plus/Aspects/PlusCrossCuttingConcerns.cs
+1
-2
Extensions.cs
src/Plus/Collections/Extensions.cs
+0
-193
DictionaryBasedConfig.cs
src/Plus/Configuration/DictionaryBasedConfig.cs
+1
-2
EventBus.cs
src/Plus/Event/Bus/EventBus.cs
+0
-1
PlusModule.cs
src/Plus/Modules/PlusModule.cs
+0
-1
PlusModuleCollection.cs
src/Plus/Modules/PlusModuleCollection.cs
+1
-2
Plus.csproj
src/Plus/Plus.csproj
+4
-0
PlusLeadershipModule.cs
src/Plus/PlusLeadershipModule.cs
+0
-2
MethodInvocationValidator.cs
...time/Validation/Interception/MethodInvocationValidator.cs
+5
-10
No files found.
src/Plus.Extensions/Extensions.cs
0 → 100644
View file @
066fa075
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/Plus/Aspects/PlusCrossCuttingConcerns.cs
View file @
066fa075
using
Plus.Collections
;
using
Plus.Service
;
using
Plus.Service
;
using
System
;
using
System
;
namespace
Plus.Aspects
namespace
Plus.Aspects
...
...
src/Plus/Collections/Extensions.cs
deleted
100644 → 0
View file @
e1abb5b0
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Reflection
;
using
System.Runtime.ExceptionServices
;
using
System.Threading.Tasks
;
namespace
Plus.Collections
{
/// <summary>
/// 扩展方法,后面要拿出来单独放一个项目中
/// </summary>
public
static
class
Extensions
{
public
static
bool
IsAsync
(
this
MethodInfo
method
)
{
return
method
.
ReturnType
==
typeof
(
Task
)
||
(
method
.
ReturnType
.
GetTypeInfo
().
IsGenericType
&&
method
.
ReturnType
.
GetGenericTypeDefinition
()
==
typeof
(
Task
<>));
}
public
static
List
<
T
>
SortByDependencies
<
T
>(
this
IEnumerable
<
T
>
source
,
Func
<
T
,
IEnumerable
<
T
>>
getDependencies
)
{
var
sorted
=
new
List
<
T
>();
var
visited
=
new
Dictionary
<
T
,
bool
>();
foreach
(
var
item
in
source
)
{
SortByDependenciesVisit
(
item
,
getDependencies
,
sorted
,
visited
);
}
return
sorted
;
}
private
static
void
SortByDependenciesVisit
<
T
>(
T
item
,
Func
<
T
,
IEnumerable
<
T
>>
getDependencies
,
List
<
T
>
sorted
,
Dictionary
<
T
,
bool
>
visited
)
{
var
alreadyVisited
=
visited
.
TryGetValue
(
item
,
out
bool
inProcess
);
if
(
alreadyVisited
)
{
if
(
inProcess
)
{
throw
new
ArgumentException
(
"Cyclic dependency found! Item: "
+
item
);
}
}
else
{
visited
[
item
]
=
true
;
var
dependencies
=
getDependencies
(
item
);
if
(
dependencies
!=
null
)
{
foreach
(
var
dependency
in
dependencies
)
{
SortByDependenciesVisit
(
dependency
,
getDependencies
,
sorted
,
visited
);
}
}
visited
[
item
]
=
false
;
sorted
.
Add
(
item
);
}
}
public
static
bool
IsNullOrEmpty
<
T
>(
this
ICollection
<
T
>
source
)
{
return
source
==
null
||
source
.
Count
<=
0
;
}
public
static
bool
AddIfNotContains
<
T
>(
this
ICollection
<
T
>
source
,
T
item
)
{
if
(
source
==
null
)
{
throw
new
ArgumentNullException
(
"source"
);
}
if
(
source
.
Contains
(
item
))
{
return
false
;
}
source
.
Add
(
item
);
return
true
;
}
/// <summary>
/// This method is used to try to get a value in a dictionary if it does exists.
/// </summary>
/// <typeparam name="T">Type of the value</typeparam>
/// <param name="dictionary">The collection object</param>
/// <param name="key">Key</param>
/// <param name="value">Value of the key (or default value if key not exists)</param>
/// <returns>True if key does exists in the dictionary</returns>
internal
static
bool
TryGetValue
<
T
>(
this
IDictionary
<
string
,
object
>
dictionary
,
string
key
,
out
T
value
)
{
object
valueObj
;
if
(
dictionary
.
TryGetValue
(
key
,
out
valueObj
)
&&
valueObj
is
T
)
{
value
=
(
T
)
valueObj
;
return
true
;
}
value
=
default
(
T
);
return
false
;
}
/// <summary>
/// Gets a value from the dictionary with given key. Returns default value if can not find.
/// </summary>
/// <param name="dictionary">Dictionary to check and get</param>
/// <param name="key">Key to find the value</param>
/// <typeparam name="TKey">Type of the key</typeparam>
/// <typeparam name="TValue">Type of the value</typeparam>
/// <returns>Value if found, default if can not found.</returns>
public
static
TValue
GetOrDefault
<
TKey
,
TValue
>(
this
IDictionary
<
TKey
,
TValue
>
dictionary
,
TKey
key
)
{
TValue
obj
;
return
dictionary
.
TryGetValue
(
key
,
out
obj
)
?
obj
:
default
(
TValue
);
}
/// <summary>
/// Gets a value from the dictionary with given key. Returns default value if can not find.
/// </summary>
/// <param name="dictionary">Dictionary to check and get</param>
/// <param name="key">Key to find the value</param>
/// <param name="factory">A factory method used to create the value if not found in the dictionary</param>
/// <typeparam name="TKey">Type of the key</typeparam>
/// <typeparam name="TValue">Type of the value</typeparam>
/// <returns>Value if found, default if can not found.</returns>
public
static
TValue
GetOrAdd
<
TKey
,
TValue
>(
this
IDictionary
<
TKey
,
TValue
>
dictionary
,
TKey
key
,
Func
<
TKey
,
TValue
>
factory
)
{
TValue
obj
;
if
(
dictionary
.
TryGetValue
(
key
,
out
obj
))
{
return
obj
;
}
return
dictionary
[
key
]
=
factory
(
key
);
}
/// <summary>
/// Gets a value from the dictionary with given key. Returns default value if can not find.
/// </summary>
/// <param name="dictionary">Dictionary to check and get</param>
/// <param name="key">Key to find the value</param>
/// <param name="factory">A factory method used to create the value if not found in the dictionary</param>
/// <typeparam name="TKey">Type of the key</typeparam>
/// <typeparam name="TValue">Type of the value</typeparam>
/// <returns>Value if found, default if can not found.</returns>
public
static
TValue
GetOrAdd
<
TKey
,
TValue
>(
this
IDictionary
<
TKey
,
TValue
>
dictionary
,
TKey
key
,
Func
<
TValue
>
factory
)
{
return
dictionary
.
GetOrAdd
(
key
,
k
=>
factory
());
}
public
static
Assembly
GetAssembly
(
this
Type
type
)
{
return
type
.
GetTypeInfo
().
Assembly
;
}
public
static
MethodInfo
GetMethod
(
this
Type
type
,
string
methodName
,
int
pParametersCount
=
0
,
int
pGenericArgumentsCount
=
0
)
{
return
type
.
GetMethods
()
.
Where
(
m
=>
m
.
Name
==
methodName
).
ToList
()
.
Select
(
m
=>
new
{
Method
=
m
,
Params
=
m
.
GetParameters
(),
Args
=
m
.
GetGenericArguments
()
})
.
Where
(
x
=>
x
.
Params
.
Length
==
pParametersCount
&&
x
.
Args
.
Length
==
pGenericArgumentsCount
).
Select
(
x
=>
x
.
Method
)
.
First
();
}
/// <summary>
/// Executes given <paramref name="action"/> by locking given <paramref name="source"/> object.
/// </summary>
/// <typeparam name="T">Type of the object (to be locked)</typeparam>
/// <param name="source">Source object (to be locked)</param>
/// <param name="action">Action (to be executed)</param>
public
static
void
Locking
<
T
>(
this
T
source
,
Action
<
T
>
action
)
where
T
:
class
{
lock
(
source
)
{
action
(
source
);
}
}
public
static
void
ReThrow
(
this
Exception
exception
)
{
ExceptionDispatchInfo
.
Capture
(
exception
).
Throw
();
}
}
}
\ No newline at end of file
src/Plus/Configuration/DictionaryBasedConfig.cs
View file @
066fa075
using
Plus.Collections
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
namespace
Plus.Configuration
namespace
Plus.Configuration
...
...
src/Plus/Event/Bus/EventBus.cs
View file @
066fa075
using
Castle.Core.Logging
;
using
Castle.Core.Logging
;
using
Plus.Collections
;
using
Plus.Event.Bus.Factories
;
using
Plus.Event.Bus.Factories
;
using
Plus.Event.Bus.Factories.Internals
;
using
Plus.Event.Bus.Factories.Internals
;
using
Plus.Event.Bus.Handlers
;
using
Plus.Event.Bus.Handlers
;
...
...
src/Plus/Modules/PlusModule.cs
View file @
066fa075
using
Castle.Core.Logging
;
using
Castle.Core.Logging
;
using
Plus.Collections
;
using
Plus.Configuration.Startup
;
using
Plus.Configuration.Startup
;
using
Plus.Dependency
;
using
Plus.Dependency
;
using
System
;
using
System
;
...
...
src/Plus/Modules/PlusModuleCollection.cs
View file @
066fa075
using
Plus.Collections
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Linq
;
...
...
src/Plus/Plus.csproj
View file @
066fa075
...
@@ -11,4 +11,8 @@
...
@@ -11,4 +11,8 @@
<PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.5.0" />
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Plus.Extensions\Plus.Extensions.csproj" />
</ItemGroup>
</Project>
</Project>
src/Plus/PlusLeadershipModule.cs
View file @
066fa075
using
Castle.MicroKernel.Registration
;
using
Castle.MicroKernel.Registration
;
using
Plus.Collections
;
using
Plus.Configuration.Startup
;
using
Plus.Configuration.Startup
;
using
Plus.Dependency
;
using
Plus.Dependency
;
using
Plus.Event.Bus
;
using
Plus.Event.Bus
;
using
Plus.Modules
;
using
Plus.Modules
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.IO
;
using
System.Linq.Expressions
;
using
System.Linq.Expressions
;
...
...
src/Plus/Runtime/Validation/Interception/MethodInvocationValidator.cs
View file @
066fa075
using
Plus.Dependency
;
using
Plus.Configuration.Startup
;
using
Plus.Dependency
;
using
Plus.Reflection
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
System.Collections
;
using
System.Collections
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.ComponentModel
;
using
System.ComponentModel.DataAnnotations
;
using
System.Linq
;
using
System.Linq
;
using
System.Reflection
;
using
System.Reflection
;
using
Plus
;
using
Plus.Configuration.Startup
;
using
Plus.Runtime.Validation
;
using
Plus.Runtime.Validation.Interception
;
using
System.ComponentModel.DataAnnotations
;
using
Plus.Collections
;
using
Plus.Reflection
;
namespace
Plus.Runtime.Validation.Interception
namespace
Plus.Runtime.Validation.Interception
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment