Example #1
0
        static void Main(string[] args)
        {
            IOptionManager ow = OptionWorker.Current;

            ow.Initializes("my.option", true);
            Console.WriteLine(ow.Option[0].Value.Value);
        }
Example #2
0
        private IOptionManager CreateOptionManager(string optionFile, bool monitor)
        {
            OptionAttribute[] optionAttributes = OptionAttribute.GetOptionAttributeFromAssembly(null);
            IOptionManager    createdObject    = null;

            if (optionAttributes != null && optionAttributes.Length > 0)
            {
                OptionAttribute optionAttribute = optionAttributes[0];
                for (int i = 1; i < optionAttributes.Length; i++)
                {
                    if (optionAttributes[i].Priority > optionAttribute.Priority)
                    {
                        optionAttribute = optionAttributes[i];
                    }
                }
                Type type = optionAttribute.RealType;
                if (type == null)
                {
                    try
                    {
                        type = UtilityType.CreateType(this.GetType().Assembly, optionAttribute.TypeName, true);
                    }
                    catch (Exception e)
                    {
                        throw new OptionException("类型载入错误:" + e.Message, e);
                    }
                }
                try
                {
                    createdObject = (IOptionManager)UtilityType.CreateObject(this.GetType().Assembly, type.FullName, typeof(IOptionManager), true);
                    createdObject.Initializes(optionFile, monitor);
                }
                catch (Exception e)
                {
                    throw new OptionException(e.Message, e);
                }
            }
            return(createdObject);
        }