当前位置: 首页>>代码示例>>C#>>正文


C# DateTime.GetType方法代码示例

本文整理汇总了C#中System.DateTime.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.GetType方法的具体用法?C# DateTime.GetType怎么用?C# DateTime.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.DateTime的用法示例。


在下文中一共展示了DateTime.GetType方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DateTime_ConstructorTest1

        public MFTestResults DateTime_ConstructorTest1()
        {
            /// <summary>
            ///  1. Creates a DateTime
            ///  2. Verifies that the created object is a DateTime
            /// </summary>

            MFTestResults testResult = MFTestResults.Pass;
            try
            {
                Log.Comment("Creating new DateTime Object");
                DateTime dt = new DateTime();
                Log.Comment(dt.ToString());
                Type type = dt.GetType();
                Log.Comment("Verifying its type");
                if (!(type == Type.GetType("System.DateTime")))
                {
                    Log.Comment("Expected Type 'System.DateTime' but got '" + type.ToString());
                    testResult = MFTestResults.Fail;
                }
            }
            catch (Exception ex)
            {
                Log.Comment("Caught Unexpected Exception : " + ex.Message);
                return MFTestResults.Fail;
            }

            return testResult;
        }
开发者ID:samunake,项目名称:netmf-interpreter,代码行数:29,代码来源:SystemDateTimeTests.cs

示例2: DateTimeIsSerializedCorrect

        public void DateTimeIsSerializedCorrect()
        {
            var elementValue = new DateTime(2001, 12, 31, 22, 45, 30);

            var xDoc = Serialize(elementValue);

            if (xDoc.Root == null) Assert.Fail("Document should not be null");
            Assert.That(xDoc.Root.Name.LocalName, Is.EqualTo(elementValue.GetType().Name));
            Assert.That(xDoc.Descendants("DateTime").First().Value, Is.EqualTo(elementValue.ToString(CultureInfo.InvariantCulture)));
        }
开发者ID:Zapote,项目名称:EzBus,代码行数:10,代码来源:XmlSerializationTest.cs

示例3: IsValid

 public override bool IsValid(object value, object container)
 {
     object dependentValue = GetDependentValue(container);
     if (value != null && dependentValue != null) {
         try {
             DateTime date = new DateTime();
             if (DateTime.TryParse(value.ToString(), out date)) {
                 value = Convert.ChangeType(value, date.GetType());
             }
             if (DateTime.TryParse(dependentValue.ToString(), out date)) {
                 dependentValue = Convert.ChangeType(dependentValue, date.GetType());
             }
             else
                 dependentValue = Convert.ChangeType(dependentValue, value.GetType());
         }
         catch (Exception) {
             throw new InvalidOperationException("EzValidation: Specific value must be same type, or a type that is able to be cast to the type of property being validated!");
         }
     }
     return IsValid(value, dependentValue, container);
 }
开发者ID:kburnell,项目名称:EZValidation,代码行数:21,代码来源:EzValidationDependentAttributeBase.cs

示例4: Main

        public static void Main()
        {
            DateTime dateTime = new DateTime();

            Type type = dateTime.GetType();
            foreach(
                System.Reflection.PropertyInfo property in
                    type.GetProperties())
            {
                Console.WriteLine(property.Name);
            }
        }
开发者ID:andrewdwalker,项目名称:EssentialCSharp,代码行数:12,代码来源:Listing17.01.UsingTypeGetPropertiesToObtainAnObjectsPublicProperties.cs

