Esempio n. 1
0
        public void TypeTest()
        {
            AreEqual(TypeHelper.CanBeGenericParameter(typeof(TypedReference)), false);
            AreEqual(TypeHelper.CanBeGenericParameter(typeof(void *)), false);
            AreEqual(TypeHelper.CanBeGenericParameter(typeof(int).MakeByRefType()), false);
            AreEqual(TypeHelper.CanBeGenericParameter(typeof(TypeHelper)), false);
            AreEqual(TypeHelper.CanBeGenericParameter(typeof(int)), true);
            AreEqual(TypeHelper.CanBeGenericParameter(typeof(Tester_Struct)), true);
            AreEqual(TypeHelper.CanBeGenericParameter(typeof(Tester)), true);
            AreEqual(TypeHelper.CanBeGenericParameter(typeof(IntPtr)), true);

            AreEqual(VersionDifferences.IsByRefLike(typeof(TypedReference)), true);
            AreEqual(VersionDifferences.IsByRefLike(typeof(int)), false);
            AreEqual(VersionDifferences.IsByRefLike(typeof(IntPtr)), false);
            AreEqual(VersionDifferences.IsByRefLike(typeof(void *)), false);
            AreEqual(VersionDifferences.IsByRefLike(typeof(int).MakeByRefType()), false);

            AreEqual(TypeHelper.GetDefaultValue(typeof(IntPtr)), default(IntPtr));
            AreEqual(TypeHelper.GetDefaultValue(typeof(string)), default(string));
            AreEqual(TypeHelper.GetDefaultValue(typeof(string)), default(string));
            AreEqual(TypeHelper.GetDefaultValue(typeof(int)), default(int));
            AreEqual(TypeHelper.GetDefaultValue(typeof(Tester_Struct)), default(Tester_Struct));

            AreEqual(TypeHelper.IsEmptyValue(default(IntPtr)), true);
            AreEqual(TypeHelper.IsEmptyValue(default(Tester_Struct)), true);
            AreEqual(TypeHelper.IsEmptyValue(default(string)), true);
            AreEqual(TypeHelper.IsEmptyValue(""), false);
            AreEqual(TypeHelper.IsEmptyValue(Guid.NewGuid()), false);

            AreEqual(TypeHelper.IsEmptyValue((object)default(IntPtr)), true);
            AreEqual(TypeHelper.IsEmptyValue((object)default(Tester_Struct)), true);
            AreEqual(TypeHelper.IsEmptyValue((object)default(string)), true);
            AreEqual(TypeHelper.IsEmptyValue((object)""), false);
            AreEqual(TypeHelper.IsEmptyValue((object)Guid.NewGuid()), false);

            AreEqual(TypeHelper.IsAutoProperty(typeof(Tester).GetProperty(nameof(Tester.auto_property)), out var fieldInfo), true);
            IsNotNull(fieldInfo);
            AreEqual(TypeHelper.IsAutoProperty(typeof(Tester).GetProperty(nameof(Tester.non_auto_property)), out var _), false);

            AreEqual(TypeHelper.IsAutoProperty(typeof(Tester_Struct).GetProperty(nameof(Tester_Struct.auto_property)), out fieldInfo), true);
            IsNotNull(fieldInfo);
            AreEqual(TypeHelper.IsAutoProperty(typeof(Tester_Struct).GetProperty(nameof(Tester_Struct.non_auto_property)), out var _), false);
        }