コード例 #1
0
        protected void CheckProperty(string propertyName)
        {
            var properties = this.GetType().GetProperties().ToDictionary(m => m.Name);

            if (!properties.ContainsKey(propertyName))
            {
                throw new ArgumentException("Property {0} not exist.", propertyName);
            }

            var pi = properties[propertyName];

            OptionAttribute oa = (OptionAttribute)Attribute.GetCustomAttribute(pi, typeof(OptionAttribute));

            if (oa != null)
            {
                if (oa.MetaValue.Equals("FILE"))
                {
                    string filename = pi.GetValue(this, null) as string;
                    if (!string.IsNullOrEmpty(filename) && !File.Exists(filename))
                    {
                        ParsingErrors.Add(string.Format("File {0} not exists : {1}.", oa.HelpText, filename));
                    }
                }
                else if (oa.MetaValue.Equals("DIRECTORY"))
                {
                    string dirname = pi.GetValue(this, null) as string;
                    if (!string.IsNullOrEmpty(dirname) && !Directory.Exists(dirname))
                    {
                        ParsingErrors.Add(string.Format("Directory {0} not exists : {1}.", oa.HelpText, dirname));
                    }
                }
            }
            else
            {
                OptionListAttribute ola = (OptionListAttribute)Attribute.GetCustomAttribute(pi, typeof(OptionListAttribute));
                if (ola != null)
                {
                    IList <string> filenames = pi.GetValue(this) as IList <string>;
                    if (ola.MetaValue.Equals("FILELIST"))
                    {
                        foreach (var filename in filenames)
                        {
                            if (!string.IsNullOrEmpty(filename) && !File.Exists(filename))
                            {
                                ParsingErrors.Add(string.Format("File {0} not exists : {1}.", ola.HelpText, filename));
                            }
                        }
                    }
                }
                else
                {
                    throw new ArgumentException("Property {0} doesn't have attribute Option/OptionList.", propertyName);
                }
            }
        }
コード例 #2
0
 public void Setup()
 {
     _optionList          = new List <PollOptionDto>();
     _optionListAttribute = new OptionListAttribute(2, 10);
 }