Пример #1
0
        public static IDictionary <string, string> GetNamespacesInScope(this XmlReader reader)
        {
            if (reader == null)
            {
                return(null);
            }
            var xmlResolver = reader as IXmlNamespaceResolver;

            if (xmlResolver != null)
            {
                return(xmlResolver.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml));
            }
            var asmSysRuntimeSerialization = Assembly.Load("System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
            var t          = asmSysRuntimeSerialization.GetType("System.Xml.XmlBaseReader");
            var readerType = reader.GetType();

            if (t.IsAssignableFrom(readerType))
            {
                var nsMgr      = ExposedObject.From(ExposedObject.From(reader).nsMgr);
                var namespaces = nsMgr.namespaces as object[];
                if (namespaces == null)
                {
                    return(null);
                }
                var dic = new Dictionary <string, string>();
                for (int i = nsMgr.nsCount - 1; i >= 0; i--)
                {
                    var ns = ExposedObject.From(namespaces[i]);
                    if (ns == null)
                    {
                        continue;
                    }
                    var prefix = ExposedObject.From(ns.Prefix);
                    if (prefix == null || prefix.IsEmpty || prefix.IsXml || prefix.IsXmlns)
                    {
                        continue;
                    }
                    var key = prefix.GetString() as string;
                    if (String.IsNullOrEmpty(key))
                    {
                        continue;
                    }
                    var    uri   = ExposedObject.From(ns.Uri);
                    string value = uri != null?uri.GetString() : null;

                    dic[key] = value ?? String.Empty;
                }
                return(dic);
            }
            return(null);
        }
Пример #2
0
 public static T Cast <T>(ExposedObject t)
 {
     return((T)t.m_object);
 }