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


C# PythonType.CreateInstance方法代码示例

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


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

示例1: __new__

        public static object __new__(CodeContext/*!*/ context, PythonType cls, object x) {
            if (cls == TypeCache.Double) {
                if (x is string) {
                    return ParseFloat((string)x);
                } else if (x is Extensible<string>) {
                    object res;
                    if (PythonTypeOps.TryInvokeUnaryOperator(context, x, "__float__", out res)) {
                        return res;
                    }
                    return ParseFloat(((Extensible<string>)x).Value);
                } else if (x is char) {
                    return ParseFloat(ScriptingRuntimeHelpers.CharToString((char)x));
                }

                if (x is Complex) {
                    throw PythonOps.TypeError("can't convert complex to float; use abs(z)");
                }

                object d = PythonOps.CallWithContext(context, PythonOps.GetBoundAttr(context, x, "__float__"));
                if (d is double) {
                    return d;
                } else if (d is Extensible<double>) {
                    return ((Extensible<double>)d).Value;
                }

                throw PythonOps.TypeError("__float__ returned non-float (type {0})", PythonTypeOps.GetName(d));
            } else {
                return cls.CreateInstance(context, x);
            }
        }
开发者ID:follesoe,项目名称:ironruby,代码行数:30,代码来源:FloatOps.cs

示例2: CreateNativeWrapper

        public static object CreateNativeWrapper(PythonType type, object holder) {
            Debug.Assert(holder is MemoryHolder);

            CTypes.CData data = (CTypes.CData)type.CreateInstance(type.Context.SharedContext);
            data._memHolder = (MemoryHolder)holder;
            return data;
        }
开发者ID:nieve,项目名称:ironruby,代码行数:7,代码来源:ModuleOps.cs

示例3: CreateCData

 public static object CreateCData(IntPtr dataAddress, PythonType type) {
     CTypes.INativeType nativeType = (CTypes.INativeType)type;
     CTypes.CData data = (CTypes.CData)type.CreateInstance(type.Context.SharedContext);
     data._memHolder = new MemoryHolder(nativeType.Size);
     data._memHolder.CopyFrom(dataAddress, new IntPtr(nativeType.Size));
     return data;
 }
开发者ID:nieve,项目名称:ironruby,代码行数:7,代码来源:ModuleOps.cs

示例4: __new__

        public static object __new__(CodeContext/*!*/ context, PythonType cls, object x) {
            if (cls == TypeCache.Double) {
                if (x is string) {
                    return ParseFloat((string)x);
                } else if (x is Extensible<string>) {
                    object res;
                    if (PythonTypeOps.TryInvokeUnaryOperator(context, x, Symbols.ConvertToFloat, out res)) {
                        return res;
                    }
                    return ParseFloat(((Extensible<string>)x).Value);
                } else if (x is char) {
                    return ParseFloat(ScriptingRuntimeHelpers.CharToString((char)x));
                }

                double doubleVal;
                if (Converter.TryConvertToDouble(x, out doubleVal)) return doubleVal;

                if (x is Complex64) throw PythonOps.TypeError("can't convert complex to float; use abs(z)");

                object d = PythonOps.CallWithContext(context, PythonOps.GetBoundAttr(context, x, Symbols.ConvertToFloat));
                if (d is double) return d;
                throw PythonOps.TypeError("__float__ returned non-float (type %s)", DynamicHelpers.GetPythonType(d));
            } else {
                return cls.CreateInstance(context, x);
            }
        }
开发者ID:techarch,项目名称:ironruby,代码行数:26,代码来源:FloatOps.cs

示例5: __new__

        public static object __new__(CodeContext context, PythonType type, object o) {
            object reversed;
            if (PythonOps.TryGetBoundAttr(context, o, "__reversed__", out reversed)) {
                return PythonCalls.Call(context, reversed);
            }

            object boundFunc;

            PythonTypeSlot getitem;
            PythonType pt = DynamicHelpers.GetPythonType(o);
            if(!pt.TryResolveSlot(context, "__getitem__", out getitem) ||
                !getitem.TryGetValue(context, o, pt, out boundFunc)
                || o is PythonDictionary) {
                throw PythonOps.TypeError("argument to reversed() must be a sequence");
            }

            int length;
            if (!DynamicHelpers.GetPythonType(o).TryGetLength(context, o, out length)) {
                throw PythonOps.TypeError("object of type '{0}' has no len()", DynamicHelpers.GetPythonType(o).Name);
            }

            if (type.UnderlyingSystemType == typeof(ReversedEnumerator)) {
                return new ReversedEnumerator((int)length, boundFunc);
            }

            return type.CreateInstance(context, length, getitem);
        }
开发者ID:rudimk,项目名称:dlr-dotnet,代码行数:27,代码来源:Reversed.cs

示例6: __new__

        public static PythonModule/*!*/ __new__(CodeContext/*!*/ context, PythonType/*!*/ cls, params object[]/*!*/ args\u00F8) {
            PythonModule res;
            if (cls == TypeCache.Module) {
                res = new PythonModule();
            } else if (cls.IsSubclassOf(TypeCache.Module)) {
                res = (PythonModule)cls.CreateInstance(context);
            } else {
                throw PythonOps.TypeError("{0} is not a subtype of module", cls.Name);
            }

            return res;
        }
