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


C# IAttributesCollection.TryGetValue方法代码示例

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


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

示例1: StructType

            public StructType(CodeContext/*!*/ context, string name, PythonTuple bases, IAttributesCollection members)
                : base(context, name, bases, members) {

                foreach (PythonType pt in ResolutionOrder) {
                    StructType st = pt as StructType;
                    if (st != this && st != null) {
                        st.EnsureFinal();
                    }

                    UnionType ut = pt as UnionType;
                    if (ut != null) {
                        ut.EnsureFinal();
                    }
                }

                object pack;
                if (members.TryGetValue(SymbolTable.StringToId("_pack_"), out pack)) {
                    if (!(pack is int) || ((int)pack < 0)) {
                        throw PythonOps.ValueError("pack must be a non-negative integer");
                    }
                    _pack = (int)pack;
                }

                object fields;
                if (members.TryGetValue(SymbolTable.StringToId("_fields_"), out fields)) {
                    SetFields(fields);
                }

                // TODO: _anonymous_
            }
开发者ID:joshholmes,项目名称:ironruby,代码行数:30,代码来源:StructType.cs

示例2: ArrayType

            public ArrayType(CodeContext/*!*/ context, string name, PythonTuple bases, IAttributesCollection dict)
                : base(context, name, bases, dict) {
                object len;
                int iLen;
                if (!dict.TryGetValue(SymbolTable.StringToId("_length_"), out len) || !(len is int) || (iLen = (int)len) < 0) {
                    throw PythonOps.AttributeError("arrays must have _length_ attribute and it must be a positive integer");
                }

                object type;
                if (!dict.TryGetValue(SymbolTable.StringToId("_type_"), out type)) {
                    throw PythonOps.AttributeError("class must define a '_type_' attribute");
                }

                _length = iLen;
                _type = (INativeType)type;

                if (_type is SimpleType) {
                    SimpleType st = (SimpleType)_type;
                    if (st._type == SimpleTypeKind.Char) {
                        // TODO: (c_int * 2).value isn't working
                        SetCustomMember(context,
                            SymbolTable.StringToId("value"),
                            new ReflectedExtensionProperty(
                                new ExtensionPropertyInfo(this, typeof(CTypes).GetMethod("GetCharArrayValue")),
                                NameType.Property | NameType.Python
                            )
                        );

                        SetCustomMember(context,
                            SymbolTable.StringToId("raw"),
                            new ReflectedExtensionProperty(
                                new ExtensionPropertyInfo(this, typeof(CTypes).GetMethod("GetWCharArrayRaw")),
                                NameType.Property | NameType.Python
                            )
                        );
                    } else if (st._type == SimpleTypeKind.WChar) {
                        SetCustomMember(context,
                            SymbolTable.StringToId("value"),
                            new ReflectedExtensionProperty(
                                new ExtensionPropertyInfo(this, typeof(CTypes).GetMethod("GetWCharArrayValue")),
                                NameType.Property | NameType.Python
                            )
                        );

                        SetCustomMember(context,
                            SymbolTable.StringToId("raw"),
                            new ReflectedExtensionProperty(
                                new ExtensionPropertyInfo(this, typeof(CTypes).GetMethod("GetWCharArrayRaw")),
                                NameType.Property | NameType.Python
                            )
                        );
                    }
                }
            }
开发者ID:techarch,项目名称:ironruby,代码行数:54,代码来源:ArrayType.cs

示例3: UnionType

            public UnionType(CodeContext/*!*/ context, string name, PythonTuple bases, IAttributesCollection members)
                : base(context, name, bases, members) {

                object fields;
                if (members.TryGetValue(SymbolTable.StringToId("_fields_"), out fields)) {
                    SetFields(fields);
                }
            }
开发者ID:xerxesb,项目名称:ironruby,代码行数:8,代码来源:UnionType.cs

示例4: PointerType

            public PointerType(CodeContext/*!*/ context, string name, PythonTuple bases, IAttributesCollection members)
                : base(context, name, bases, members) {

                object type;
                if (members.TryGetValue(SymbolTable.StringToId("_type_"), out type) && !(type is INativeType)) {
                    throw PythonOps.TypeError("_type_ must be a type");
                }
                _type = (INativeType)type;
            }
开发者ID:joshholmes,项目名称:ironruby,代码行数:9,代码来源:PointerType.cs

示例5: VerifyMaxLen

            private static int VerifyMaxLen(IAttributesCollection dict) {
                if (dict.Count != 1) {
                    throw PythonOps.TypeError("deque() takes at most 1 keyword argument ({0} given)", dict.Count);
                }
                
                object value;
                if (!dict.TryGetValue(SymbolTable.StringToId("maxlen"), out value)) {
                    IEnumerator<object> e = dict.Keys.GetEnumerator();
                    if (e.MoveNext()) {
                        throw PythonOps.TypeError("deque(): '{0}' is an invalid keyword argument", e.Current);
                    }
                }

                return VerifyMaxLenValue(value);
            }
开发者ID:rvernagus,项目名称:ironruby,代码行数:15,代码来源:_collections.cs

示例6: VerifyMaxLen

            private static int VerifyMaxLen(IAttributesCollection dict) {
                if (dict.Count != 1) {
                    throw PythonOps.TypeError("deque() takes at most 1 keyword argument ({0} given)", dict.Count);
                }
                
                object value;
                if (!dict.TryGetValue(SymbolTable.StringToId("maxlen"), out value)) {
                    IEnumerator<object> e = dict.Keys.GetEnumerator();
                    if (e.MoveNext()) {
                        throw PythonOps.TypeError("deque(): '{0}' is an invalid keyword argument", e.Current);
                    }
                }

                if (value is int) return (int)value;
                else if (value is Extensible<int>) return ((Extensible<int>)value).Value;
                throw PythonOps.TypeError("deque(): keyword argument 'maxlen' requires integer");
            }
开发者ID:octavioh,项目名称:ironruby,代码行数:17,代码来源:collections.cs

示例7: InitializeSlots

        private void InitializeSlots(string name, PythonTuple bases, IAttributesCollection vars) {
            List<string> slots = NewTypeMaker.GetSlots(vars);

            if (slots != null) {
                int index = 0;
                foreach (object o in bases) {
                    PythonType pt = o as PythonType;
                    if (pt == null) {
                        continue;
                    }

                    index += pt.SlotCount;
                }

                for (int i = 0; i < slots.Count; i++) {
                    string slotName = slots[i];
                    if (slotName.StartsWith("__") && !slotName.EndsWith("__")) {
                        slotName = "_" + name + slotName;
                    }

                    SymbolId id = SymbolTable.StringToId(slotName);

                    // don't replace existing values, they'll just be read-only.  For example
                    // class foo(object):
                    //     __slots__ = ['__init__']
                    //     def __init__(self): pass
                    //
                    object dummy;
                    if (vars.TryGetValue(id, out dummy) ||
                        id == Symbols.Dict ||
                        id == Symbols.WeakRef) {
                        continue;
                    }

                    AddSlot(id, new ReflectedSlotProperty(slotName, name, i + index));
                }
            }
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:38,代码来源:PythonType.cs

示例8: GetSlots

        internal static List<string> GetSlots(IAttributesCollection dict) {
            List<string> res = null;
            object slots;
            if (dict != null && dict.TryGetValue(Symbols.Slots, out slots)) {
                res = SlotsToList(slots);
            }

            return res;
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:9,代码来源:NewTypeMaker.cs


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