本文整理汇总了C#中UIntPtr.ToPointer方法的典型用法代码示例。如果您正苦于以下问题:C# UIntPtr.ToPointer方法的具体用法?C# UIntPtr.ToPointer怎么用?C# UIntPtr.ToPointer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIntPtr
的用法示例。
在下文中一共展示了UIntPtr.ToPointer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PosTest1
public bool PosTest1()
{
bool retVal = true;
const string c_TEST_ID = "P001";
string testDesc = string.Format("PosTest1: value is a random {0}-bit c-style generic pointer",
8*UIntPtr.Size);
string errorDesc;
UIntPtr actualUIntPtr;
bool actualResult;
TestLibrary.TestFramework.BeginScenario(testDesc);
try
{
void * ptr;
if(UIntPtr.Size == 4) //32-bit platform
{
ptr = (void *)TestLibrary.Generator.GetInt32(-55);
}
else //64-bit platform
{
ptr = (void *)TestLibrary.Generator.GetInt64(-55);
}
actualUIntPtr = new UIntPtr(ptr);
actualResult = actualUIntPtr.ToPointer() == ptr;
if (!actualResult)
{
errorDesc = "Actual UIntPtr value is not " + (UInt64)ptr + " as expected: Actual(" + actualUIntPtr + ")";
TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc);
retVal = false;
}
}
catch (Exception e)
{
errorDesc = "Unexpected exception: " + e;
TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc);
retVal = false;
}
return retVal;
}
示例2: TestBasics
public static unsafe void TestBasics()
{
UIntPtr p;
uint i;
ulong l;
if (sizeof(void*) == 4)
{
// Skip UIntPtr tests on 32-bit platforms
return;
}
int size = UIntPtr.Size;
Assert.Equal(size, sizeof(void*));
TestPointer(UIntPtr.Zero, 0);
i = 42;
TestPointer(new UIntPtr(i), i);
TestPointer((UIntPtr)i, i);
i = 42;
TestPointer(new UIntPtr(i), i);
l = 0x0fffffffffffffff;
TestPointer(new UIntPtr(l), l);
TestPointer((UIntPtr)l, l);
void* pv = new UIntPtr(42).ToPointer();
TestPointer(new UIntPtr(pv), 42);
TestPointer((UIntPtr)pv, 42);
p = UIntPtr.Add(new UIntPtr(42), 5);
TestPointer(p, 42 + 5);
// Add is spected NOT to generate an OverflowException
p = UIntPtr.Add(new UIntPtr(0xffffffffffffffff), 5);
unchecked
{
TestPointer(p, (long)0x0000000000000004);
}
p = UIntPtr.Subtract(new UIntPtr(42), 5);
TestPointer(p, 42 - 5);
bool b;
p = new UIntPtr(42);
b = p.Equals(null);
Assert.False(b);
b = p.Equals((object)42);
Assert.False(b);
b = p.Equals((object)(new UIntPtr(42)));
Assert.True(b);
int h = p.GetHashCode();
int h2 = p.GetHashCode();
Assert.Equal(h, h2);
p = new UIntPtr(42);
i = (uint)p;
Assert.Equal(i, 42u);
l = (ulong)p;
Assert.Equal(l, 42u);
UIntPtr p2;
p2 = (UIntPtr)i;
Assert.Equal(p, p2);
p2 = (UIntPtr)l;
Assert.Equal(p, p2);
p2 = (UIntPtr)(p.ToPointer());
Assert.Equal(p, p2);
p2 = new UIntPtr(40) + 2;
Assert.Equal(p, p2);
p2 = new UIntPtr(44) - 2;
Assert.Equal(p, p2);
p = new UIntPtr(0x7fffffffffffffff);
Assert.Throws<OverflowException>(() => (uint)p);
}
示例3: PosTest2
public bool PosTest2()
{
bool retVal = true;
const string c_TEST_ID = "P002";
const string c_TEST_DESC = "PosTest2: value is 0";
string errorDesc;
UIntPtr actualUIntPtr;
bool actualResult;
TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
try
{
void *ptr = (void *) 0;
actualUIntPtr = new UIntPtr(ptr);
actualResult = actualUIntPtr.ToPointer() == ptr;
if (!actualResult)
{
errorDesc = "Actual UIntPtr value is not " + (int)ptr + " as expected: Actual(" + actualUIntPtr + ")";
TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc);
retVal = false;
}
}
catch (Exception e)
{
errorDesc = "Unexpected exception: " + e;
TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc);
retVal = false;
}
return retVal;
}
示例4: PosTest3
public bool PosTest3()
{
bool retVal = true;
const string c_TEST_ID = "P002";
string testDesc = string.Format("PosTest1: value is max {0}-bit pointer: UInt{0}.MaxValue",
8 * UIntPtr.Size);
string errorDesc;
UIntPtr actualUIntPtr;
bool actualResult;
TestLibrary.TestFramework.BeginScenario(testDesc);
try
{
void* ptr;
if (UIntPtr.Size == 4)
{
ptr = (void*)UInt32.MaxValue;
}
else
{
ptr = (void *)UInt64.MaxValue;
}
actualUIntPtr = new UIntPtr(ptr);
actualResult = actualUIntPtr.ToPointer() == ptr;
if (!actualResult)
{
errorDesc = "Actual UIntPtr value is not " + (UInt64)ptr + " as expected: Actual(" + actualUIntPtr + ")";
TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc);
retVal = false;
}
}
catch (Exception e)
{
errorDesc = "Unexpected exception: " + e;
TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, errorDesc);
retVal = false;
}
return retVal;
}
示例5: runTest
public unsafe virtual bool runTest()
{
Console.Error.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
String strLoc = "Loc_000oo";
UIntPtr ip1;
void* vd1;
void* vd2;
int* iptr1;
Int32 iValue;
Int64 lValue;
Boolean fValue;
Char chValue;
Byte btValue;
SByte sbValue;
Int16 sValue;
UInt16 usValue;
UInt32 uiValue;
UInt64 ulValue;
DateTime dt1;
String strValue;
Int32[] iArr = {1, 2, 3, 4, 5};
MyEnum en1;
String strReturned;
try {
strLoc = "Loc_743wg";
iValue = 16;
vd1 = &iValue;
ip1 = new UIntPtr(vd1);
vd2 = ip1.ToPointer();
iCountTestcases++;
if((*((int*)vd2)) != iValue){
iCountErrors++;
Console.WriteLine("Err_2975sf! Wrong value returned, " + (*((int*)vd2)));
}
strLoc = "Loc_0084wf";
lValue = 16;
vd1 = &lValue;
ip1 = new UIntPtr(vd1);
vd2 = ip1.ToPointer();
iCountTestcases++;
if((*((long*)vd2)) != lValue){
iCountErrors++;
Console.WriteLine("Err_974325sdg! Wrong value returned");
}
strLoc = "Loc_0084wf";
lValue = 16;
vd1 = &lValue;
ip1 = new UIntPtr(vd1);
iptr1 = (int*)ip1.ToPointer();
iCountTestcases++;
if((*iptr1) != lValue){
iCountErrors++;
Console.WriteLine("Err_974325sdg! Wrong value returned! check the endiannees of this machine!!!, " + (*iptr1));
}
strLoc = "Loc_00845wsdg";
lValue = Int64.MaxValue;
vd1 = &lValue;
ip1 = new UIntPtr(vd1);
vd2 = ip1.ToPointer();
iCountTestcases++;
if((*((long*)vd2)) != lValue){
iCountErrors++;
Console.WriteLine("Err_94753sdg! Wrong value returned");
}
strLoc = "Loc_875esfg";
lValue = Int64.MaxValue;
vd1 = &lValue;
ip1 = new UIntPtr(vd1);
iptr1 = (int*)ip1.ToPointer();
iCountTestcases++;
if((*iptr1) != -1){
iCountErrors++;
Console.WriteLine("Err_756wrg! Wrong value returned! , " + (*iptr1));
}
strLoc = "Loc_008742sf";
fValue = true;
vd1 = &fValue;
ip1 = new UIntPtr(vd1);
iCountTestcases++;
if((*((Boolean*)ip1.ToPointer())) != fValue){
iCountErrors++;
Console.WriteLine("Err_984753sdg! Wrong value returned!");
}
strLoc = "Loc_735sdg";
chValue = 'a';
vd1 = &chValue;
ip1 = new UIntPtr(vd1);
iptr1 = (int*)ip1.ToPointer();
iCountTestcases++;
if((*((char*)ip1.ToPointer())) != chValue){
iCountErrors++;
Console.WriteLine("Err_9745sg! Wrong value returned!");
}
strLoc = "Loc_735sdg";
btValue = 5;
vd1 = &btValue;
ip1 = new UIntPtr(vd1);
iCountTestcases++;
//.........这里部分代码省略.........
示例6: PosTest2
public bool PosTest2()
{
bool retVal = true;
const string c_TEST_ID = "P002";
const string c_TEST_DESC = "PosTest2: UIntPtr with a random Int32 value ";
string errorDesc;
void *expectedPtr;
void *actualPtr;
UIntPtr uiPtr;
bool actualResult;
TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
try
{
UInt32 ui = (UInt32)TestLibrary.Generator.GetInt32(-55);
expectedPtr = (void *)ui;
uiPtr = new UIntPtr(ui);
actualPtr = uiPtr.ToPointer();
actualResult = actualPtr == expectedPtr;
if (!actualResult)
{
errorDesc = "Actual pointer value is not " + (UInt32)expectedPtr + " as expected: Actual(" + (UInt32)actualPtr + ")";
TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc);
retVal = false;
}
}
catch (Exception e)
{
errorDesc = "Unexpected exception: " + e;
TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, errorDesc);
retVal = false;
}
return retVal;
}