Exemplo n.º 1
0
        public CollectionTypeMap(
            Type type, Type elementType,
            QName qname, KnownTypeCollection knownTypes)
            : base(type, qname, knownTypes)
        {
            element_type  = elementType;
            element_qname = KnownTypes.GetQName(element_type);
            var icoll = GetGenericCollectionInterface(RuntimeType);

            if (icoll != null)
            {
                if (RuntimeType.IsInterface)
                {
                    add_method = RuntimeType.GetMethod("Add", icoll.GetGenericArguments());
                }
                else
                {
                    var imap = RuntimeType.GetInterfaceMap(icoll);
                    for (int i = 0; i < imap.InterfaceMethods.Length; i++)
                    {
                        if (imap.InterfaceMethods [i].Name == "Add")
                        {
                            add_method = imap.TargetMethods [i];
                            break;
                        }
                    }
                    if (add_method == null)
                    {
                        add_method = type.GetMethod("Add", icoll.GetGenericArguments());
                    }
                }
            }
        }
Exemplo n.º 2
0
        public DictionaryTypeMap(
            Type type, CollectionDataContractAttribute a, KnownTypeCollection knownTypes)
            : base(type, QName.Empty, knownTypes)
        {
            this.a = a;

            key_type   = typeof(object);
            value_type = typeof(object);

            var idic = GetGenericDictionaryInterface(RuntimeType);

            if (idic != null)
            {
                var imap = RuntimeType.GetInterfaceMap(idic);
                for (int i = 0; i < imap.InterfaceMethods.Length; i++)
                {
                    if (imap.InterfaceMethods [i].Name == "Add")
                    {
                        add_method = imap.TargetMethods [i];
                        break;
                    }
                }
                var argtypes = idic.GetGenericArguments();
                key_type   = argtypes [0];
                value_type = argtypes [1];
                if (add_method == null)
                {
                    add_method = type.GetMethod("Add", argtypes);
                }
            }

            XmlName     = GetDictionaryQName();
            item_qname  = GetItemQName();
            key_qname   = GetKeyQName();
            value_qname = GetValueQName();
        }