本文整理汇总了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);
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
}
示例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;
}
示例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));
}
示例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));
}
示例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);
}
}
示例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);
}
示例13: ReturnObject
private static object ReturnObject(CodeContext context, PythonType cls, object value) {
if (cls == TypeCache.BigInteger) {
return value;
} else {
return cls.CreateInstance(context, value);
}
}
示例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);
}
示例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;
}
}