コード例 #1
0
        public static string UUIDAsName(string fileName)
        {
            AssertUtils.AssertNotNull(fileName);

            int dotIdx = fileName.LastIndexOf('.');

            AssertUtils.AssertTrue(dotIdx >= 0, "fileName is invalid.");

            return($"{UUIDUtils.randomUUID()}{fileName.Substring(dotIdx)}");
        }
コード例 #2
0
        public bool Validate(string value)
        {
            Initialize();

            AssertUtils.AssertNotNull(value);
            foreach (var pattern in this.allowPatterns)
            {
                if (pattern.IsMatch(value))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #3
0
        public static string UUIDAppendToName(string fileName)
        {
            AssertUtils.AssertNotNull(fileName);

            int dotIdx = fileName.LastIndexOf('.');

            AssertUtils.AssertTrue(dotIdx >= 0, "fileName is invalid.");

            string name = StringUtils.TrimToEmpty(fileName.Substring(0, dotIdx));

            if (name.Length == 0)
            {
                return($"{UUIDUtils.randomUUID()}{fileName.Substring(dotIdx)}");
            }
            return($"{name}-{UUIDUtils.randomUUID()}{fileName.Substring(dotIdx)}");
        }
コード例 #4
0
        public static void SetProperties(object to, object from, Func <string, bool> forProperties)
        {
            AssertUtils.AssertNotNull(to);
            AssertUtils.AssertNotNull(from);
            AssertUtils.AssertNotNull(forProperties);

            PropertyInfo[] fromProperties = from.GetType().GetProperties();
            foreach (PropertyInfo fromProp in fromProperties)
            {
                if (!forProperties(fromProp.Name))
                {
                    continue;
                }
                AssertUtils.AssertTrue(fromProp.CanRead);

                PropertyInfo toProp = to.GetType().GetProperty(fromProp.Name);
                AssertUtils.AssertNotNull(toProp);
                AssertUtils.AssertTrue(toProp.CanWrite);

                toProp.SetValue(to, fromProp.GetValue(from));
            }
        }