internal void Set(TwCapability cap)
        {
            try {
                switch (cap.ConType)
                {
                case TwOn.One:
                    var _genericValue = cap.GetValue();
                    var _oneValue     = _genericValue as TwOneValue;
                    if (_oneValue != null)
                    {
                        this.SetCore(TwTypeHelper.CastToCommon(_oneValue.ItemType, TwTypeHelper.ValueToTw <uint>(_oneValue.ItemType, _oneValue.Item)));
                    }
                    else
                    {
                        this.SetCore(_genericValue.ToString());
                    }
                    break;

                case TwOn.Range:
                    for (var _range = cap.GetValue() as TwRange; _range != null; _range = null)
                    {
                        this.SetCore(
                            TwTypeHelper.CastToCommon(_range.ItemType, TwTypeHelper.ValueToTw <uint>(_range.ItemType, _range.MinValue)),
                            TwTypeHelper.CastToCommon(_range.ItemType, TwTypeHelper.ValueToTw <uint>(_range.ItemType, _range.MaxValue)),
                            TwTypeHelper.CastToCommon(_range.ItemType, TwTypeHelper.ValueToTw <uint>(_range.ItemType, _range.StepSize)),
                            TwTypeHelper.CastToCommon(_range.ItemType, TwTypeHelper.ValueToTw <uint>(_range.ItemType, _range.DefaultValue)),
                            TwTypeHelper.CastToCommon(_range.ItemType, TwTypeHelper.ValueToTw <uint>(_range.ItemType, _range.CurrentValue)));
                    }
                    break;

                case TwOn.Array:
                    for (var _array = cap.GetValue() as __ITwArray; _array != null; _array = null)
                    {
                        this.SetCore(_array.Items);
                    }
                    break;

                case TwOn.Enum:
                    for (var _enum = cap.GetValue() as __ITwEnumeration; _enum != null; _enum = null)
                    {
                        this.SetCore(_enum.Items, _enum.DefaultIndex, _enum.CurrentIndex);
                    }
                    break;

                default:
                    throw new DataSourceException(TwRC.Failure, TwCC.BadValue);
                }
            } catch (Exception ex) {
                throw new DataSourceException(TwRC.Failure, TwCC.BadValue, ex.Message);
            }
        }
        private TwCapability _ToTwCapability(object[] data, TwOn container)
        {
            switch (container)
            {
            case TwOn.One:
                if (data[0] is string)
                {
                    return(new TwCapability(this.CapabilityInfo.Capability, data[0] as string, this.CapabilityInfo.Type));
                }
                else
                {
                    return(new TwCapability(this.CapabilityInfo.Capability, TwTypeHelper.ValueFromTw <uint>(TwTypeHelper.CastToTw(this.CapabilityInfo.Type, data[0])), this.CapabilityInfo.Type));
                }

            case TwOn.Range:     //object[] {<MinValue>,<StepSize>,<DefaultValue>,<CurrentValue>,<MaxValue>}
                return(new TwCapability(
                           this.CapabilityInfo.Capability,
                           new TwRange {
                    ItemType = this.CapabilityInfo.Type,
                    DefaultValue = TwTypeHelper.ValueFromTw <uint>(TwTypeHelper.CastToTw(this.CapabilityInfo.Type, data[2])),
                    CurrentValue = TwTypeHelper.ValueFromTw <uint>(TwTypeHelper.CastToTw(this.CapabilityInfo.Type, data[3])),
                    MinValue = TwTypeHelper.ValueFromTw <uint>(TwTypeHelper.CastToTw(this.CapabilityInfo.Type, data[0])),
                    MaxValue = TwTypeHelper.ValueFromTw <uint>(TwTypeHelper.CastToTw(this.CapabilityInfo.Type, data[data.Length - 1])),
                    StepSize = TwTypeHelper.ValueFromTw <uint>(TwTypeHelper.CastToTw(this.CapabilityInfo.Type, data[1]))
                }));

            case TwOn.Array:
                return(new TwCapability(
                           this.CapabilityInfo.Capability,
                           new TwArray {
                    ItemType = this.CapabilityInfo.Type,
                    NumItems = (uint)data.Length
                },
                           data));

            case TwOn.Enum:
                return(new TwCapability(
                           this.CapabilityInfo.Capability,
                           new TwEnumeration {
                    ItemType = this.CapabilityInfo.Type,
                    NumItems = (uint)data.Length,
                    DefaultIndex = (uint)this.DefaultIndex,
                    CurrentIndex = (uint)this.CurrentIndex
                },
                           data));
            }
            throw new DataSourceException(TwRC.Failure, TwCC.CapSeqError);
        }