using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Globalization;

namespace FLY.ControlLibrary.Rules
{
    public class FileNameRule : ValidationRule
    {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if (value == null)
                return new ValidationResult(false, "不能为空值！");
            if (!(value is string))
                return new ValidationResult(false, "不能为空字符串！");

            string filename = value as string;

            if (string.IsNullOrEmpty(filename))
                return new ValidationResult(false, "不能为空字符串！");


            foreach (char rInvalidChar in System.IO.Path.GetInvalidFileNameChars())
                if (filename.Contains(rInvalidChar))
                {
                    string msg = "不能包含";
                    foreach (char c in System.IO.Path.GetInvalidFileNameChars())
                        msg += c;
                    return new ValidationResult(false, msg);
                }

            return new ValidationResult(true, null);
        }
    }
}
