本文整理汇总了C#中IronPython.Runtime.Types.PythonType类的典型用法代码示例。如果您正苦于以下问题:C# PythonType类的具体用法?C# PythonType怎么用?C# PythonType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PythonType类属于IronPython.Runtime.Types命名空间,在下文中一共展示了PythonType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TrySetValue
internal override bool TrySetValue(CodeContext context, object instance, PythonType owner, object value) {
IWeakReferenceable reference = instance as IWeakReferenceable;
if (reference != null) {
return reference.SetWeakRef(new WeakRefTracker(value, instance));
}
return false;
}
示例2: IronPythonTypeWrapper
public IronPythonTypeWrapper(ScriptEngine engine, string name, PythonType pythonType, ObjectHandle classHandle)
{
Name = name;
PythonType = pythonType;
_engine = engine;
_classHandle = classHandle;
}
示例3: __new__
public static object __new__(CodeContext context, PythonType cls, object x) {
Extensible<string> es;
if (x is string) {
return ReturnBigInteger(context, cls, ParseBigIntegerSign((string)x, 10));
} else if ((es = x as Extensible<string>) != null) {
object value;
if (PythonTypeOps.TryInvokeUnaryOperator(context, x, Symbols.ConvertToLong, out value)) {
return ReturnBigInteger(context, cls, (BigInteger)value);
}
return ReturnBigInteger(context, cls, ParseBigIntegerSign(es.Value, 10));
}
BigInteger intVal;
if (Converter.TryConvertToBigInteger(x, out intVal)) {
if (Object.Equals(intVal, null)) throw PythonOps.TypeError("can't convert {0} to long", PythonTypeOps.GetName(x));
return ReturnBigInteger(context, cls, intVal);
}
if (x is Complex64) throw PythonOps.TypeError("can't convert complex to long; use long(abs(z))");
throw PythonOps.ValueError("long argument must be convertible to long (string, number, or type that defines __long__, got {0})",
StringOps.Quote(PythonOps.GetPythonTypeName(x)));
}
示例4: Make
public static InstanceCreator Make(PythonType type) {
if (type.IsSystemType) {
return new SystemInstanceCreator(type);
}
return new UserInstanceCreator(type);
}
示例5: __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);
}
}
示例6: __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);
}
示例7: __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);
}
}
示例8: 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;
}
示例9: 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;
}
示例10: __new__
public static object __new__(PythonType cls, object value) {
if (cls != DynamicHelpers.GetPythonTypeFromType(typeof(SByte))) {
throw PythonOps.TypeError("SByte.__new__: first argument must be SByte type.");
}
IConvertible valueConvertible;
if ((valueConvertible = value as IConvertible) != null) {
switch (valueConvertible.GetTypeCode()) {
case TypeCode.Byte: return (SByte)(Byte)value;
case TypeCode.SByte: return (SByte)(SByte)value;
case TypeCode.Int16: return (SByte)(Int16)value;
case TypeCode.UInt16: return (SByte)(UInt16)value;
case TypeCode.Int32: return (SByte)(Int32)value;
case TypeCode.UInt32: return (SByte)(UInt32)value;
case TypeCode.Int64: return (SByte)(Int64)value;
case TypeCode.UInt64: return (SByte)(UInt64)value;
case TypeCode.Single: return (SByte)(Single)value;
case TypeCode.Double: return (SByte)(Double)value;
}
}
if (value is String) {
return SByte.Parse((String)value);
} else if (value is BigInteger) {
return (SByte)(BigInteger)value;
} else if (value is Extensible<BigInteger>) {
return (SByte)((Extensible<BigInteger>)value).Value;
} else if (value is Extensible<double>) {
return (SByte)((Extensible<double>)value).Value;
}
throw PythonOps.ValueError("invalid value for SByte.__new__");
}
示例11: DlrClass
/// <summary>
/// Create new dlr class
/// </summary>
/// <param name="scriptScope">Scope which contains the class definition and in which the instance will be created</param>
/// <param name="pythonType">Python-Type instance</param>
/// <param name="parameter">Arguments for the constructor</param>
public DlrClass(DlrScriptScope scriptScope, PythonType pythonType, params object[] parameter)
{
this.scriptScope = scriptScope;
// create class instance
instance = scriptScope.Host.ScriptEngine.Operations.CreateInstance(pythonType, parameter);
}
示例12: TrySetValue
internal override bool TrySetValue(CodeContext context, object instance, PythonType owner, object value) {
IWeakReferenceable reference;
if (context.GetPythonContext().TryConvertToWeakReferenceable(instance, out reference)) {
return reference.SetWeakRef(new WeakRefTracker(value, instance));
}
return false;
}
示例13: TryDeleteValue
internal override bool TryDeleteValue(CodeContext context, object instance, PythonType owner) {
if (_deleter == null || instance == null) {
return base.TryDeleteValue(context, instance, owner);
}
CallTarget(context, null, new MethodInfo[] { _deleter }, instance);
return true;
}
示例14: BuiltinClassInfo
public BuiltinClassInfo(PythonType classObj, ProjectState projectState)
: base(new LazyDotNetDict(classObj, projectState, true))
{
// TODO: Get parameters from ctor
// TODO: All types should be shared via projectState
_type = classObj;
_doc = null;
}
示例15: TrySetValue
internal override bool TrySetValue(CodeContext context, object instance, PythonType owner, object value) {
if (instance != null) {
Setter(instance, value);
return true;
}
return false;
}