Beispiel #1
0
 internal static string FormatTypeAndId(VivendiResourceType type, int id, string extension = "")
 {
     // ensure the arguments are valid before formatting them
     if (!Enum.IsDefined(typeof(VivendiResourceType), type))
     {
         throw new InvalidEnumArgumentException(nameof(type), (int)type, typeof(VivendiResourceType));
     }
     if (id < 0)
     {
         throw new ArgumentOutOfRangeException(nameof(id), "Resource IDs must be non-negative.");
     }
     return(Invariant($"{ReservedNamePrefix}-{(int)type}-{id}{extension}"));
 }
Beispiel #2
0
        internal static bool TryParseTypeAndID(string name, out VivendiResourceType type, out int id)
        {
            // remove the extension and parse the remaining name
            var dot       = name.LastIndexOf('.');
            var typeAndId = (dot > -1 ? name.Substring(0, dot) : name).Split('-');

            if (typeAndId.Length == 3 && string.Equals(typeAndId[0], ReservedNamePrefix, Vivendi.PathComparison) && int.TryParse(typeAndId[1], NumberStyles.None, CultureInfo.InvariantCulture, out var typeNumeric) && int.TryParse(typeAndId[2], NumberStyles.None, CultureInfo.InvariantCulture, out id))
            {
                type = (VivendiResourceType)typeNumeric;
                return(true);
            }
            else
            {
                type = 0;
                id   = -1;
                return(false);
            }
        }