示例#1
0
    public static void showInt()
    {
        short  a = 0;
        ushort b = 0;
        int    c = 0;
        uint   d = 0;
        long   e = 0L;
        ulong  f = 0L;
        Int16  g = 0;
        Int32  h = 0;
        Int64  i = 0;
        UInt16 j = 0;
        UInt32 k = 0;
        UInt64 l = 0;

        Console.WriteLine(a.GetType());
        Console.WriteLine(b.GetType());
        Console.WriteLine(c.GetType());
        Console.WriteLine(d.GetType());
        Console.WriteLine(e.GetType());
        Console.WriteLine(f.GetType());
        Console.WriteLine(g.GetType());
        Console.WriteLine(h.GetType());
        Console.WriteLine(i.GetType());
        Console.WriteLine(j.GetType());
        Console.WriteLine(k.GetType());
        Console.WriteLine(l.GetType());
    }
示例#2
0
    public static void Main()
    {
        try
        {
// <Snippet1>
            UInt16 myVariable1 = 10;
            UInt16 myVariable2 = 10;

            //Display the declaring type.
            Console.WriteLine("\nType of 'myVariable1' is '{0}' and" +
                              " value is :{1}", myVariable1.GetType(), myVariable1);
            Console.WriteLine("Type of 'myVariable2' is '{0}' and" +
                              " value is :{1}", myVariable2.GetType(), myVariable2);

            // Compare 'myVariable1' instance with 'myVariable2' Object.
            if (myVariable1.Equals(myVariable2))
            {
                Console.WriteLine("\nStructures 'myVariable1' and " +
                                  "'myVariable2' are equal");
            }
            else
            {
                Console.WriteLine("\nStructures 'myVariable1' and " +
                                  "'myVariable2' are not equal");
            }

// </Snippet1>
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception :{0}", e.Message);
        }
    }
示例#3
0
 UInt16 compareUInt16(UInt16 b, UInt16 b2)
 {
     if (b == b2)
     {
         return(b);
     }
     throw new IllegalStateException("Not got expected value for type: " + b2.GetType().ToString());
 }
示例#4
0
 public void TestUint16()
 {
     Property myProperty = new Property(new Uri("ex:myProperty"));
     Resource r = new Resource(new Uri("ex:myResource"));
     UInt16 val = 126;
     r.AddProperty(myProperty, val);
     object res = r.ListValues(myProperty).First();
     Assert.AreEqual(val.GetType(), res.GetType());
     Assert.AreEqual(val, res);
     r.RemoveProperty(myProperty, val);
 }