示例5: MarshalCOMVariant

        private static void MarshalCOMVariant()
        {
            MarshalCOMDataTypeClass comObj = new MarshalCOMDataTypeClass();

            object outArg = null;
            string description = string.Empty;

            uint uintArg = 10;
            description = comObj.MarshalCOMVariant(uintArg, out outArg);
            Console.WriteLine("VARIANT - uint: {0}, {1}, {2}",
                uintArg.GetType().Name, outArg.GetType().Name, description);

            double doubleArg = 10.0;
            description = comObj.MarshalCOMVariant(doubleArg, out outArg);
            Console.WriteLine("VARIANT - double: {0}, {1}, {2}",
                doubleArg.GetType().Name, outArg.GetType().Name, description);

            string stringArg = "�ַ���";
            description = comObj.MarshalCOMVariant(stringArg, out outArg);
            Console.WriteLine("VARIANT - string: {0}, {1}, {2}",
                stringArg.GetType().Name, outArg.GetType().Name, description);

            decimal decimalArg = 10.20m;
            description = comObj.MarshalCOMVariant(decimalArg, out outArg);
            Console.WriteLine("VARIANT - decimal: {0}, {1}, {2}",
                decimalArg.GetType().Name, outArg.GetType().Name, description);

            CurrencyWrapper currencyArg = new CurrencyWrapper(10.20m);
            description = comObj.MarshalCOMVariant(currencyArg, out outArg);
            Console.WriteLine("VARIANT - currency: {0}, {1}, {2}",
                currencyArg.GetType().Name, outArg.GetType().Name, description);

            DateTime dateArg = new DateTime(2008, 8, 8);
            description = comObj.MarshalCOMVariant(dateArg, out outArg);
            Console.WriteLine("VARIANT - date: {0}, {1}, {2}",
                dateArg.GetType().Name, outArg.GetType().Name, description);

            object objectArg = new object();
            description = comObj.MarshalCOMVariant(objectArg, out outArg);
            Console.WriteLine("VARIANT - object: {0}, {1}, {2}",
                objectArg.GetType().Name, outArg.GetType().Name, description);

            object nullArg = null;
            description = comObj.MarshalCOMVariant(nullArg, out outArg);
            Console.WriteLine("VARIANT - null: {0}, {1}, {2}",
                "null", outArg == null ? "null" : outArg.GetType().Name, description);

            IntPtr intptrArg = IntPtr.Zero;
            description = comObj.MarshalCOMVariant(intptrArg, out outArg);
            Console.WriteLine("VARIANT - IntPtr: {0}, {1}, {2}",
                intptrArg.GetType().Name, outArg.GetType().Name, description);
        }
开发者ID:zhaohengyi,项目名称:dotNet_PInvoke,代码行数:52,代码来源:Program.cs

示例6: Test

        public void Test()
        {
            byte a = 1;
            short b = 1;
            int c = -1;
            long d = 1;
            ushort e = 1;
            uint f = 1;
            ulong g = 1;
            float h = 1.1f;
            double i = 1.222;
            bool j = true;
            char k = 'a';
            string l = "aaa";
            DateTime m = new DateTime(2015,1,1,1,1,1);

            var encoder = new BasicType();
            Assert.IsTrue(BasicType.IsBasicType(a.GetType()));
            Assert.AreEqual(a, encoder.DeSerialize<byte>(encoder.Serialize(a)));
            Assert.IsTrue(BasicType.IsBasicType(b.GetType()));
            Assert.AreEqual(b, encoder.DeSerialize<short>(encoder.Serialize(b)));
            Assert.IsTrue(BasicType.IsBasicType(c.GetType()));
            Assert.AreEqual(c, encoder.DeSerialize<int>(encoder.Serialize(c)));
            Assert.IsTrue(BasicType.IsBasicType(d.GetType()));
            Assert.AreEqual(d, encoder.DeSerialize<long>(encoder.Serialize(d)));
            Assert.IsTrue(BasicType.IsBasicType(e.GetType()));
            Assert.AreEqual(e, encoder.DeSerialize<ushort>(encoder.Serialize(e)));
            Assert.IsTrue(BasicType.IsBasicType(f.GetType()));
            Assert.AreEqual(f, encoder.DeSerialize<uint>(encoder.Serialize(f)));
            Assert.IsTrue(BasicType.IsBasicType(g.GetType()));
            Assert.AreEqual(g, encoder.DeSerialize<ulong>(encoder.Serialize(g)));
            Assert.IsTrue(BasicType.IsBasicType(h.GetType()));
            Assert.AreEqual(h, encoder.DeSerialize<float>(encoder.Serialize(h)));
            Assert.IsTrue(BasicType.IsBasicType(i.GetType()));
            Assert.AreEqual(i, encoder.DeSerialize<double>(encoder.Serialize(i)));
            Assert.IsTrue(BasicType.IsBasicType(j.GetType()));
            Assert.AreEqual(j, encoder.DeSerialize<bool>(encoder.Serialize(j)));
            Assert.IsTrue(BasicType.IsBasicType(k.GetType()));
            Assert.AreEqual(k, encoder.DeSerialize<char>(encoder.Serialize(k)));
            Assert.IsTrue(BasicType.IsBasicType(l.GetType()));
            Assert.AreEqual(l, encoder.DeSerialize<string>(encoder.Serialize(l)));
            Assert.IsTrue(BasicType.IsBasicType(m.GetType()));
            Assert.AreEqual(m, encoder.DeSerialize<DateTime>(encoder.Serialize(m)));
            Assert.IsFalse(BasicType.IsBasicType(typeof(object)));
            Assert.Throws(typeof(ArgumentException), () => encoder.Serialize(new List<int>()));
        }
