Disco.Services.DeviceDetailExtensions.SetDetail C# (CSharp) Method

SetDetail() private static method

private static SetDetail ( this device, string Scope, string Key, string Value ) : void
device this
Scope string
Key string
Value string
return void
        private static void SetDetail(this Device device, string Scope, string Key, string Value)
        {
            if (device == null)
                throw new ArgumentNullException("device");
            if (string.IsNullOrEmpty(Scope))
                throw new ArgumentNullException("Scope");
            if (string.IsNullOrEmpty(Key))
                throw new ArgumentNullException("Key");

            var detail = device.DeviceDetails.Where(d => d.Scope == Scope && d.Key == Key).FirstOrDefault();

            // No Detail Stored & Set to Null
            if (detail == null && Value == null)
                return;

            if (detail == null)
            {
                detail = new DeviceDetail()
                {
                    DeviceSerialNumber = device.SerialNumber,
                    Scope = Scope,
                    Key = Key,
                    Value = Value
                };
                device.DeviceDetails.Add(detail);
            }

            if (detail.Value != Value)
            {
                if (Value == null)
                {
                    device.DeviceDetails.Remove(detail);
                }
                else
                {
                    detail.Value = Value;
                }
            }
        }
        #endregion