示例#5
0
        //FileStream fsLog = new FileStream($"{DateTime.Now.ToString("yyyyMMdd")}.log", FileMode.OpenOrCreate);
        //StreamWriter swLog;
        ///// <summary>
        ///// 写文件
        ///// </summary>
        ///// <param name="xContent">内容</param>
        ///// <param name="xFilePath">路径</param>
        //public void WriteFile(string xContent)
        //{
        //    //lock (lockObject)
        //    //{
        //    logStringQueue.Enqueue(xContent);

        //    //swLog.WriteAsync(xContent);

        //    //}

        //}

        //private void writeLogAsync()
        //{
        //    Task.Factory.StartNew(() =>
        //    {
        //        StringBuilder sb = new StringBuilder();
        //        while (true)
        //        {
        //            try
        //            {

        //                while (logStringQueue.Any())
        //                {
        //                    logStringQueue.TryDequeue(out string log);
        //                    sb.Append(log);
        //                }

        //                swLog.WriteAsync(sb.ToString());
        //                sb.Clear();

        //            }
        //            catch (Exception ex)
        //            {
        //                //Logger.Error($"处理订阅信息异常! + \n {ex.ToString()}");
        //            }
        //            //Task.Delay(10);

        //            System.Threading.Thread.Sleep(1000);
        //        }
        //    });
        //}
        //ConcurrentQueue<string> logStringQueue = new ConcurrentQueue<string>();


        //FileStream fs = new FileStream("log.log", FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write);
        //StreamWriter swData;

        /// <summary>
        /// 初始化数据点
        /// </summary>
        private void initOpcUaDataItems()
        {
            StringBuilder sb = new StringBuilder();

            //#if DEBUG
            //            sb.Append("ns=2;s=TestChannel.TestDevice.Agv_TaskStatus;1000;False;True;Unknow");
            //            sb.AppendLine();
            //            sb.Append("Channel_1.Device_1.Tag_1;1000;0;0;Unknow");
            //            sb.AppendLine();
            //            sb.Append("Channel_1.Device_1.Tag_2;1000;0;0;Unknow");
            //            sb.AppendLine();
            //            sb.Append("Channel_1.Device_1.Tag_3;1000;0;0;Unknow");
            //            sb.AppendLine();
            //            sb.Append("Channel_1.Device_1.Tag_4;1000;0;0;Unknow");
            //            sb.AppendLine();
            //            sb.Append("Channel_1.Device_1.Tag_5;1000;0;0;Unknow");
            //            sb.AppendLine();
            //            sb.Append("Channel1.Device1.Tag1;1000;0;0;Unknow");
            //            sb.AppendLine();
            //            sb.Append("Channel1.Device1.Tag2;1000;0;0;Unknow");
            //            sb.AppendLine();
            //            sb.Append("S7:[S7 connection_52]DB800,X0.1;1000;0;0;Unknow");
            //            sb.AppendLine();
            //            sb.Append("S7 [S7_connection_52]DB800,X0.2;1000;0;0;Unknow");
            //            sb.AppendLine();
            //            //txtOpcDataItems.Text = sb.ToString();
            //#else
            //            txtOpcDataItems.Text = System.IO.File.ReadAllText("数据点.txt", Encoding.Default);
            //#endif
            type  = i.GetType();
            type2 = dateTime.GetType();

            //OpcUaDataItems.Add(new OpcUaDataItem($"{Opc.Ua.VariableIds.ServerStatusType_CurrentTime}", 1000, type2, i, i, OpcUaStatusCodes.Bad));
            //i=2259i=2258
            opcUaDataItems.Add(new OpcUaDataItem("ns=2;s=TestChannel.TestDevice.Agv_TaskStatus", 1000, typeof(UInt16), i, i, OpcUaStatusCodes.Bad));
            opcUaDataItems.Add(new OpcUaDataItem("ns=2;s=TestChannel.TestDevice.Agv_SettingSpeed", 1000, typeof(UInt16), i, i, OpcUaStatusCodes.Bad));
            opcUaDataItems.Add(new OpcUaDataItem("ns=2;s=数据类型示例.8 位设备.R 寄存器.Short1", 1000, typeof(UInt16), i, i, OpcUaStatusCodes.Bad));
            opcUaDataItems.Add(new OpcUaDataItem("ns=2;s=数据类型示例.8 位设备.R 寄存器.Short2", 1000, typeof(UInt16), i, i, OpcUaStatusCodes.Bad));

            //string path = @"C:\Users\PEPE\Desktop\证据接口结构.xml";
            //FileStream stream = new FileStream(path, FileMode.Open);
            //EvidenceFilesModel dep = (EvidenceFilesModel)XMLParser.Deserialize(typeof(EvidenceFilesModel), stream);
            //stream.Close();
            ////txtOpcDataItems.Text = System.IO.File.ReadAllText("数据点.txt", Encoding.Default);

            sb.Clear();
            sb = null;

            //WriteFile("数据点加载完成!");
        }
        public void TestUInt16()
        {
            FileStream       stream     = new FileStream("Prova.bin", System.IO.FileMode.Create);
            CompactFormatter CFormatter = new CompactFormatter();

            long start = DateTime.Now.Ticks;

            UInt16[] s = new UInt16[max];
            s[0] = 0;

            Console.WriteLine(
                "Serializing and Deserializing an array of type {1} composed by {0} elements",
                max, s.GetType().ToString()
                );

            for (int i = 1; i < max; i++)
            {
                //Console.WriteLine("Serialized {0}",s);
                s[i] = (ushort)((s[i - 1] + 1) % 32000);
            }
            CFormatter.Serialize(stream, s);
            stream.Flush();
            stream.Close();

            stream = new FileStream("Prova.bin", System.IO.FileMode.Open);
            CompactFormatter CFormatter2 = new CompactFormatter();

            UInt16[] temp = new UInt16[max];

            //for(int i = 0; i<max; i++)
            //{
            temp = (UInt16[])CFormatter2.Deserialize(stream);
            //}
            stream.Close();

            long stop = DateTime.Now.Ticks;
            long ts   = stop - start;

            Console.WriteLine("Elapsed Time:{0},{1},{2}", ts, start, stop);

            UInt16 s2 = 0;

            for (int i = 0; i < max; i++)
            {
                //Console.WriteLine("Deserialized {0}",temp[i]);
                Assert.AreEqual(temp[i], s2);
                s2 = (ushort)((s2 + 1) % 32000);
            }
        }
