F
Funky
In the code snippet below, I have a base class (originally written in
C++) that byte swaps data when assigned or read from the class (thus,
always storing the data as big-endian).
As for those wondering how the data is set outside these 2 public
operations: This class is later used to declare attributes in other
classes and in these other classes, System.IO.Buffer is used copy bytes
from a socket.
So anyway, I see that C# does not support assignment operator
overloading. Nor does it support primitive type overloading. What are
my alternatives?
using System;
using System.Collections.Generic;
using System.Text;
namespace TestApp {
class BaseClass {
/* Always stored in big-endian */
private ushort myValue;
private static ushort swap(ushort input) {
return((ushort)((0xFF00 & input) >> 8) | ((0x00FF & input) << 8));
}
public operator ushort () {
return (swap(myValue));
}
public BaseClass operator= (byte rhs) {
myValue = swap(rhs);
return(this);
}
}
}
C++) that byte swaps data when assigned or read from the class (thus,
always storing the data as big-endian).
As for those wondering how the data is set outside these 2 public
operations: This class is later used to declare attributes in other
classes and in these other classes, System.IO.Buffer is used copy bytes
from a socket.
So anyway, I see that C# does not support assignment operator
overloading. Nor does it support primitive type overloading. What are
my alternatives?
using System;
using System.Collections.Generic;
using System.Text;
namespace TestApp {
class BaseClass {
/* Always stored in big-endian */
private ushort myValue;
private static ushort swap(ushort input) {
return((ushort)((0xFF00 & input) >> 8) | ((0x00FF & input) << 8));
}
public operator ushort () {
return (swap(myValue));
}
public BaseClass operator= (byte rhs) {
myValue = swap(rhs);
return(this);
}
}
}