示例#1
0
        public override IMember Create(ModuleFactory mf, IPythonType declaringType, IGlobalScope gs)
        {
            if (_cls != null)
            {
                return(_cls);
            }
            _cls = new PythonClassType(Name, new Location(mf.Module, IndexSpan.ToSpan()));
            var bases = CreateBases(mf, gs);

            _cls.SetBases(bases);
            _cls.SetDocumentation(Documentation);

            if (GenericParameterValues.Length > 0)
            {
                _cls.StoreGenericParameters(
                    _cls,
                    _cls.GenericParameters.Keys.ToArray(),
                    GenericParameterValues.ToDictionary(
                        k => _cls.GenericParameters.Keys.First(x => x == k.Name),
                        v => mf.ConstructType(v.Type)
                        )
                    );
            }

            var all = Classes.Concat <MemberModel>(Properties).Concat(Methods).Concat(Fields);

            foreach (var m in all)
            {
                _cls.AddMember(m.Name, m.Create(mf, _cls, gs), false);
            }
            return(_cls);
        }
示例#2
0
        protected override void EnsureContent(ClassModel cm)
        {
            var bases = CreateBases(cm, ModuleFactory, GlobalScope);

            _cls.SetBases(bases);

            if (cm.GenericParameterValues.Length > 0)
            {
                _cls.StoreGenericParameters(
                    _cls,
                    _cls.GenericParameters.Keys.ToArray(),
                    cm.GenericParameterValues.ToDictionary(
                        k => _cls.GenericParameters.Keys.First(x => x == k.Name),
                        v => ModuleFactory.ConstructType(v.Type)
                        )
                    );
            }

            foreach (var model in GetMemberModels(cm))
            {
                _cls.AddMember(model.Name, MemberFactory.CreateMember(model, ModuleFactory, GlobalScope, _cls), false);
            }
            _cls.AddMember("__class__", _cls, true);
        }