示例#7
0
        static void Main(string[] args)
        {
            sbyte sb1 = 3;
            SByte sb2 = 3;

            Console.WriteLine(sb1.GetType());
            Console.WriteLine(sb2.GetType());

            byte b1 = 3;
            Byte b2 = 3;

            Console.WriteLine(b1.GetType());
            Console.WriteLine(b2.GetType());

            short s1 = 3;
            Int16 s2 = 3;

            Console.WriteLine(s1.GetType());
            Console.WriteLine(s2.GetType());

            ushort us1 = 3;
            UInt16 us2 = 3;

            Console.WriteLine(us1.GetType());
            Console.WriteLine(us2.GetType());

            int   i1 = 3;
            Int32 i2 = 3;

            Console.WriteLine(i1.GetType());
            Console.WriteLine(i2.GetType());

            uint   ui1 = 3;
            UInt32 ui2 = 3;

            Console.WriteLine(ui1.GetType());
            Console.WriteLine(ui2.GetType());

            long  l1 = 3;
            Int64 l2 = 3;

            Console.WriteLine(l1.GetType());
            Console.WriteLine(l2.GetType());

            ulong  ul1 = 3;
            UInt64 ul2 = 3;

            Console.WriteLine(ul1.GetType());
            Console.WriteLine(ul2.GetType());

            float  f1 = 3.0f;
            Single f2 = 3.0f;

            Console.WriteLine(f1.GetType());
            Console.WriteLine(f2.GetType());

            double d1 = 3.0d;
            Double d2 = 3.0d;

            Console.WriteLine(d1.GetType());
            Console.WriteLine(d2.GetType());

            decimal dl1 = 3.0m;
            Decimal dl2 = 3.0m;

            Console.WriteLine(dl1.GetType());
            Console.WriteLine(dl2.GetType());

            char ch1 = 'A';
            Char ch2 = 'B';

            Console.WriteLine(ch1.GetType());
            Console.WriteLine(ch2.GetType());

            string st1 = "str";
            String st2 = "str";

            Console.WriteLine(st1.GetType());
            Console.WriteLine(st2.GetType());

            object o1 = 3;
            Object o2 = 3;

            Console.WriteLine(o1.GetType());
            Console.WriteLine(o2.GetType());
            Console.Read();
        }
示例#8
0
        static void Main(string[] args)
        {
            //числовые (целочисленные)
            byte bit1 = 1;
            Byte bit2 = 1;

            Console.WriteLine(bit1.GetType());
            Console.WriteLine(bit2.GetType());

            sbyte bit3 = 2;
            SByte bit4 = 2;

            Console.WriteLine(bit3.GetType());
            Console.WriteLine(bit4.GetType());

            short shot1 = 3;
            Int16 shot2 = 3;

            Console.WriteLine(shot1.GetType());
            Console.WriteLine(shot2.GetType());

            ushort shot3 = 4;
            UInt16 shot4 = 4;

            Console.WriteLine(shot3.GetType());
            Console.WriteLine(shot4.GetType());

            int   i1 = 5;
            Int32 i2 = 5;

            Console.WriteLine(i1.GetType());
            Console.WriteLine(i2.GetType());

            uint   i3 = 6;
            UInt32 i4 = 6;

            Console.WriteLine(i3.GetType());
            Console.WriteLine(i4.GetType());

            long   l1 = 7;
            UInt64 l2 = 7;

            Console.WriteLine(l1.GetType());
            Console.WriteLine(l2.GetType());

            ulong  l3 = 8;
            UInt64 l4 = 8;

            Console.WriteLine(l3.GetType());
            Console.WriteLine(l4.GetType());


            //числовые (c плавающей точкой)
            float  flt1 = 9f;
            Single flt2 = 9f;

            Console.WriteLine(flt1.GetType());
            Console.WriteLine(flt2.GetType());

            double d1 = 10d;
            Double d2 = 10d;

            Console.WriteLine(d1.GetType());
            Console.WriteLine(d2.GetType());

            decimal dcm1 = 11m;
            Decimal dcm2 = 11m;

            Console.WriteLine(dcm1.GetType());
            Console.WriteLine(dcm2.GetType());


            //Символьные типы
            char chr1 = 'a';
            Char chr2 = 'b';

            Console.WriteLine(chr1.GetType());
            Console.WriteLine(chr2.GetType());

            string str1 = "word";
            string str2 = "world";

            Console.WriteLine(str1.GetType());
            Console.WriteLine(str2.GetType());


            //Логический тип
            bool    bl1 = true;
            Boolean bl2 = false;

            Console.WriteLine(bl1.GetType());
            Console.WriteLine(bl2.GetType());


            //Особые типы
            object obj1 = i3;
            Object obj2 = str2;

            Console.WriteLine(obj1.GetType());
            Console.WriteLine(obj2.GetType());

            dynamic dnmc = "stringValue";

            Console.WriteLine(dnmc.GetType());


            Console.ReadKey();
        }
