Esempio n. 1
0
        public void Apply(IComponentDirectory toolDirectory)
        {
            string dum1, dum2;

            MatchThrow(path, out dum1, out dum2);

            Node <object>        node = manager.Find(path);
            TypedStream <object> obj  = node.Open(Type.GetType(typeName), attribute.OpenMode);

            toolDirectory.Register(new Instance(obj, name));
        }
Esempio n. 2
0
        public bool Match(string sourceString, out string path, out string typeName)
        {
            path     = string.Empty;
            typeName = string.Empty;

            // We extract path and typed stream.
            string[] data = sourceString.Split('@');
            if (data.Length == 0)
            {
                return(false);
            }

            path = data[0];
            Type          type;
            Node <object> node = manager.Find(path);

            if (node == null)
            {
                return(false);
            }

            if (data.Length == 1)
            {
                type = node.DefaultType;
            }
            else if (data.Length == 2)
            {
                type = Type.GetType(data[1]);
            }
            else
            {
                return(false);
            }


            // We check type.
            if (type == null)
            {
                return(false);
            }
            if (attribute.Type != null && !Common.IsTypeSameOrDerived(attribute.Type, type))
            {
                return(false);
            }

            typeName = type.FullName;

            // We now validate.
            using (TypedStream <object> typedStream = node.Open(type, OpenMode.Read))
            {
                // Check object count.
                uint count = typedStream.Count;
                if (count < attribute.MinObjectCount || count > attribute.MaxObjectCount)
                {
                    return(false);
                }

                // Are derived disallowed.
                if (attribute.DissallowDerivedTypes &&
                    (typedStream.Flags & StreamOptions.AllowDerivedTypes) != 0)
                {
                    return(false);
                }
            }

            return(true);
        }