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)}"); }
public bool Validate(string value) { Initialize(); AssertUtils.AssertNotNull(value); foreach (var pattern in this.allowPatterns) { if (pattern.IsMatch(value)) { return(true); } } return(false); }
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)}"); }
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)); } }