示例#9
0
        public void OpenTR2(string TR2fileName)
        {
            tr2Path   = TR2fileName;
            loadedTR2 = new TR2(tr2Path);

            // Adding header column
            DataGridViewTextBoxColumn headColumn = new DataGridViewTextBoxColumn();

            headColumn.ValueType = Type.GetType("System.Int32");
            headColumn.Name      = loadedTR2.fileName;
            dataTable.Columns.Add(headColumn);
            columnListBox.Items.Add(loadedTR2.fileName);

            // Adding dynamic columns
            for (int i = 0; i < loadedTR2.columnNum; i++)
            {
                DataGridViewTextBoxColumn currColumn = new DataGridViewTextBoxColumn();
                if (loadedTR2.columnsList[i].dataLenght == loadedTR2.columnsList[i].singleDataLenght)
                {
                    int    int8   = 0;
                    Int16  int16  = 0;
                    Int32  int32  = 0;
                    UInt16 uint16 = 0;

                    switch (loadedTR2.columnsList[i].dataType.ToLower())
                    {
                    case "int8":
                        currColumn.ValueType = int8.GetType();
                        break;

                    case "uint8":
                        currColumn.ValueType = int8.GetType();
                        break;

                    case "int16":
                        currColumn.ValueType = int16.GetType();
                        break;

                    case "uint16":
                        currColumn.ValueType = uint16.GetType();
                        break;

                    case "int32":
                        currColumn.ValueType = int32.GetType();
                        break;

                    case "utf-8":
                        currColumn.ValueType = "".GetType();
                        break;

                    case "ascii":
                        currColumn.ValueType = "".GetType();
                        break;

                    default:
                        currColumn.ValueType = Type.GetType(loadedTR2.columnsList[i].dataType);
                        break;
                    }
                }
                else
                {
                    currColumn.ValueType = "".GetType();
                }
                currColumn.Name = loadedTR2.columnsList[i].name;
                dataTable.Columns.Add(currColumn);

                columnListBox.Items.Add(currColumn.Name);
            }

            columnListBox.SelectedIndex = 0;

            // Adding Rows
            for (int i = 0; i < loadedTR2.rowNum; i++)
            {
                DataGridViewRow           row   = new DataGridViewRow();
                DataGridViewTextBoxCell[] cells = new DataGridViewTextBoxCell[loadedTR2.columnNum + 1];

                cells[0]       = new DataGridViewTextBoxCell();
                cells[0].Value = loadedTR2.rowHeaderValues[i];

                for (int j = 1; j <= loadedTR2.columnNum; j++)
                {
                    cells[j] = new DataGridViewTextBoxCell();
                    if (loadedTR2.columnsList[j - 1].dataLenght != loadedTR2.columnsList[j - 1].singleDataLenght)
                    {
                        int    doneTot    = 0;
                        string currValue  = "";
                        byte[] dataBuffer = (byte[])loadedTR2.columnsList[j - 1].data[i];
                        if (dataBuffer != null)
                        {
                            while (doneTot != dataBuffer.Length)
                            {
                                byte[] valueBuffer = new byte[loadedTR2.columnsList[j - 1].singleDataLenght];
                                Buffer.BlockCopy(dataBuffer, doneTot, valueBuffer, 0, valueBuffer.Length);
                                currValue += TR2Utils.ConvertNumber(valueBuffer);
                                doneTot   += valueBuffer.Length;

                                if (doneTot != dataBuffer.Length)
                                {
                                    currValue += " | ";
                                }
                            }
                        }
                        else
                        {
                            currValue = null;
                        }
                        cells[j].Value = currValue;
                    }
                    else
                    {
                        if (loadedTR2.columnsList[j - 1].dataLenght == -1)
                        {
                            string laStringa = (string)loadedTR2.columnsList[j - 1].data[i];
                            cells[j].Value = laStringa.Replace("\n", "\\n");
                        }
                        else
                        {
                            cells[j].Value = loadedTR2.columnsList[j - 1].data[i];
                        }
                    }
                }
                row.Cells.AddRange(cells);
                dataTable.Rows.Add(row);
            }
        }
