Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
H
HIAST-Clinics
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
almohanad.hafez
HIAST-Clinics
Commits
b6617453
Commit
b6617453
authored
Aug 14, 2024
by
Almouhannad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(B) Add entity base class
parent
c417bc62
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
0 deletions
+73
-0
Entity.cs
Clinics.Backend/Domain/Primitives/Entity.cs
+73
-0
No files found.
Clinics.Backend/Domain/Primitives/Entity.cs
0 → 100644
View file @
b6617453
namespace
Domain.Primitives
;
// To use nullable reference types within the file
#
nullable
enable
public
class
Entity
{
protected
Entity
(
int
id
)
{
Id
=
id
;
}
#
region
Properties
// Init is to ensure that Id is unchangable
public
int
Id
{
get
;
private
init
;
}
#
endregion
#
region
Equality
by
matching
Id
public
override
bool
Equals
(
object
?
obj
)
{
if
(
InvalidType
(
obj
))
{
return
false
;
}
if
(
obj
is
not
Entity
entity
)
{
return
false
;
}
return
entity
.
Id
==
Id
;
}
public
bool
Equals
(
Entity
other
)
{
if
(
InvalidType
(
other
))
{
return
false
;
}
return
other
.
Id
==
Id
;
}
public
static
bool
operator
==(
Entity
?
first
,
Entity
?
second
)
{
return
(
first
is
not
null
)
&&
(
second
is
not
null
)
&&
first
.
Equals
(
second
);
}
public
static
bool
operator
!=(
Entity
?
first
,
Entity
?
second
)
{
return
!(
first
==
second
);
}
private
bool
InvalidType
(
object
?
obj
)
{
return
(
obj
is
null
)
||
(
obj
.
GetType
()
!=
this
.
GetType
());
}
#
endregion
#
region
Custom
hash
code
for
collections
// For dealing with collections
public
override
int
GetHashCode
()
{
// It's a best practice to mult by prime number when defining custom hash code
return
Id
.
GetHashCode
()
*
41
;
}
#
endregion
}
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