Beispiel #1
0
        public GuidTypeResolver(params Type[] types)
        {
            if (types == null || types.Length == 0)
            {
                throw new NFXException(StringConsts.ARGUMENT_ERROR + "GuidTypeResolver.ctor(types==null|Empty)");
            }

            var mappings = types.ToDictionary(t => GuidTypeAttribute.GetGuidTypeAttribute <T, A>(t).TypeGuid, t => t);

            ctor(mappings);
        }
Beispiel #2
0
        public GuidTypeResolver(IConfigSectionNode conf)
        {
            m_Cache = new Dictionary <Guid, Type>();

            if (conf == null || !conf.Exists)
            {
                return;
            }

            foreach (var nasm in conf.Children.Where(n => n.IsSameName(CONFIG_ASSEMBLY_SECTION)))
            {
                var asmName = nasm.AttrByName(Configuration.CONFIG_NAME_ATTR).Value;
                var asmNS   = nasm.AttrByName(CONFIG_NS_ATTR).Value;
                if (asmName.IsNullOrWhiteSpace())
                {
                    continue;
                }

                var asm = Assembly.LoadFrom(asmName);

                foreach (var type in asm.GetTypes().Where(t => t.IsPublic && t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(T))))
                {
                    if (asmNS.IsNotNullOrWhiteSpace() && !NFX.Parsing.Utils.MatchPattern(type.FullName, asmNS))
                    {
                        continue;
                    }
                    var atr = GuidTypeAttribute.GetGuidTypeAttribute <T, A>(type);

                    Type existing;
                    if (m_Cache.TryGetValue(atr.TypeGuid, out existing))
                    {
                        throw new NFXException(StringConsts.GUID_TYPE_RESOLVER_DUPLICATE_ATTRIBUTE_ERROR.Args(type.FullName, atr.TypeGuid, existing.FullName));
                    }

                    m_Cache.Add(atr.TypeGuid, type);
                }
            }

            if (m_Cache.Count == 0)
            {
                App.Log.Write(new NFX.Log.Message
                {
                    Type  = NFX.Log.MessageType.Warning,
                    Topic = CoreConsts.APPLICATION_TOPIC,
                    From  = "{0}.ctor()".Args(GetType().Name),
                    Text  = "No assemblies/types have been registered"
                });
            }
        }