示例#10
0
    public bool PosTest2(int id, String curValue, UInt16 expValue)
    {
        bool            retVal = true;
        UInt16          newValue;
        IFormatProvider myfp;

        TestLibrary.TestFramework.BeginScenario("PosTest" + id + ": Convert.ToUInt16(...) (curValue:string " + curValue + " newType:" + expValue.GetType() + ")");

        try
        {
            newValue = Convert.ToUInt16(curValue);

            if (!newValue.Equals(expValue))
            {
                TestLibrary.TestFramework.LogError("003", "Value mismatch: Expected(" + expValue + ") Actual(" + newValue + ")");
                retVal = false;
            }

            myfp     = null;
            newValue = Convert.ToUInt16(curValue, myfp);

            if (!newValue.Equals(expValue))
            {
                TestLibrary.TestFramework.LogError("004", "Value mismatch: Expected(" + expValue + ") Actual(" + newValue + ")");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("005", "Unexpected exception: " + e);
            retVal = false;
        }

        return(retVal);
    }
示例#11
0
        static void Main(string[] args)
        {
            int   int1 = 3;
            Int32 int2 = 4;

            Console.WriteLine(int1.GetType());
            Console.WriteLine(int2.GetType());
            Console.WriteLine();


            bool    bool1 = true;
            Boolean bool2 = false;

            Console.WriteLine(bool1.GetType());
            Console.WriteLine(bool2.GetType());
            Console.WriteLine();

            byte byte1 = 1;
            Byte byte2 = 2;

            Console.WriteLine(byte1.GetType());
            Console.WriteLine(byte2.GetType());
            Console.WriteLine();

            sbyte sbyte1 = 1;
            SByte sbyte2 = 2;

            Console.WriteLine(sbyte1.GetType());
            Console.WriteLine(sbyte2.GetType());
            Console.WriteLine();

            short short1 = 1;
            Int16 short2 = 2;

            Console.WriteLine(short1.GetType());
            Console.WriteLine(short2.GetType());
            Console.WriteLine();


            ushort ushort1 = 1;
            UInt16 ushort2 = 2;

            Console.WriteLine(ushort1.GetType());
            Console.WriteLine(ushort2.GetType());
            Console.WriteLine();

            uint   uint1 = 1;
            UInt32 uint2 = 2;

            Console.WriteLine(uint1.GetType());
            Console.WriteLine(uint2.GetType());
            Console.WriteLine();

            long  long1 = 1;
            Int64 long2 = 2;

            Console.WriteLine(long1.GetType());
            Console.WriteLine(long2.GetType());
            Console.WriteLine();

            ulong  ulong1 = 1;
            UInt64 ulong2 = 2;

            Console.WriteLine(ulong1.GetType());
            Console.WriteLine(ulong2.GetType());
            Console.WriteLine();

            float  float1 = 1.1f;
            Single float2 = 2.2f;

            Console.WriteLine(float1.GetType());
            Console.WriteLine(float2.GetType());
            Console.WriteLine();

            double double1 = 1.1;
            Double double2 = 2.2;

            Console.WriteLine(double1.GetType());
            Console.WriteLine(double2.GetType());
            Console.WriteLine();

            decimal decimal1 = 1.1m;
            Decimal decimal2 = 2.2m;

            Console.WriteLine(decimal1.GetType());
            Console.WriteLine(decimal2.GetType());
            Console.WriteLine();

            char char1 = 'a';
            Char char2 = 'b';

            Console.WriteLine(char1.GetType());
            Console.WriteLine(char2.GetType());
            Console.WriteLine();

            string string1 = "AAA";
            String string2 = "BBB";

            Console.WriteLine(string1.GetType());
            Console.WriteLine(string2.GetType());
            Console.WriteLine();

            object object1 = new object();
            Object object2 = new Object();

            Console.WriteLine(object1.GetType());
            Console.WriteLine(object2.GetType());
            Console.WriteLine();

            //explicit type conversion
            int1  = 42;
            long1 = int1; // conversion int to long

            short1 = 3;
            float1 = short1; //conversion shot to float

            string1 = "Test";
            object1 = string1; //conversion string to object


            //implicit type conversion

            int2 = (int)long1;         // conversion long to int

            short2 = (short)float1;    //conversion float to short

            string2 = (string)object1; //conversion object to string

            decimal1 = 23.123m;
            object2  = decimal1;         //boxing
            decimal2 = (decimal)object2; //unboxing


            Console.ReadKey();
        }
示例#12
0
        static void Main(string[] args)
        {
            sbyte a1 = -10;
            SByte a2 = -11;

            Console.WriteLine(a1.GetType());
            Console.WriteLine(a2.GetType());

            short b1 = -500;
            Int16 b2 = -400;

            Console.WriteLine(b1.GetType());
            Console.WriteLine(b2.GetType());

            int   c1 = 123;
            Int32 c2 = -123;

            Console.WriteLine(c1.GetType());
            Console.WriteLine(c2.GetType());

            long  d1 = -100000;
            Int64 d2 = 110000;

            Console.WriteLine(d1.GetType());
            Console.WriteLine(d2.GetType());

            byte e1 = 99;
            Byte e2 = 98;

            Console.WriteLine(e1.GetType());
            Console.WriteLine(e2.GetType());

            ushort f1 = 655;
            UInt16 f2 = 666;

            Console.WriteLine(f1.GetType());
            Console.WriteLine(f2.GetType());

            char g1 = 'c';
            Char g2 = '!';

            Console.WriteLine(g1.GetType());
            Console.WriteLine(g2.GetType());

            uint   h1 = 333;
            UInt32 h2 = 334;

            Console.WriteLine(h1.GetType());
            Console.WriteLine(h2.GetType());

            ulong  i1 = 12321;
            UInt64 i2 = 123321;

            Console.WriteLine(i1.GetType());
            Console.WriteLine(i2.GetType());

            float  k1 = 2.2f;
            Single k2 = 45.05f;

            Console.WriteLine(k1.GetType());
            Console.WriteLine(k2.GetType());

            double l1 = 8.098;
            Double l2 = 8.98;

            Console.WriteLine(l1.GetType());
            Console.WriteLine(l2.GetType());

            decimal m1 = 1.2E3m;
            Decimal m2 = 1.3E2m;

            Console.WriteLine(m1.GetType());
            Console.WriteLine(m2.GetType());

            object obj1 = 9;
            Object obj2 = true;

            Console.WriteLine(obj1.GetType());
            Console.WriteLine(obj2.GetType());

            string str1 = "valar morghulis";
            String str2 = "valar dohaeris";

            Console.WriteLine(str1.GetType());
            Console.WriteLine(str2.GetType());
        }
示例#13
0
 public static string DebugString(this UInt16 v)
 {
     return(v.ToString().PadLeft(columnWidth) + " " + v.ToString("X4").PadRight(columnWidth) + v.GetType().Name);
 }
示例#14
0
        static void Main(string[] args)
        {
            bool    a1   = true;
            Boolean a2   = true;
            byte    b1   = 1;
            Byte    b2   = 2;
            char    c1   = '%';
            Char    c2   = '&';
            decimal d1   = 10;
            Decimal d2   = 10;
            sbyte   sb1  = 1;
            SByte   sb2  = -15;
            float   fl1  = 4.5f;
            Single  fl2  = 4.6f;
            double  db1  = 55.55;
            Double  db2  = 55.66;
            short   sh1  = 1;
            Int16   sh2  = 1;
            ushort  ush1 = 10;
            UInt16  ush2 = 10;
            int     i1   = 5;
            Int32   i2   = 5;
            uint    ui1  = 5000;
            UInt32  ui2  = 5000;
            long    l1   = 155;
            Int64   l2   = 156;
            ulong   ul1  = 500;
            UInt64  ul2  = 501;
            object  ob1  = 500;
            Object  ob2  = 500;
            string  str1 = "stroka";
            String  str2 = "stroka2";

            Console.WriteLine("Variable type: " + a1.GetType());
            Console.WriteLine("Variable type: " + a2.GetType());
            Console.WriteLine("Variable type: " + b1.GetType());
            Console.WriteLine("Variable type: " + b2.GetType());
            Console.WriteLine("Variable type: " + c1.GetType());
            Console.WriteLine("Variable type: " + c2.GetType());
            Console.WriteLine("Variable type: " + d1.GetType());
            Console.WriteLine("Variable type: " + d2.GetType());
            Console.WriteLine("Variable type: " + sb1.GetType());
            Console.WriteLine("Variable type: " + sb2.GetType());
            Console.WriteLine("Variable type: " + fl1.GetType());
            Console.WriteLine("Variable type: " + fl2.GetType());
            Console.WriteLine("Variable type: " + db1.GetType());
            Console.WriteLine("Variable type: " + db2.GetType());
            Console.WriteLine("Variable type: " + sh1.GetType());
            Console.WriteLine("Variable type: " + sh2.GetType());
            Console.WriteLine("Variable type: " + ush1.GetType());
            Console.WriteLine("Variable type: " + ush2.GetType());
            Console.WriteLine("Variable type: " + i1.GetType());
            Console.WriteLine("Variable type: " + i2.GetType());
            Console.WriteLine("Variable type: " + ui1.GetType());
            Console.WriteLine("Variable type: " + ui2.GetType());
            Console.WriteLine("Variable type: " + l1.GetType());
            Console.WriteLine("Variable type: " + l2.GetType());
            Console.WriteLine("Variable type: " + ul1.GetType());
            Console.WriteLine("Variable type: " + ul2.GetType());
            Console.WriteLine("Variable type: " + ob1.GetType());
            Console.WriteLine("Variable type: " + ob2.GetType());
            Console.WriteLine("Variable type: " + str1.GetType());
            Console.WriteLine("Variable type: " + str2.GetType());
            Console.ReadKey();
        }
示例#15
0
        public void TestIsPrimitiveMethod_UInt16()
        {
            UInt16 value = 1;

            TypeUtil.IsPrimitive(value.GetType()).IsTrue();
        }
示例#16
0
        static void Main(string[] args)
        {
            sbyte example1 = 1;

            Console.WriteLine(example1.GetType());
            SByte example2 = 1;

            Console.WriteLine(example2.GetType());

            short example3 = 1;

            Console.WriteLine(example3.GetType());
            Int16 example4 = 1;

            Console.WriteLine(example4.GetType());

            int example5 = 1;

            Console.WriteLine(example5.GetType());
            Int32 example6 = 1;

            Console.WriteLine(example6.GetType());

            long example7 = 1;

            Console.WriteLine(example7.GetType());
            Int64 example8 = 1;

            Console.WriteLine(example8.GetType());

            byte example9 = 1;

            Console.WriteLine(example9.GetType());
            Byte example10 = 1;

            Console.WriteLine(example10.GetType());

            ushort example11 = 1;

            Console.WriteLine(example11.GetType());
            UInt16 example12 = 1;

            Console.WriteLine(example12.GetType());

            char example13 = '1';

            Console.WriteLine(example13.GetType());
            Char example14 = '1';

            Console.WriteLine(example14.GetType());

            uint example15 = 1;

            Console.WriteLine(example15.GetType());
            UInt32 example16 = 1;

            Console.WriteLine(example16.GetType());

            ulong example17 = 1;

            Console.WriteLine(example17.GetType());
            UInt64 example18 = 1;

            Console.WriteLine(example18.GetType());

            float example19 = 1;

            Console.WriteLine(example19.GetType());
            Single example20 = 1;

            Console.WriteLine(example20.GetType());

            double example21 = 1;

            Console.WriteLine(example21.GetType());
            Double example22 = 1;

            Console.WriteLine(example22.GetType());

            decimal example23 = 1;

            Console.WriteLine(example23.GetType());
            Decimal example24 = 1;

            Console.WriteLine(example24.GetType());
        }
示例#17
0
 public void Convert_PrimitiveDatatypeToString_Test()
 {
     {
         Boolean t1  = true;
         var     SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null));
         SPV.PropertyValue = t1;
         SPV.SerializedValue.Should().Be("True");
     }
     {
         Byte t1  = 5;
         var  SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null));
         SPV.PropertyValue = t1;
         SPV.SerializedValue.Should().Be("5");
     }
     {
         SByte t1  = 5;
         var   SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null));
         SPV.PropertyValue = t1;
         SPV.SerializedValue.Should().Be("5");
     }
     {
         Int16 t1  = 5;
         var   SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null));
         SPV.PropertyValue = t1;
         SPV.SerializedValue.Should().Be("5");
     }
     {
         UInt16 t1  = 5;
         var    SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null));
         SPV.PropertyValue = t1;
         SPV.SerializedValue.Should().Be("5");
     }
     {
         Int32 t1  = 5;
         var   SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null));
         SPV.PropertyValue = t1;
         SPV.SerializedValue.Should().Be("5");
     }
     {
         UInt32 t1  = 5;
         var    SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null));
         SPV.PropertyValue = t1;
         SPV.SerializedValue.Should().Be("5");
     }
     {
         Int64 t1  = 5;
         var   SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null));
         SPV.PropertyValue = t1;
         SPV.SerializedValue.Should().Be("5");
     }
     {
         UInt64 t1  = 5;
         var    SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null));
         SPV.PropertyValue = t1;
         SPV.SerializedValue.Should().Be("5");
     }
     {
         Char t1  = '5';
         var  SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null));
         SPV.PropertyValue = t1;
         SPV.SerializedValue.Should().Be("5");
     }
     {
         Double t1  = 1.79;
         var    SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null));
         SPV.PropertyValue = t1;
         SPV.SerializedValue.Should().Be("1.79");
     }
     {
         Single t1  = 1.79f;
         var    SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null));
         SPV.PropertyValue = t1;
         SPV.SerializedValue.Should().Be("1.79");
     }
     {
         Decimal t1  = 1.79M;
         var     SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null));
         SPV.PropertyValue = t1;
         SPV.SerializedValue.Should().Be("1.79");
     }
     {
         string t1  = null;
         var    SPV = new SettingsPropertyValue(new SettingsProperty("whatever", typeof(string), null));
         SPV.PropertyValue = t1;
         SPV.SerializedValue.Should().BeNull();
     }
     {
         string t1  = "";
         var    SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null));
         SPV.PropertyValue = t1;
         SPV.SerializedValue.Should().Be("");
     }
     {
         string t1  = "foo";
         var    SPV = new SettingsPropertyValue(new SettingsProperty("whatever", t1.GetType(), null));
         SPV.PropertyValue = t1;
         SPV.SerializedValue.Should().Be("foo");
     }
 }