开发者ID:atczyc,项目名称:ironruby,代码行数:12,代码来源:PythonModule.cs

示例7: __new__

        public static object __new__(CodeContext context, PythonType cls, string s, int radix) {
            if (radix == 16 || radix == 8 || radix == 2) {
                s = Int32Ops.TrimRadix(s, radix);
            }

            if (cls == TypeCache.BigInteger) {
                return ParseBigIntegerSign(s, radix);
            } else {
                BigInteger res = ParseBigIntegerSign(s, radix);
                return cls.CreateInstance(context, res);
            }
        }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:12,代码来源:LongOps.cs

示例8: __new__

        public static Scope/*!*/ __new__(CodeContext/*!*/ context, PythonType/*!*/ cls, params object[]/*!*/ args\u00F8) {
            Scope res;
            if (cls == TypeCache.Module) {
                res = new Scope(PythonDictionary.MakeSymbolDictionary());
            } else if (cls.IsSubclassOf(TypeCache.Module)) {
                res = (Scope)cls.CreateInstance(context);
            } else {
                throw PythonOps.TypeError("{0} is not a subtype of module", cls.Name);
            }

            PythonContext.GetContext(context).CreateModule(null, res, null, ModuleOptions.None);
            res.Clear();
            return res;
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:14,代码来源:ScopeOps.cs

示例9: __new__

        public static object __new__(CodeContext/*!*/ context, PythonType cls, IList<byte> s) {
            if (cls == TypeCache.BigInteger) {
                object value;
                IPythonObject po = s as IPythonObject;
                if (po != null &&
                    PythonTypeOps.TryInvokeUnaryOperator(DefaultContext.Default, po, "__long__", out value)) {
                    return value;
                }

                return ParseBigIntegerSign(s.MakeString(), 10);
            }

            return cls.CreateInstance(context, ParseBigIntegerSign(s.MakeString(), 10));
        }
开发者ID:yarrow2,项目名称:ironruby,代码行数:14,代码来源:LongOps.cs

示例10: __new__

        public static object __new__(CodeContext/*!*/ context, PythonType cls, IList<byte> s) {
            if (cls == TypeCache.BigInteger) {
                object value;
                IPythonObject po = s as IPythonObject;
                if (po != null &&
                    PythonTypeOps.TryInvokeUnaryOperator(DefaultContext.Default, po, Symbols.ConvertToLong, out value)) {
                    return value;
                }

                return ParseBigIntegerSign(StringOps.FromByteArray(s), 10);
            }

            return cls.CreateInstance(context, ParseBigIntegerSign(StringOps.FromByteArray(s), 10));
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:14,代码来源:LongOps.cs

示例11: __new__

            public static object __new__(CodeContext context, PythonType cls, object @object) {
                IWeakReferenceable iwr = ConvertToWeakReferenceable(@object);

                if (cls == DynamicHelpers.GetPythonTypeFromType(typeof(@ref))) {
                    WeakRefTracker wrt = iwr.GetWeakRef();
                    if (wrt != null) {
                        for (int i = 0; i < wrt.HandlerCount; i++) {
                            if (wrt.GetHandlerCallback(i) == null && wrt.GetWeakRef(i) is @ref) {
                                return wrt.GetWeakRef(i);
                            }
                        }
                    }

                    return new @ref(@object);
                } else {
                    return cls.CreateInstance(context, @object);
                }
            }
开发者ID:jcteague,项目名称:ironruby,代码行数:18,代码来源:_weakref.cs

示例12: __new__

        public static object __new__(CodeContext/*!*/ context, PythonType cls, params object[] args\u00F8) {
            if (cls == null) {
                throw PythonOps.TypeError("__new__ expected type object, got {0}", PythonOps.Repr(context, DynamicHelpers.GetPythonType(cls)));
            }

            InstanceOps.CheckInitArgs(context, null, args\u00F8, cls);

            return cls.CreateInstance(context);
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:9,代码来源:ObjectOps.cs

示例13: ReturnObject

 private static object ReturnObject(CodeContext context, PythonType cls, object value) {
     if (cls == TypeCache.BigInteger) {
         return value;
     } else {
         return cls.CreateInstance(context, value);
     }
 }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:7,代码来源:LongOps.cs

示例14: __new__

        public static object __new__(CodeContext/*!*/ context, PythonType cls) {
            if (cls == null) {
                throw PythonOps.TypeError("__new__ expected type object, got {0}", PythonOps.Repr(context, DynamicHelpers.GetPythonType(cls)));
            }

            return cls.CreateInstance(context);
        }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:7,代码来源:ObjectOps.cs

示例15: __new__

 public static struct_time __new__(CodeContext context, PythonType cls, int year, int month, int day, int hour, int minute, int second, int dayOfWeek, int dayOfYear, int isDst) {
     if (cls == _StructTimeType) {
         return new struct_time(year, month, day, hour, minute, second, dayOfWeek, dayOfYear, isDst);
     } else {
         struct_time st = cls.CreateInstance(context, year, month, day, hour, minute, second, dayOfWeek, dayOfYear, isDst) as struct_time;
         if (st == null)
             throw PythonOps.TypeError("{0} is not a subclass of time.struct_time", cls);
         return st;
     }
 }
开发者ID:kashano,项目名称:main,代码行数:10,代码来源:time.cs


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