当前位置: 首页>>代码示例>>C#>>正文


C# PythonDictionary.__len__方法代码示例

本文整理汇总了C#中PythonDictionary.__len__方法的典型用法代码示例。如果您正苦于以下问题:C# PythonDictionary.__len__方法的具体用法?C# PythonDictionary.__len__怎么用?C# PythonDictionary.__len__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PythonDictionary的用法示例。


在下文中一共展示了PythonDictionary.__len__方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetInitializedSlotValues

 /// <summary>
 /// Return a dict that maps slot names to slot values, but only include slots that have been assigned to.
 /// Looks up slots in base types as well as the current type.
 /// 
 /// Sort-of Python equivalent (doesn't look up base slots, while the real code does):
 ///   return dict([(slot, getattr(self, slot)) for slot in type(self).__slots__ if hasattr(self, slot)])
 /// 
 /// Return null if the object has no __slots__, or empty dict if it has __slots__ but none are initialized.
 /// </summary>
 private static PythonDictionary GetInitializedSlotValues(object obj) {
     PythonDictionary initializedSlotValues = new PythonDictionary();
     IList<PythonType> mro = DynamicHelpers.GetPythonType(obj).ResolutionOrder;
     object slots;
     object slotValue;
     foreach (object type in mro) {
         if (PythonOps.TryGetBoundAttr(type, Symbols.Slots, out slots)) {
             List<string> slotNames = NewTypeMaker.SlotsToList(slots);
             foreach (string slotName in slotNames) {
                 if (slotName == "__dict__") continue;
                 // don't reassign same-named slots from types earlier in the MRO
                 if (initializedSlotValues.__contains__(slotName)) continue;
                 if (PythonOps.TryGetBoundAttr(obj, SymbolTable.StringToId(slotName), out slotValue)) {
                     initializedSlotValues[slotName] = slotValue;
                 }
             }
         }
     }
     if (initializedSlotValues.__len__() == 0) return null;
     return initializedSlotValues;
 }
开发者ID:octavioh,项目名称:ironruby,代码行数:30,代码来源:ObjectOps.cs


注:本文中的PythonDictionary.__len__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。