示例#18
0
        public static Type ToType(CIMType cimtype,
                                  bool bIsArray,
                                  Property prop)
        {
            Type t = null;

            switch (cimtype)
            {
            case (CIMType.Boolean):
            {
                if (bIsArray)
                {
                    Boolean[] ar = new Boolean[0];
                    t = ar.GetType();
                }
                else
                {
                    t = typeof(Boolean);
                }
            } break;

            case (CIMType.Char16):
            {
                if (bIsArray)
                {
                    Char[] ar = new Char[0];
                    t = ar.GetType();
                }
                else
                {
                    t = typeof(Char);
                }
            } break;

            case (CIMType.DateTime):
            {
                if (WmiHelper.IsInterval(prop))
                {
                    if (bIsArray)
                    {
                        TimeSpan[] ar = new TimeSpan[0];
                        t = ar.GetType();
                    }
                    else
                    {
                        t = typeof(TimeSpan);
                    }
                }
                else
                {
                    if (bIsArray)
                    {
                        DateTime[] ar = new DateTime[0];
                        t = ar.GetType();
                    }
                    else
                    {
                        t = typeof(DateTime);
                    }
                }
            } break;

            case (CIMType.Object):
            {
                if (bIsArray)
                {
                    WMIObjectComponent[] ar = new WMIObjectComponent[0];
                    t = ar.GetType();
                }
                else
                {
                    t = typeof(WMIObjectComponent);
                }
            } break;

            case (CIMType.Real32):
            {
                if (bIsArray)
                {
                    Single[] ar = new Single[0];
                    t = ar.GetType();
                }
                else
                {
                    t = typeof(Single);
                }
            } break;

            case (CIMType.Real64):
            {
                if (bIsArray)
                {
                    Double[] ar = new Double[0];
                    t = ar.GetType();
                }
                else
                {
                    t = typeof(Double);
                }
            } break;

            case (CIMType.Reference):
            {
                if (bIsArray)
                {
                    String[] ar = new String[0];
                    t = ar.GetType();
                }
                else
                {
                    t = typeof(String);
                }
            } break;

            case (CIMType.Sint16):
            {
                if (bIsArray)
                {
                    Int16[] ar = new Int16[0];
                    t = ar.GetType();
                }
                else
                {
                    t = typeof(Int16);
                }
            } break;

            case (CIMType.Sint32):
            {
                if (bIsArray)
                {
                    Int32[] ar = new Int32[0];
                    t = ar.GetType();
                }
                else
                {
                    t = typeof(Int32);
                }
            } break;

            case (CIMType.Sint64):
            {
                if (bIsArray)
                {
                    Int64[] ar = new Int64[0];
                    t = ar.GetType();
                }
                else
                {
                    t = typeof(Int64);
                }
            } break;

            case (CIMType.Sint8):
            {
                if (bIsArray)
                {
                    SByte[] ar = new SByte[0];
                    t = ar.GetType();
                }
                else
                {
                    t = typeof(SByte);
                }
            } break;

            case (CIMType.String):
            {
                if (bIsArray)
                {
                    String[] ar = new String[0];
                    t = ar.GetType();
                    //return typeof(System.Collections.ArrayList);
                }
                else
                {
                    t = typeof(String);
                }
            } break;

            case (CIMType.Uint16):
            {
                if (bIsArray)
                {
                    UInt16[] ar = new UInt16[0];
                    t = ar.GetType();
                }
                else
                {
                    t = typeof(UInt16);
                }
            } break;

            case (CIMType.Uint32):
            {
                if (bIsArray)
                {
                    UInt32[] ar = new UInt32[0];
                    t = ar.GetType();
                }
                else
                {
                    t = typeof(UInt32);
                }
            } break;

            case (CIMType.Uint64):
            {
                if (bIsArray)
                {
                    UInt64[] ar = new UInt64[0];
                    t = ar.GetType();
                }
                else
                {
                    t = typeof(UInt64);
                }
            } break;

            case (CIMType.Uint8):
            {
                if (bIsArray)
                {
                    Byte[] ar = new Byte[0];
                    t = ar.GetType();
                }
                else
                {
                    t = typeof(Byte);
                }
            } break;

            default:
            {
                if (bIsArray)
                {
                    Object[] ar = new Object[0];
                    t = ar.GetType();
                }
                else
                {
                    t = typeof(Object);
                }
            }
            }

            return(t);
        }