Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
DynamicInterfaceCastableHelpers.cs
Go to the documentation of this file.
2
4
5internal static class DynamicInterfaceCastableHelpers
6{
7 [StackTraceHidden]
8 internal static bool IsInterfaceImplemented(IDynamicInterfaceCastable castable, RuntimeType interfaceType, bool throwIfNotImplemented)
9 {
10 bool flag = castable.IsInterfaceImplemented(new RuntimeTypeHandle(interfaceType), throwIfNotImplemented);
11 if (!flag && throwIfNotImplemented)
12 {
13 throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, castable.GetType(), interfaceType));
14 }
15 return flag;
16 }
17
18 [StackTraceHidden]
20 {
21 RuntimeTypeHandle interfaceImplementation = castable.GetInterfaceImplementation(new RuntimeTypeHandle(interfaceType));
22 if (interfaceImplementation.Equals(default(RuntimeTypeHandle)))
23 {
24 throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, castable.GetType(), interfaceType));
25 }
26 RuntimeType runtimeType = interfaceImplementation.GetRuntimeType();
27 if (!runtimeType.IsInterface)
28 {
30 }
31 if (!runtimeType.IsDefined(typeof(DynamicInterfaceCastableImplementationAttribute), inherit: false))
32 {
33 throw new InvalidOperationException(SR.Format(SR.IDynamicInterfaceCastable_MissingImplementationAttribute, runtimeType, "DynamicInterfaceCastableImplementationAttribute"));
34 }
35 if (!runtimeType.IsAssignableTo(interfaceType))
36 {
38 }
39 return runtimeType;
40 }
41}
override string ToString()
override bool IsDefined(Type attributeType, bool inherit)
static RuntimeType GetInterfaceImplementation(IDynamicInterfaceCastable castable, RuntimeType interfaceType)
static bool IsInterfaceImplemented(IDynamicInterfaceCastable castable, RuntimeType interfaceType, bool throwIfNotImplemented)
static string IDynamicInterfaceCastable_MissingImplementationAttribute
Definition SR.cs:2172
static string InvalidCast_FromTo
Definition SR.cs:1392
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string IDynamicInterfaceCastable_NotInterface
Definition SR.cs:2174
static string IDynamicInterfaceCastable_DoesNotImplementRequested
Definition SR.cs:2170
Definition SR.cs:7
bool IsInterface
Definition Type.cs:30
bool IsAssignableTo([NotNullWhen(true)] Type? targetType)
Definition Type.cs:531
RuntimeTypeHandle GetInterfaceImplementation(RuntimeTypeHandle interfaceType)
bool IsInterfaceImplemented(RuntimeTypeHandle interfaceType, bool throwIfNotImplemented)
override bool Equals(object? obj)