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
e6f8f8b9
Commit
e6f8f8b9
authored
May 16, 2019
by
阿星Plus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Entities
parent
c9b20d97
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
1 deletion
+76
-1
Entity.cs
src/Plus/Domain/Entities/Entity.cs
+74
-0
IEntity.cs
src/Plus/Domain/Entities/IEntity.cs
+2
-1
No files found.
src/Plus/Domain/Entities/Entity.cs
0 → 100644
View file @
e6f8f8b9
using
System
;
using
System.Collections.Generic
;
namespace
Plus.Domain.Entities
{
[
Serializable
]
public
abstract
class
Entity
:
Entity
<
int
>,
IEntity
{
}
[
Serializable
]
public
abstract
class
Entity
<
TPrimaryKey
>
:
IEntity
<
TPrimaryKey
>
{
public
virtual
TPrimaryKey
Id
{
get
;
set
;
}
public
virtual
bool
IsTransient
()
{
return
EqualityComparer
<
TPrimaryKey
>.
Default
.
Equals
(
Id
,
default
);
}
public
override
bool
Equals
(
object
obj
)
{
if
(
obj
==
null
||
!(
obj
is
Entity
<
TPrimaryKey
>))
{
return
false
;
}
if
(
ReferenceEquals
(
this
,
obj
))
{
return
true
;
}
Entity
<
TPrimaryKey
>
entity
=
(
Entity
<
TPrimaryKey
>)
obj
;
if
(
IsTransient
()
&&
entity
.
IsTransient
())
{
return
false
;
}
Type
type
=
GetType
();
Type
type2
=
entity
.
GetType
();
if
(!
type
.
IsAssignableFrom
(
type2
)
&&
!
type2
.
IsAssignableFrom
(
type
))
{
return
false
;
}
return
Id
.
Equals
(
entity
.
Id
);
}
public
override
int
GetHashCode
()
{
return
Id
.
GetHashCode
();
}
public
static
bool
operator
==(
Entity
<
TPrimaryKey
>
left
,
Entity
<
TPrimaryKey
>
right
)
{
if
(
Equals
(
left
,
null
))
{
return
Equals
(
right
,
null
);
}
return
left
.
Equals
(
right
);
}
public
static
bool
operator
!=(
Entity
<
TPrimaryKey
>
left
,
Entity
<
TPrimaryKey
>
right
)
{
return
!(
left
==
right
);
}
public
override
string
ToString
()
{
return
$"[
{
GetType
().
Name
}
{
Id
}
]"
;
}
}
}
\ No newline at end of file
src/Plus/Domain/Entities/IEntity.cs
View file @
e6f8f8b9
namespace
Plus.Domain.Entities
{
public
interface
IEntity
public
interface
IEntity
:
IEntity
<
int
>
{
}
}
\ No newline at end of file
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