forked from pythonnet/pythonnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefaultBaseTypeProvider.cs
More file actions
34 lines (29 loc) · 1.19 KB
/
DefaultBaseTypeProvider.cs
File metadata and controls
34 lines (29 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Collections.Generic;
namespace Python.Runtime
{
/// <summary>Minimal Python base type provider</summary>
public sealed class DefaultBaseTypeProvider : IPythonBaseTypeProvider
{
public IEnumerable<PyType> GetBaseTypes(Type type, IList<PyType> existingBases)
{
if (type is null)
throw new ArgumentNullException(nameof(type));
if (existingBases is null)
throw new ArgumentNullException(nameof(existingBases));
if (existingBases.Count > 0)
throw new ArgumentException("To avoid confusion, this type provider requires the initial set of base types to be empty");
return new[] { new PyType(GetBaseType(type)) };
}
static BorrowedReference GetBaseType(Type type)
{
if (type == typeof(Exception))
return Exceptions.Exception;
return type.BaseType is not null
? ClassManager.GetClass(type.BaseType)
: Runtime.PyBaseObjectType;
}
DefaultBaseTypeProvider(){}
public static DefaultBaseTypeProvider Instance { get; } = new DefaultBaseTypeProvider();
}
}