Exemplo n.º 1
0
        /// <summary>
        /// Creates a Parser.
        /// </summary>
        public Parser()
        {
            if (s_Status != Status.Uninitialized)
            {
                Dbg.Err($"Parser created while the world is in {s_Status} state; should be {Status.Uninitialized} state");
            }
            s_Status = Status.Accumulating;

            bool unitTestMode = Config.TestParameters != null;

            {
                IEnumerable <Type> staticRefs;
                if (!unitTestMode)
                {
                    staticRefs = UtilReflection.GetAllTypes().Where(t => t.GetCustomAttribute <StaticReferencesAttribute>() != null);
                }
                else if (Config.TestParameters.explicitStaticRefs != null)
                {
                    staticRefs = Config.TestParameters.explicitStaticRefs;
                }
                else
                {
                    staticRefs = Enumerable.Empty <Type>();
                }

                foreach (var type in staticRefs)
                {
                    if (type.GetCustomAttribute <StaticReferencesAttribute>() == null)
                    {
                        Dbg.Err($"{type} is not tagged as StaticReferences");
                    }

                    if (!type.IsAbstract || !type.IsSealed)
                    {
                        Dbg.Err($"{type} is not static");
                    }

                    staticReferences.Add(type);
                }
            }

            Serialization.Initialize();
        }
Exemplo n.º 2
0
        internal static void Initialize()
        {
            Converters = new Dictionary <Type, Converter>();

            IEnumerable <Type> conversionTypes;

            if (Config.TestParameters == null)
            {
                conversionTypes = UtilReflection.GetAllTypes().Where(t => t.IsSubclassOf(typeof(Converter)) && !t.IsAbstract);
            }
            else if (Config.TestParameters.explicitConverters != null)
            {
                conversionTypes = Config.TestParameters.explicitConverters;
            }
            else
            {
                conversionTypes = Enumerable.Empty <Type>();
            }

            foreach (var type in conversionTypes)
            {
                var converter      = (Converter)System.Activator.CreateInstance(type);
                var convertedTypes = converter.HandledTypes();
                if (convertedTypes.Count == 0)
                {
                    Dbg.Err($"{type} is a Def.Converter, but doesn't convert anything");
                }

                foreach (var convertedType in convertedTypes)
                {
                    if (Converters.ContainsKey(convertedType))
                    {
                        Dbg.Err($"Converters {Converters[convertedType].GetType()} and {type} both generate result {convertedType}");
                    }

                    Converters[convertedType] = converter;
                }
            }
        }