Beispiel #1
0
    /// <summary>
    /// Get the Python type that reflects the given CLR type.
    /// </summary>
    /// <remarks>
    /// Returned <see cref="ReflectedClrType"/> might be partially initialized.
    /// If you need fully initialized type, use <see cref="GetOrInitialize(ClassBase, Type)"/>
    /// </remarks>
    public static ReflectedClrType GetOrCreate(Type type)
    {
        if (ClassManager.cache.TryGetValue(type, out var pyType))
        {
            return(pyType);
        }

        // Ensure, that matching Python type exists first.
        // It is required for self-referential classes
        // (e.g. with members, that refer to the same class)
        pyType = AllocateClass(type);
        ClassManager.cache.Add(type, pyType);

        var impl = ClassManager.CreateClass(type);

        TypeManager.InitializeClassCore(type, pyType, impl);

        ClassManager.InitClassBase(type, impl, pyType);

        // Now we force initialize the Python type object to reflect the given
        // managed type, filling the Python type slots with thunks that
        // point to the managed methods providing the implementation.
        TypeManager.InitializeClass(pyType, impl, type);

        return(pyType);
    }
Beispiel #2
0
 public void CreateNew(string aName, int aYear, bool aStandartBase)
 {
     ClassManager.CreateClass(TurgoSettings.I.Model, aStandartBase?TurgoSettings.I.UserBaseList:new List <User>(), aName, aYear);
     TurgoSettings.Save(TurgoSettings.I);
     TurgoSettings.Load();
 }