コード例 #1
0
ファイル: MetaFields.cs プロジェクト: nicolaiarocci/Boxroom
        public void Defaults()
        {
            var restMetaFields = new MetaFields();

            Assert.AreEqual("ETag", restMetaFields.ETag);
            Assert.AreEqual("DateCreated", restMetaFields.DateCreated);
        }
コード例 #2
0
 public override string ToString()
 {
     return($"TrackInfo Id: {Id}, " +
            $"Title {Title}, " +
            $"Artist {Artist}, " +
            $"MediaType {MediaType}, " +
            $"MetaFields {string.Join(",", MetaFields.Select(pair => $"{pair.Key}:{pair.Value}"))}");
 }
コード例 #3
0
        /// <summary>
        /// get MetaObject by propertyName which same as DataKey
        /// </summary>
        /// <param name="fieldKey"></param>
        /// <returns></returns>
        public object this[string fieldKey]
        {
            get { return(this.MetaFields.ContainsKey(fieldKey) ? this.MetaFields[fieldKey].DataValue : null); }
            set
            {
                if (MetaFields.ContainsKey(fieldKey))
                {
                    DataType type = EnumsTranslaterUseInProgram.ToDataType(MetaFields[fieldKey].DataType);
                    //check type
                    switch (type)
                    {
                    case DataType.Unknown:
                        break;

                    case DataType.Number:
                        if (!(value is int))
                        {
                            throw new ArgumentException($"value type mismatch.({value} is not '{nameof(DataType.Number)}')");
                        }
                        else
                        {
                            if (value is int intValue)
                            {
                                if (intValue < 0)
                                {
                                    throw new ArgumentException($"value type mismatch.({value} is not '{nameof(DataType.Number)}')");
                                }
                            }
                        }
                        break;

                    case DataType.Text:
                        break;

                    case DataType.DateTime:
                        if (!(value is DateTime || value is DateTimeOffset))
                        {
                            throw new ArgumentException($"value type mismatch.({value} is not correct of '{nameof(DataType.DateTime)}')");
                        }
                        break;

                    case DataType.Date:
                        if (!(value is DateTime || value is DateTimeOffset))
                        {
                            throw new ArgumentException($"value type mismatch.({value} is not correct of '{nameof(DataType.Date)}')");
                        }
                        break;

                    case DataType.Boolean:
                        if (!(value is int || value is bool || value is string))
                        {
                            throw new ArgumentException($"value type mismatch.({value} is not correct of '{nameof(DataType.Boolean)}')");
                        }
                        else
                        {
                            if (value is int intValue)
                            {
                                if (intValue == 0)
                                {
                                    MetaFields[fieldKey].DataValue = false;
                                }
                                else if (intValue == 1)
                                {
                                    MetaFields[fieldKey].DataValue = true;
                                }
                                else
                                {
                                    throw new ArgumentException($"value type mismatch.({value} is not correct of '{nameof(DataType.Boolean)}')");
                                }
                            }
                            else if (value is string strValue)
                            {
                                if (strValue.ToLower().Equals("true"))
                                {
                                    MetaFields[fieldKey].DataValue = true;
                                }
                                else if (strValue.ToLower().Equals("false"))
                                {
                                    MetaFields[fieldKey].DataValue = false;
                                }
                                else
                                {
                                    throw new ArgumentException($"value type mismatch.({value} is not correct of '{nameof(DataType.Boolean)}')");
                                }
                            }
                        }
                        break;

                    case DataType.Int:
                        if (!(value is int))
                        {
                            throw new ArgumentException($"value type mismatch.({value} is not '{nameof(DataType.Int)}')");
                        }
                        break;

                    case DataType.Long:
                        if (!(value is long))
                        {
                            throw new ArgumentException($"value type mismatch.({value} is not '{nameof(DataType.Long)}')");
                        }
                        break;

                    case DataType.Double:
                        if (!(value is double))
                        {
                            throw new ArgumentException($"value type mismatch.({value} is not '{nameof(DataType.Double)}')");
                        }
                        break;

                    case DataType.DataSource:
                        break;

                    case DataType.StandradDate:
                        if (!(value is DateTime || value is DateTimeOffset))
                        {
                            throw new ArgumentException($"value type mismatch.({value} is not correct of '{nameof(DataType.Date)}')");
                        }
                        break;

                    case DataType.StandradDateTime:
                        if (!(value is DateTime || value is DateTimeOffset))
                        {
                            throw new ArgumentException($"value type mismatch.({value} is not correct of '{nameof(DataType.Date)}')");
                        }
                        break;

                    default:
                        break;
                    }
                    MetaFields[fieldKey].DataValue = value;
                }
            }
        }
コード例 #4
0
ファイル: MetaFields.cs プロジェクト: nicolaiarocci/Boxroom
 public void Setup()
 {
     MetaFields = new MetaFields();
 }