File tree Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Original file line number Diff line number Diff line change 125125 <Compile Include =" nativecall.cs" />
126126 <Compile Include =" overload.cs" />
127127 <Compile Include =" propertyobject.cs" />
128+ <Compile Include =" pyansistring.cs" />
128129 <Compile Include =" pydict.cs" />
129130 <Compile Include =" pyfloat.cs" />
130131 <Compile Include =" pyint.cs" />
Original file line number Diff line number Diff line change 1+ public class PyAnsiString : PySequence {
2+ /// <summary>
3+ /// PyAnsiString Constructor
4+ /// </summary>
5+ ///
6+ /// <remarks>
7+ /// Creates a new PyAnsiString from an existing object reference. Note
8+ /// that the instance assumes ownership of the object reference.
9+ /// The object reference is not checked for type-correctness.
10+ /// </remarks>
11+
12+ public PyAnsiString ( IntPtr ptr ) : base ( ptr ) { }
13+
14+
15+ /// <summary>
16+ /// PyString Constructor
17+ /// </summary>
18+ ///
19+ /// <remarks>
20+ /// Copy constructor - obtain a PyAnsiString from a generic PyObject.
21+ /// An ArgumentException will be thrown if the given object is not
22+ /// a Python string object.
23+ /// </remarks>
24+
25+ public PyAnsiString ( PyObject o )
26+ : base ( ) {
27+ if ( ! IsStringType ( o ) ) {
28+ throw new ArgumentException ( "object is not a string" ) ;
29+ }
30+ Runtime . Incref ( o . obj ) ;
31+ obj = o . obj ;
32+ }
33+
34+
35+ /// <summary>
36+ /// PyAnsiString Constructor
37+ /// </summary>
38+ ///
39+ /// <remarks>
40+ /// Creates a Python string from a managed string.
41+ /// </remarks>
42+
43+ public PyAnsiString ( string s )
44+ : base ( ) {
45+ obj = Runtime . PyString_FromStringAndSize ( s , s . Length ) ;
46+ if ( obj == IntPtr . Zero ) {
47+ throw new PythonException ( ) ;
48+ }
49+ }
50+
51+
52+ /// <summary>
53+ /// IsStringType Method
54+ /// </summary>
55+ ///
56+ /// <remarks>
57+ /// Returns true if the given object is a Python string.
58+ /// </remarks>
59+
60+ public static bool IsStringType ( PyObject value ) {
61+ return Runtime . PyString_Check ( value . obj ) ;
62+ }
63+ }
You can’t perform that action at this time.
0 commit comments