public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if ((destinationType == typeof(InstanceDescriptor)) && (value is UnicodeType))
            {
                ConstructorInfo ci = typeof(UnicodeType).GetConstructor(
                    new [] {
                    typeof(int),
                    typeof(string)
                });
                if (ci != null)
                {
                    UnicodeType c = ((UnicodeType)value);
                    return(new InstanceDescriptor(
                               ci,
                               new object[] {
                        c.Id,
                        c.Name
                    }
                               ));
                }
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
Пример #2
0
        public void Marshaling()
        {
            var uni = new UnicodeType();

            // マーシャル情報があればutf16で扱える
            Assert.AreEqual(38, Marshal.SizeOf(typeof(UnicodeType)));
            Assert.AreEqual(38, Marshal.SizeOf(uni));
            Assert.AreEqual(1, Marshal.SizeOf(s8));
            Assert.AreEqual(2, Marshal.SizeOf(s16));
            Assert.AreEqual(4, Marshal.SizeOf(s32));
            Assert.AreEqual(8, Marshal.SizeOf(s64));
            Assert.AreEqual(1, Marshal.SizeOf(u8));
            Assert.AreEqual(2, Marshal.SizeOf(u16));
            Assert.AreEqual(4, Marshal.SizeOf(u32));
            Assert.AreEqual(8, Marshal.SizeOf(u64));
            /**/
            Assert.AreEqual(4, Marshal.SizeOf(true));
            // マーシャルではStructLayout情報がない文字は1byte
            Assert.AreEqual(1, Marshal.SizeOf(uni.c16));
            // マーシャル情報(MarshalAs)はUnicodeTypeの型情報なので失敗する
            try {
                Assert.AreEqual(10, Marshal.SizeOf(uni.str));
                Assert.IsTrue(false);
            }
            catch (ArgumentException) {
            }
            Assert.AreEqual(4, Marshal.SizeOf(1.0f));
            Assert.AreEqual(8, Marshal.SizeOf(1.1));
            Assert.AreEqual(16, Marshal.SizeOf(1.1m));
            Assert.AreEqual(15, Marshal.SizeOf(new MarshalEnum()));
            try {
                Assert.AreEqual(1, Marshal.SizeOf(EnumU8.Value));
                Assert.IsTrue(false);
            }
            catch (ArgumentException) {
            }
            unsafe
            {
                Assert.AreEqual(2, sizeof(short));
                Assert.AreEqual(4, sizeof(int));
                Assert.AreEqual(8, sizeof(long));
                Assert.AreEqual(1, sizeof(byte));
                Assert.AreEqual(2, sizeof(ushort));
                Assert.AreEqual(4, sizeof(uint));
                Assert.AreEqual(8, sizeof(ulong));
                /**/
                Assert.AreEqual(1, sizeof(bool));
                Assert.AreEqual(2, sizeof(char));
                Assert.AreEqual(1, sizeof(sbyte));
                Assert.AreEqual(4, sizeof(float));
                Assert.AreEqual(8, sizeof(double));
                Assert.AreEqual(16, sizeof(decimal));
                Assert.AreEqual(1, sizeof(EnumU8));
                Assert.AreEqual(2, sizeof(EnumU16));
                Assert.AreEqual(4, sizeof(EnumU32));
                Assert.AreEqual(8, sizeof(EnumU64));
                Assert.AreEqual(1, sizeof(EnumS8));
                Assert.AreEqual(2, sizeof(EnumS16));
                Assert.AreEqual(4, sizeof(EnumS32));
                Assert.AreEqual(8, sizeof(EnumS64));
            }
Пример #3
0
 /**
  * Gets an output character in the table by Unicode character type.
  *
  * @param unicodeType
  *            the type of Unicode character
  *
  * @return the output character in the table
  */
 public char getCharacter(UnicodeType unicodeType)
 {
     return unicodeList[(int)unicodeType];
 }
Пример #4
0
 /**
  * Adds an Arabic character to the table.
  *
  * @param unicodeType
  *            the type of Unicode character
  *
  * @param ch
  *            the output character
  *
  * @param characterType
  *            the type of Arabic character
  */
 protected void addItem(UnicodeType unicodeType, char ch, CharacterType characterType)
 {
     this.addItem(unicodeType, ch, characterType, DiacriticType.Unknown);
 }
Пример #5
0
        /**
         * Adds an Arabic character with an attached diacritic to the table.
         *
         * @param unicodeType
         *            the type of Unicode character
         *
         * @param ch
         *            the output character
         *
         * @param characterType
         *            the type of Arabic character
         *
         * @param diacriticType
         *            the type of diacritic
         */
        protected void addItem(UnicodeType unicodeType, char ch, CharacterType characterType, DiacriticType diacriticType)
        {
            // Create the item that will be added to the table.
            EncodingTableItem item = new EncodingTableItem(characterType, diacriticType);

            // Unicode --> item
            unicodeMap[ch] = item;

            // Character type --> Unicode
            if (characterType != CharacterType.Unknown && diacriticType == DiacriticType.Unknown)
            {
                characterList[(int)characterType] = ch;
            }

            // Unicode type --> Unicode
            unicodeList[(int)unicodeType] = ch;
        }