[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/saroad2/pythonnet/master/src/runtime/DefaultBaseTypeProvider.cs [Back]  [Original]

using System;
using System.Collections.Generic;

namespace Python.Runtime
{
    /// Minimal Python base type provider
    public sealed class DefaultBaseTypeProvider : IPythonBaseTypeProvider
    {
        public IEnumerable GetBaseTypes(Type type, IList 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 new BorrowedReference(Exceptions.Exception);

            return type.BaseType is not null
                ? ClassManager.GetClass(type.BaseType).ObjectReference
                : new BorrowedReference(Runtime.PyBaseObjectType);
        }

        DefaultBaseTypeProvider(){}
        public static DefaultBaseTypeProvider Instance { get; } = new DefaultBaseTypeProvider();
    }
}

Web Proxy Viewer  |  New URL  |  Original Page