开发者ID:zesus19,项目名称:c5.v1,代码行数:46,代码来源:BasicTypeTest.cs

示例7: Should_test_nullable_non_numeric_types_gettype

        public void Should_test_nullable_non_numeric_types_gettype()
        {
            bool? nullableBool = true;
            Assert.False(nullableBool.GetType().IsNumeric());

            char? nullableChar = ' ';
            Assert.False(nullableChar.GetType().IsNumeric());
            
            DateTime? nullableDateTime = new DateTime(2009, 1, 1);
            Assert.False(nullableDateTime.GetType().IsNumeric());
        }
开发者ID:JulianRooze,项目名称:Nancy,代码行数:11,代码来源:TypeExtensionsFixture.cs

示例8: EvalDateTimeOperator

 private bool EvalDateTimeOperator(TokenId op, DateTime lValue, DateTime rValue)
 {
     switch (op)
     {
         case TokenId.EqualEqual:
             {
                 return lValue == rValue;
             }
         case TokenId.Less:
             {
                 return lValue < rValue;
             }
         case TokenId.LessEqual:
             {
                 return lValue <= rValue;
             }
         case TokenId.Greater:
             {
                 return lValue > rValue;
             }
         case TokenId.GreaterEqual:
             {
                 return lValue >= rValue;
             }
         case TokenId.NotEqual:
             {
                 return lValue != rValue;
             }
         default:
             {
                 throw new ParseException("BinaryNotSupport '{0}' between type of '{1}' and '{2}'", op.ToString(), lValue.GetType().Name, rValue.GetType().Name);
             }
     }
 }
开发者ID:yslib,项目名称:minimvc,代码行数:34,代码来源:BinaryExpression.cs

示例9: MarshalDate

 public void MarshalDate(DateTime value)
 {
     Console.WriteLine(".NET�е����ͣ�{0}, ֵΪ��{1}", value.GetType().Name, value);
 }
开发者ID:zhaohengyi,项目名称:dotNet_PInvoke,代码行数:4,代码来源:MarshalCommonType.cs

示例10: SyncGold

        public void SyncGold(DateTime date)
        {
            XmlSerializer dateSerializer = new XmlSerializer(date.GetType());
            var serializer = new XmlSerializer(typeof(IdCardError));

            var memoryStream = new MemoryStream();
            var streamWriter = new StreamWriter(memoryStream, System.Text.Encoding.UTF8);

            dateSerializer.Serialize(streamWriter, date);

            byte[] utf8EncodedXml = memoryStream.ToArray();

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(String.Concat(URI.RESTurl(), "SyncGold"));
            request.Method = "POST";
            request.ContentType = "application/xml";
            request.ContentLength = utf8EncodedXml.Length;
            this.authenticationProvider.AuthenticatePostRequest(request, null); //serializedValue);
            request.Accept = "application/xml";

            Stream dataStream = request.GetRequestStream();
            dataStream.Write(utf8EncodedXml, 0, utf8EncodedXml.Length);
            dataStream.Close();

            HttpWebResponse response = null;

            IdCardError status = null;

            try
            {
                using (response = (HttpWebResponse)request.GetResponse())
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        Stream ReceiveStream = response.GetResponseStream();
                        StreamReader readStream = new StreamReader(ReceiveStream);
                        string xml = readStream.ReadToEnd();

                        status = (IdCardError)serializer.Deserialize(new StringReader(xml));
                    }
                }
            }
            catch (WebException webEx)
            {
                if (response == null)
                {
                    System.Diagnostics.Debug.WriteLine(webEx.Message);
                }
            }

            if (status.Errors == null)
            {
                MessageBox.Show("There are no cards from " + date.ToShortDateString() + " to synchronize.", "Nothing to Sync", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                string message = "";
                foreach (Errors error in status.Errors)
                {
                    message += error.Error;
                    message += "\n";
                }
                MessageBox.Show(message, "Synchronize From " + date.ToShortDateString() + " Complete", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
开发者ID:byu-oit-appdev,项目名称:IdCard,代码行数:64,代码来源:IdCardClientImpl.cs


注:本文中的System.DateTime.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。