DotNetDupe
4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Toggle main menu visibility
Loading...
Searching...
No Matches
IServiceProvider.h
Go to the documentation of this file.
1
5
6
#pragma once
7
8
#include "
Common.h
"
9
#include "
System/Object.h
"
10
#include "
System/SmartPointer.h
"
11
#include "
System/InvalidOperationException.h
"
12
#include <typeindex>
13
14
namespace
DotNetDupe
{
15
namespace
System
{
20
class
IServiceProvider
:
public
Object
{
21
public
:
23
virtual
~IServiceProvider
() =
default
;
24
28
virtual
SmartPointer<Object>
GetService
(
const
std::type_index& serviceType) = 0;
29
33
template
<
typename
T>
34
SmartPointer<T>
GetService
() {
35
SmartPointer<Object>
spObj =
GetService
(
typeid
(T));
36
if
(spObj.
IsNull
()) {
37
return
SmartPointer<T>
(
nullptr
);
38
}
39
return
spObj.template
DynamicCast<T>
();
40
}
41
46
template
<
typename
T>
47
SmartPointer<T>
GetRequiredService
() {
48
SmartPointer<T>
spService =
GetService<T>
();
49
if
(spService.
IsNull
()) {
50
throw
InvalidOperationException
(
"Required service not registered."
);
51
}
52
return
spService;
53
}
54
};
55
}
56
}
Common.h
Defines common cross-platform macros, export decorators, and fundamental types.
InvalidOperationException.h
Defines the exception thrown when a method call is invalid for the object's current state.
Object.h
Base object class for DotNetDupe mirroring .NET System.Object.
SmartPointer.h
Provides reference-counted and weak pointer memory management primitives ensuring zero raw ownership.
DotNetDupe::System::IServiceProvider
Defines a mechanism for retrieving a service object; that is, an object that provides custom support ...
Definition
IServiceProvider.h:20
DotNetDupe::System::IServiceProvider::GetRequiredService
SmartPointer< T > GetRequiredService()
Gets service of type T, throwing InvalidOperationException if not found.
Definition
IServiceProvider.h:47
DotNetDupe::System::IServiceProvider::GetService
SmartPointer< T > GetService()
Gets the service object of the specified generic type T.
Definition
IServiceProvider.h:34
DotNetDupe::System::IServiceProvider::GetService
virtual SmartPointer< Object > GetService(const std::type_index &serviceType)=0
Gets the service object of the specified type.
DotNetDupe::System::IServiceProvider::~IServiceProvider
virtual ~IServiceProvider()=default
Virtual destructor for polymorphic interface cleanup.
DotNetDupe::System::InvalidOperationException::InvalidOperationException
InvalidOperationException(const String &sMessage)
Initializes a new instance of the InvalidOperationException class with a specified error message.
Definition
InvalidOperationException.h:20
DotNetDupe::System::Object
Supports all classes in the DotNetDupe class hierarchy.
Definition
Object.h:18
DotNetDupe::System::SmartPointer
A unified smart pointer that supports both unique and shared ownership semantics.
Definition
SmartPointer.h:72
DotNetDupe::System::SmartPointer::IsNull
bool IsNull() const noexcept
Checks if the SmartPointer is null.
Definition
SmartPointer.h:393
DotNetDupe::System::SmartPointer::SmartPointer
friend class SmartPointer
Definition
SmartPointer.h:74
DotNetDupe::System
Definition
Action.h:11
DotNetDupe::System::DynamicCast
SmartPointer< To > DynamicCast(const SmartPointer< From > &sp)
Definition
SmartPointer.h:590
DotNetDupe
Definition
IServiceCollection.h:7
Include
System
IServiceProvider.h
Generated by
1.18.0