DotNet32¤
Wrapper around a 32-bit .NET library.
Example of a server that loads a 32-bit library, dotnet_lib32.dll, in a 32-bit Python interpreter to host the library. The corresponding DotNet64 class is created in a 64-bit Python interpreter and the DotNet64 class sends requests to the DotNet32 class which calls the 32-bit library to execute the request and then returns the response from the library.
DotNet32 ¤
DotNet32(host, port)
Bases: Server32
Wrapper around a 32-bit .NET library.
Python.NET can handle many native Python data types as input arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host
|
str
|
The IP address (or hostname) to use for the server. |
required |
port
|
int
|
The port to open for the server. |
required |
Source code in src/msl/examples/loadlib/dotnet32.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
add_integers ¤
add_integers(a, b)
Add two integers.
The corresponding C# code is
public int add_integers(int a, int b)
{
return a + b;
}
See the corresponding DotNet64.add_integers method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
int
|
First integer. |
required |
b
|
int
|
Second integer. |
required |
Returns:
Type | Description |
---|---|
int
|
The sum, |
Source code in src/msl/examples/loadlib/dotnet32.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
add_multiple ¤
add_multiple(a, b, c, d, e)
Add multiple integers.
Calls a static method in a static class.
The corresponding C# code is
public static int add_multiple(int a, int b, int c, int d, int e)
{
return a + b + c + d + e;
}
See the corresponding DotNet64.add_multiple method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
int
|
First integer. |
required |
b
|
int
|
Second integer. |
required |
c
|
int
|
Third integer. |
required |
d
|
int
|
Fourth integer. |
required |
e
|
int
|
Fifth integer. |
required |
Returns:
Type | Description |
---|---|
int
|
The sum of the input arguments. |
Source code in src/msl/examples/loadlib/dotnet32.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
add_or_subtract ¤
add_or_subtract(a, b, *, do_addition)
Add or subtract two C# double-precision numbers.
The corresponding C# code is
public double add_or_subtract(double a, double b, bool do_addition)
{
if (do_addition)
{
return a + b;
}
else
{
return a - b;
}
}
See the corresponding DotNet64.add_or_subtract method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
float
|
First double-precision number. |
required |
b
|
float
|
Second double-precision number. |
required |
do_addition
|
bool
|
Whether to add or subtract the numbers. |
required |
Returns:
Type | Description |
---|---|
float
|
|
Source code in src/msl/examples/loadlib/dotnet32.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
concatenate ¤
concatenate(a, b, c, d, e)
Concatenate strings.
Calls a static method in a static class.
The corresponding C# code is
public static string concatenate(string a, string b, string c, bool d, string e)
{
string res = a + b + c;
if (d)
{
res += e;
}
return res;
}
See the corresponding DotNet64.concatenate method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
str
|
First string. |
required |
b
|
str
|
Second string. |
required |
c
|
str
|
Third string. |
required |
d
|
bool
|
Whether to include |
required |
e
|
str
|
Fourth string. |
required |
Returns:
Type | Description |
---|---|
str
|
The strings concatenated together. |
Source code in src/msl/examples/loadlib/dotnet32.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
|
divide_floats ¤
divide_floats(a, b)
Divide two C# floating-point numbers.
The corresponding C# code is
public float divide_floats(float a, float b)
{
return a / b;
}
See the corresponding DotNet64.divide_floats method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
float
|
The numerator. |
required |
b
|
float
|
The denominator. |
required |
Returns:
Type | Description |
---|---|
float
|
The quotient, |
Source code in src/msl/examples/loadlib/dotnet32.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
get_class_names ¤
get_class_names()
Gets the class names in the library.
Calls GetTypes using the assembly property.
See the corresponding DotNet64.get_class_names method.
Returns:
Type | Description |
---|---|
list[str]
|
The names of the classes that are available in dotnet_lib32.dll. |
Source code in src/msl/examples/loadlib/dotnet32.py
41 42 43 44 45 46 47 48 49 50 51 52 |
|
multiply_doubles ¤
multiply_doubles(a, b)
Multiply two C# double-precision numbers.
The corresponding C# code is
public double multiply_doubles(double a, double b)
{
return a * b;
}
See the corresponding DotNet64.multiply_doubles method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
float
|
First double-precision number. |
required |
b
|
float
|
Second double-precision number. |
required |
Returns:
Type | Description |
---|---|
float
|
The product, |
Source code in src/msl/examples/loadlib/dotnet32.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
multiply_matrices ¤
multiply_matrices(a1, a2)
Multiply two matrices.
The corresponding C# code is
public double[,] multiply_matrices(double[,] A, double[,] B)
{
int rA = A.GetLength(0);
int cA = A.GetLength(1);
int rB = B.GetLength(0);
int cB = B.GetLength(1);
double temp = 0;
double[,] C = new double[rA, cB];
if (cA != rB)
{
Console.WriteLine("matrices can't be multiplied!");
return new double[0, 0];
}
else
{
for (int i = 0; i < rA; i++)
{
for (int j = 0; j < cB; j++)
{
temp = 0;
for (int k = 0; k < cA; k++)
{
temp += A[i, k] * B[k, j];
}
C[i, j] = temp;
}
}
return C;
}
}
See the corresponding DotNet64.multiply_matrices method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a1
|
Sequence[Sequence[float]]
|
First matrix. |
required |
a2
|
Sequence[Sequence[float]]
|
Second matrix. |
required |
Returns:
Type | Description |
---|---|
list[list[float]]
|
The result, |
Source code in src/msl/examples/loadlib/dotnet32.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
|
reverse_string ¤
reverse_string(original)
Reverse a string.
The corresponding C# code is
public string reverse_string(string original)
{
char[] charArray = original.ToCharArray();
Array.Reverse(charArray);
return new string(charArray);
}
See the corresponding DotNet64.reverse_string method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
original
|
str
|
The original string. |
required |
Returns:
Type | Description |
---|---|
str
|
The string reversed. |
Source code in src/msl/examples/loadlib/dotnet32.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
|
scalar_multiply ¤
scalar_multiply(a, xin)
Multiply each element in an array by a number.
The corresponding C# code is
public double[] scalar_multiply(double a, double[] xin)
{
int n = xin.GetLength(0);
double[] xout = new double[n];
for (int i = 0; i < n; i++)
{
xout[i] = a * xin[i];
}
return xout;
}
See the corresponding DotNet64.scalar_multiply method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
float
|
Scalar value. |
required |
xin
|
Sequence[float]
|
Array to modify. |
required |
Returns:
Type | Description |
---|---|
list[float]
|
A new array with each element in |
Source code in src/msl/examples/loadlib/dotnet32.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|