CSMongo.MongoOid.SetId C# (CSharp) Метод

SetId() публичный Метод

Converts a string into an ID - IDs should be a hexadecimal string that is either 35 characters (with hyphens) or 24 characters without
public SetId ( string value ) : void
value string
Результат void
        public void SetId(string value)
        {
            //clean up the string first
            value = Regex.Replace(value, "[^a-z0-9]", string.Empty, RegexOptions.IgnoreCase);

            //verify the length
            if (value.Length != 24) {
                throw new ArgumentException("The provided ID was not in an expected format.", "value");
            }

            //parse every pair of bytes
            List<byte> bytes = new List<byte>();
            for (int i = 0; i < value.Length; i += 2) {
                string pair = value.Substring(i, 2);
                byte parsed = byte.Parse(pair, NumberStyles.HexNumber);
                bytes.Add(parsed);
            }

            //and then assign normally
            this.SetId(bytes.ToArray());
        }

Same methods

MongoOid::SetId ( byte value ) : void