Пример #1
0
        /// <summary>
        /// Given generic class type and the passed constructor arguments
        /// creates specific type and instance of the type. Attempts to match
        /// supplied arguments to either __init__ signature or to the
        /// list of generic definitions in Generic[T1, T2, ...].
        /// </summary>
        private IMember CreateClassInstance(PythonClassType cls, IReadOnlyList <IMember> constructorArguments, CallExpression callExpr)
        {
            // Look at the constructor arguments and create argument set
            // based on the __init__ definition.
            var initFunc     = cls.GetMember(@"__init__") as IPythonFunctionType;
            var initOverload = initFunc?.DeclaringType == cls?initFunc.Overloads.FirstOrDefault() : null;

            var argSet = initOverload != null
                    ? new ArgumentSet(initFunc, 0, null, callExpr, this)
                    : new ArgumentSet(constructorArguments, callExpr, this);

            argSet.Evaluate();
            var specificType = cls.CreateSpecificType(argSet);

            return(new PythonInstance(specificType));
        }
Пример #2
0
 public IPythonType CreateSpecificType(IArgumentSet typeArguments)
 {
     EnsureContent();
     return(_cls.CreateSpecificType(typeArguments));
 }