예제 #1
0
        public void WriteXml(XmlWriter xml)
        {
            if (xml == null)
            {
                throw new ArgumentNullException("xml");
            }

            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();

            namespaces.Add("", "");

            foreach (var kvp in this)
            {
                var key = kvp.Value.GetType().Name;
                if (Types.ContainsKey(key))
                {
                    TypeValue valueType = Types[key];
                    valueType.Serialize(xml, kvp.Value, namespaces);
                }
                else
                {
                    throw new KeyNotFoundException("No serializer key for the '" + key + "' type.");
                }
            }
        }
예제 #2
0
        public IDirectoryProvider[] GetDirectoryProviders(System.Type entity)
        {
            if (!documentBuilders.ContainsKey(entity))
            {
                return(null);
            }
            DocumentBuilder documentBuilder = documentBuilders[entity];

            return(documentBuilder.DirectoryProviders);
        }
예제 #3
0
        public void Contains()
        {
            var td = new TypeDictionary <IServiceCollection, IServiceProvider>
            {
                [typeof(ServiceCollection)] = typeof(ServiceProvider)
            };

            td.Contains <ServiceCollection>().ShouldBeTrue();
            td.ContainsKey(typeof(ServiceCollection)).ShouldBeTrue();
            (td as ICollection <KeyValuePair <Type, Type> >).Contains(new KeyValuePair <Type, Type>(typeof(ServiceCollection), typeof(ServiceProvider))).ShouldBeTrue();
        }
        /// <summary>
        /// Returns an <see cref="AuthorizationEntry"/> for a given <typeparamref name="T"/>.
        /// </summary>
        /// <typeparam name="T">The type to find the AuthorizationEntry for.</typeparam>
        /// <returns>
        /// An <see cref="AuthorizationEntry"/> for a given <typeparamref name="T"/>. If the specific <typeparamref name="T"/> was not found
        /// in the internal dictionary, a new <see cref="AuthorizationEntry"/> for <typeparamref name="T"/> will be returned with the default
        /// (disallowed) permissions.
        /// </returns>
        /// <example>
        /// <code>
        /// protected internal bool CanInsertReadOnlyEntry() => AuthorizationFactory.ForType<ReadOnlyEntry>().CanInsertAction();
        /// protected internal bool CanUpdateReadOnlyEntry() => AuthorizationFactory.ForType<ReadOnlyEntry>().CanUpdateAction();
        /// protected internal bool CanDeleteReadOnlyEntry() => AuthorizationFactory.ForType<ReadOnlyEntry>().CanDeleteAction();
        ///
        /// protected internal bool CanInsertCantUpdateEntry() => AuthorizationFactory.ForType<CantUpdateEntry>().CanInsertAction();
        /// protected internal bool CanUpdateCantUpdateEntry() => AuthorizationFactory.ForType<CantUpdateEntry>().CanUpdateAction();
        /// protected internal bool CanDeleteCantUpdateEntry() => AuthorizationFactory.ForType<CantUpdateEntry>().CanDeleteAction();
        ///
        /// protected internal bool CanInsertAdminArchiveEntry() => AuthorizationFactory.ForType<AdminArchiveEntry>().CanInsertAction();
        /// protected internal bool CanUpdateAdminArchiveEntry() => AuthorizationFactory.ForType<AdminArchiveEntry>().CanUpdateAction();
        /// protected internal bool CanDeleteAdminArchiveEntry() => AuthorizationFactory.ForType<AdminArchiveEntry>().CanDeleteAction();
        /// </code>
        /// </example>
        public static AuthorizationEntry ForType <T>() where T : class
        {
            //RWM: Allocating the Type once for speed, see https://twitter.com/robertmclaws/status/1123573880780668928.
            var type = typeof(T);

            if (!_entries.ContainsKey(type))
            {
                Console.WriteLine($"RestierEssentials: The AuthorizationEntry for {type.Name} was not found. Adding new AuthorizationEntry with default permissions to speed up future lookups.");
                _entries[type] = new AuthorizationEntry(type);
            }
            return(_entries[type]);
        }
