internal static Boolean HasFlagFast(this DataObjectValue.DataObjectValueType source, DataObjectValue.DataObjectValueType flag) { var sourceValue = (Byte)source; var flagValue = (Byte)flag; return (sourceValue & flagValue) == flagValue; }
public static void Main(String[] args) { var dataObjectValue = new DataObjectValue(); var sizeOfDataObjectValue = Marshal.SizeOf(dataObjectValue); WriteLine(sizeOfDataObjectValue); ReadLine(); }
public DataObjectValue Add(DataObjectValue other) { if (_type == DataObjectValueType.None) return other; if (other._type == DataObjectValueType.None) return this; if (_type.HasFlagFast(DataObjectValueType.Boolean)) return other._type.HasFlagFast(DataObjectValueType.Boolean) ? new DataObjectValue(_booleanValue | other._booleanValue) : other; if (other._type.HasFlagFast(DataObjectValueType.Boolean)) return this; if (_type == DataObjectValueType.String) return new DataObjectValue((String)_referenceTypeValue + (String)other); if (other._type == DataObjectValueType.String) return new DataObjectValue((String)this + (String)other._referenceTypeValue); switch (_type) { case DataObjectValueType.Integer: case DataObjectValueType.IntegerString: { if (other._type.HasFlagFast(DataObjectValueType.Integer)) return new DataObjectValue(_intValue + other._intValue); if (other._type.HasFlagFast(DataObjectValueType.Float)) return new DataObjectValue(_intValue + other._singleValue); } break; case DataObjectValueType.Float: case DataObjectValueType.FloatString: { if (other._type.HasFlagFast(DataObjectValueType.Float)) return new DataObjectValue(_singleValue + other._singleValue); if (other._type.HasFlagFast(DataObjectValueType.Integer)) return new DataObjectValue(_singleValue + other._intValue); } break; } return this; }
public DataObjectValue Substact(DataObjectValue other) { if (_type == DataObjectValueType.None) return Nothing; if (other._type == DataObjectValueType.None) return this; if (_type.HasFlagFast(DataObjectValueType.Boolean)) { // false - false = false return other._type.HasFlagFast(DataObjectValueType.Boolean) // false - true = false ? new DataObjectValue(_booleanValue && !other._booleanValue) // true - false = true : other; // true - true = false } if (other._type.HasFlagFast(DataObjectValueType.Boolean)) return this; switch (_type) { case DataObjectValueType.Integer: case DataObjectValueType.IntegerString: { if (other._type.HasFlagFast(DataObjectValueType.Integer)) return new DataObjectValue(_intValue - other._intValue); if (other._type.HasFlagFast(DataObjectValueType.Float)) return new DataObjectValue(_intValue - other._singleValue); } break; case DataObjectValueType.Float: case DataObjectValueType.FloatString: { if (other._type.HasFlagFast(DataObjectValueType.Float)) return new DataObjectValue(_singleValue - other._singleValue); if (other._type.HasFlagFast(DataObjectValueType.Integer)) return new DataObjectValue(_singleValue - other._intValue); } break; } return Equals(other) ? Zero : this; }
private static Single? CastToFloat(DataObjectValue dataObjectValue) { if (dataObjectValue._type.HasFlagFast(DataObjectValueType.Float)) return dataObjectValue._singleValue; if (dataObjectValue._type.HasFlagFast(DataObjectValueType.Boolean)) return dataObjectValue._booleanValue ? MinTrueSingle : DefaultFalseSingle; if (dataObjectValue._type.HasFlagFast(DataObjectValueType.Integer)) return dataObjectValue._intValue; if (dataObjectValue._type.HasFlagFast(DataObjectValueType.String)) { var stringValue = (String)dataObjectValue._referenceTypeValue; return String.IsNullOrEmpty(stringValue) ? default(Single) : stringValue.Length; } if (dataObjectValue._type.HasFlagFast(DataObjectValueType.Object) && dataObjectValue._referenceTypeValue == null) return default(Single); if (dataObjectValue._type == DataObjectValueType.None) return default(Single); return null; }