本文整理汇总了C#中IronPython.Runtime.Types.PythonType类的典型用法代码示例。如果您正苦于以下问题:C# PythonType类的具体用法?C# PythonType怎么用?C# PythonType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PythonType类属于IronPython.Runtime.Types命名空间,在下文中一共展示了PythonType类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:7,代码来源:PythonTypeWeakRefSlot.cs
示例2: IronPythonTypeWrapper
public IronPythonTypeWrapper(ScriptEngine engine, string name, PythonType pythonType, ObjectHandle classHandle)
{
Name = name;
PythonType = pythonType;
_engine = engine;
_classHandle = classHandle;
}
开发者ID:orthros,项目名称:IronPythonMef,代码行数:7,代码来源:IronPythonTypeWrapper.cs
示例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)));
}
开发者ID:jcteague,项目名称:ironruby,代码行数:27,代码来源:LongOps.cs
示例4: Make
public static InstanceCreator Make(PythonType type) {
if (type.IsSystemType) {
return new SystemInstanceCreator(type);
}
return new UserInstanceCreator(type);
}
开发者ID:tnachen,项目名称:ironruby,代码行数:7,代码来源:InstanceCreator.cs
示例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);
}
}
开发者ID:follesoe,项目名称:ironruby,代码行数:30,代码来源:FloatOps.cs
示例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);
}
开发者ID:rudimk,项目名称:dlr-dotnet,代码行数:27,代码来源:Reversed.cs
示例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);
}
}
开发者ID:techarch,项目名称:ironruby,代码行数:26,代码来源:FloatOps.cs
示例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;
}
开发者ID:nieve,项目名称:ironruby,代码行数:7,代码来源:ModuleOps.cs
示例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;
}
开发者ID:nieve,项目名称:ironruby,代码行数:7,代码来源:ModuleOps.cs
示例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__");
}
开发者ID:jschementi,项目名称:iron,代码行数:30,代码来源:IntOps.Generated.cs
示例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);
}
开发者ID:simplic-systems,项目名称:simplic-dlr,代码行数:13,代码来源:DlrClass.cs
示例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;
}
开发者ID:paweljasinski,项目名称:ironpython3,代码行数:7,代码来源:PythonTypeWeakRefSlot.cs
示例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;
}
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:8,代码来源:ReflectedExtensionProperty.cs
示例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;
}
开发者ID:TerabyteX,项目名称:main,代码行数:8,代码来源:BuiltinClassInfo.cs
示例15: TrySetValue
internal override bool TrySetValue(CodeContext context, object instance, PythonType owner, object value) {
if (instance != null) {
Setter(instance, value);
return true;
}
return false;
}
开发者ID:octavioh,项目名称:ironruby,代码行数:8,代码来源:ReflectedSlotProperty.cs
示例16: __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
示例17: TryGetValue
internal override bool TryGetValue(CodeContext context, object instance, PythonType owner, out object value) {
if (Getter.Length == 0 || (instance == null && Getter[0].IsDefined(typeof(WrapperDescriptorAttribute), false))) {
value = null;
return false;
}
value = CallGetter(context, null, instance, ArrayUtils.EmptyObjects);
return true;
}
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:9,代码来源:ReflectedExtensionProperty.cs
示例18: TryGetValue
internal override bool TryGetValue(CodeContext context, object instance, PythonType owner, out object value) {
try {
value = PythonOps.GetUserDescriptor(Value, instance, owner);
return true;
} catch (MissingMemberException) {
value = null;
return false;
}
}
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:9,代码来源:PythonTypeUserDescriptorSlot.cs
示例19: TryGetValue
internal override bool TryGetValue(CodeContext context, object instance, PythonType owner, out object value) {
if (Getter.Length == 0 || instance == null) {
value = null;
return false;
}
value = CallGetter(context, null, instance, ArrayUtils.EmptyObjects);
return true;
}
开发者ID:jcteague,项目名称:ironruby,代码行数:9,代码来源:ReflectedExtensionProperty.cs
示例20: GetBoundPythonValue
public Expression GetBoundPythonValue(RuleBuilder builder, ActionBinder binder, PythonType accessing) {
return Ast.Call(
typeof(PythonOps).GetMethod("SlotGetValue"),
builder.Context,
Ast.Constant(GetSlot(), typeof(PythonTypeSlot)),
Ast.Constant(null),
Ast.Constant(accessing)
);
}
开发者ID:octavioh,项目名称:ironruby,代码行数:9,代码来源:CustomAttributeTracker.cs
注:本文中的IronPython.Runtime.Types.PythonType类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论