public unsafe static void __Process( [DataType("ANY")] ref Any Fun_with_ANY_BIT, [Input, DataType("ANY_BIT")] ref Any VALUE) { // get the size of the connected value type uint SIZE_OF_VALUE = VALUE.nLength; // Get the element type constants associate to the runtime type handle. // The values are defined in the standard ECMA-335 "Common Language Infrastructure (CLI)", // Partition II, chapter II.23.1.16 "Element types used in signatures") Eclr.TypeCode code = (Eclr.TypeCode)Eclr.TypeInfo.GetTypeCode(VALUE.pRuntimeTypeHandle); // type dependent action if (code == Eclr.TypeCode.Int16) // short (2 bytes) { short tempValue = *((short *)VALUE.pValue); short *pResult = (short *)Fun_with_ANY_BIT.pValue; *pResult = tempValue; } else if (code == Eclr.TypeCode.UInt16) // unsigned short (2 bytes) { ushort tempValue = *((ushort *)VALUE.pValue); ushort *pResult = (ushort *)Fun_with_ANY_BIT.pValue; *pResult = tempValue; } else if (code == Eclr.TypeCode.Int32) // int (4 Bytes) { int tempValue = *((int *)VALUE.pValue); int *pResult = (int *)Fun_with_ANY_BIT.pValue; *pResult = tempValue; } else if (code == Eclr.TypeCode.UInt32) // unsigned (4 Bytes) { uint tempValue = *((uint *)VALUE.pValue); uint *pResult = (uint *)Fun_with_ANY_BIT.pValue; *pResult = tempValue; } else { // ... } }
public unsafe void __Process() { // get the size of the connected value type SIZE_OF_VALUE = VALUE.nLength; // Get the element type constants associate to the runtime type handle. // The values are defined in the standard ECMA-335 "Common Language Infrastructure (CLI)", // Partition II, chapter II.23.1.16 "Element types used in signatures") Eclr.TypeCode code = (Eclr.TypeCode)Eclr.TypeInfo.GetTypeCode(VALUE.pRuntimeTypeHandle); // type dependent action if (code == Eclr.TypeCode.Boolean) // unsigned short (2 bytes) { ushort tempValue = *((ushort *)VALUE.pValue); ushort *pResult = (ushort *)RESULT.pValue; *pResult = tempValue; } else if (code == Eclr.TypeCode.Byte) // unsigned short (2 bytes) { ushort tempValue = *((ushort *)VALUE.pValue); ushort *pResult = (ushort *)RESULT.pValue; *pResult = tempValue; } else if (code == Eclr.TypeCode.UInt16) // unsigned short (2 bytes) { ushort tempValue = *((ushort *)VALUE.pValue); ushort *pResult = (ushort *)RESULT.pValue; *pResult = tempValue; } else if (code == Eclr.TypeCode.UInt32) // unsigned int (4 bytes) { uint tempValue = *((uint *)VALUE.pValue); uint *pResult = (uint *)RESULT.pValue; *pResult = tempValue; } else { // ... } }
public unsafe void __Process() { // Important due to unsafe programming: // Check whether all parameters have the same data type!!! if (VALUE.pRuntimeTypeHandle != MIN.pRuntimeTypeHandle || VALUE.pRuntimeTypeHandle != MAX.pRuntimeTypeHandle) { return; } // get the size of the connected value type SIZE_OF_VALUE = VALUE.nLength; // Get the element type constants associate to the runtime type handle. // The values are defined in the standard ECMA-335 "Common Language Infrastructure (CLI)", // Partition II, chapter II.23.1.16 "Element types used in signatures") Eclr.TypeCode code = (Eclr.TypeCode)Eclr.TypeInfo.GetTypeCode(VALUE.pRuntimeTypeHandle); // type dependent action if (code == Eclr.TypeCode.Int16) // short (2 bytes) { short tempValue = *((short *)VALUE.pValue); short tempMin = *((short *)MIN.pValue); short tempMax = *((short *)MAX.pValue); if (tempValue < tempMin) { tempValue = tempMin; } if (tempValue > tempMax) { tempValue = tempMax; } RESULT = tempValue; } else if (code == Eclr.TypeCode.UInt16) // unsigned short (2 bytes) { ushort tempValue = *((ushort *)VALUE.pValue); ushort tempMin = *((ushort *)MIN.pValue); ushort tempMax = *((ushort *)MAX.pValue); if (tempValue < tempMin) { tempValue = tempMin; } if (tempValue > tempMax) { tempValue = tempMax; } RESULT = tempValue; } else if (code == Eclr.TypeCode.Int32) // int (4 bytes) { int tempValue = *((int *)VALUE.pValue); int tempMin = *((int *)MIN.pValue); int tempMax = *((int *)MAX.pValue); if (tempValue < tempMin) { tempValue = tempMin; } if (tempValue > tempMax) { tempValue = tempMax; } RESULT = tempValue; } else if (code == Eclr.TypeCode.UInt32) // unsigned int (4 bytes) { uint tempValue = *((uint *)VALUE.pValue); uint tempMin = *((uint *)MIN.pValue); uint tempMax = *((uint *)MAX.pValue); if (tempValue < tempMin) { tempValue = tempMin; } if (tempValue > tempMax) { tempValue = tempMax; } RESULT = (int)tempValue; } else { // ... } }