예제 #5
0
            public void TypeLookupString()
            {
                var d = new TypeDictionary <string>(new Dictionary <Type, string>
                {
                    { typeof(IEnumerable <int>), "enumerable" },
                    { typeof(string), "string" },
                });

                Assert.AreEqual("enumerable", d[typeof(List <int>)]);
                Assert.IsFalse(d.ContainsKey(typeof(void)));
                Assert.AreEqual("string", d[typeof(string)]);
            }
예제 #6
0
 public static TypeSerializationModel GetOrAdd(TypeBase baseType)
 {
     if (baseType != null)
     {
         if (TypeDictionary.ContainsKey(baseType.Name))
         {
             return(TypeDictionary[baseType.Name]);
         }
         else
         {
             return(new TypeSerializationModel(baseType));
         }
     }
     else
     {
         return(null);
     }
 }
예제 #7
0
 public static TypeDbSaver GetOrAdd(TypeBase baseType)
 {
     if (baseType != null)
     {
         if (TypeDictionary.ContainsKey(baseType.Name))
         {
             return(TypeDictionary[baseType.Name]);
         }
         else
         {
             return(new TypeDbSaver(baseType));
         }
     }
     else
     {
         return(null);
     }
 }
예제 #8
0
        protected bool TypeUpdate()
        {
            if (!TypeDictionary.IsChanged && !FType.IsChanged)
            {
                return(false);
            }

            TypeDictionary dict = TypeDictionary.Instance;

            if (!dict.ContainsKey(FType[0]))
            {
                return(false);
            }

            if (FType[0].ToLower() == "none")
            {
                return(false);
            }

            FConfig[0] = dict[FType[0]];

            return(true);
        }
예제 #9
0
        /// <summary>
        /// Generates a new <see cref="RenderingNode">RenderingNode</see> that
        /// corresponds to the given <see cref="XmlElement">XmlElement</see>.
        /// </summary>
        /// <param name="node">
        /// The <see cref="XmlElement">XmlElement</see> node for which to generate
        /// a new <see cref="RenderingNode">RenderingNode</see> object.
        /// </param>
        /// <returns>
        /// The generated <see cref="RenderingNode">RenderingNode</see> that
        /// corresponds to the given <see cref="XmlElement">XmlElement</see>.
        /// </returns>
        public RenderingNode GetRenderingNode(
            ISvgElement node)
        {
            SvgElement    svgNode = (SvgElement)node;
            string        name    = svgNode.NamespaceURI + ":" + svgNode.LocalName;
            RenderingNode result;

            if (nodeByTagName.ContainsKey(name))
            {
                object[] args = new object[] { svgNode };
                result = (RenderingNode)nodeByTagName.CreateInstance(name, args);
            }
            else if (node is ISharpGDIPath)
            {
                result = new GDIPathGraphicsNode(svgNode);
            }
            else
            {
                result = new GraphicsNode(svgNode);
            }

            return(result);
        }
예제 #10
0
        public override XmlElement CreateElement(string prefix, string localName, string ns)
        {
            string     name = ns + ":" + localName;
            XmlElement result;

            if (nodeByTagName.ContainsKey(name))
            {
                Type     type = nodeByTagName[name];
                object[] args = new object[] { prefix, localName, ns, this };

                result = (XmlElement)nodeByTagName.CreateInstance(
                    name, args, BindingFlags.Instance | BindingFlags.NonPublic);
            }
            else if (ns == SvgNamespace)
            {
                result = new SvgElement(prefix, localName, ns, this);
            }
            else
            {
                result = base.CreateElement(prefix, localName, ns);
            }

            return(result);
        }
예제 #11
0
 public void Add_DictionaryContainsKey()
 {
     _dictionary.Add(_type1, _type2, _value);
     Assert.IsTrue(_dictionary.ContainsKey(_type1, _type2));
 }