public void ParseMetadataItemTypeTest() { MetadataItemType type = MetadataItemType.Parse(Parse("<item_type>hello world</item_type>")); Assert.AreEqual("hello world", type.Name); }
public void GenerateMetadataXmlTest() { MetadataItemType type = new MetadataItemType("xyz"); string xml = GenerateXml(type); MetadataItemType parsed = MetadataItemType.Parse(Parse(xml)); Assert.AreEqual("xyz", parsed.Name); }
/// <summary>Gets the value of the specified attribute.</summary> /// <param name="itemType">The type of the attribute.</param> /// <param name="valueData">The byte array to be parsed.</param> protected static object ParseAttributeValue(MetadataItemType itemType, byte[] valueData) { if (!Enum.IsDefined(typeof(MetadataItemType), itemType)) { throw new ArgumentOutOfRangeException("itemType"); } if (valueData == null) { throw new ArgumentNullException("valueData"); } // Convert the attribute value to a byte array based on the item type. switch (itemType) { case MetadataItemType.String: StringBuilder sb = new StringBuilder(valueData.Length); for (int i = 0; i < valueData.Length - 2; i += 2) { sb.Append(Convert.ToString(BitConverter.ToChar(valueData, i))); } string result = sb.ToString(); if (result.EndsWith("\\0")) { result = result.Substring(0, result.Length - 2); } return(result); case MetadataItemType.Boolean: return(BitConverter.ToBoolean(valueData, 0)); case MetadataItemType.Dword: return(BitConverter.ToInt32(valueData, 0)); case MetadataItemType.Qword: return(BitConverter.ToInt64(valueData, 0)); case MetadataItemType.Word: return(BitConverter.ToInt16(valueData, 0)); case MetadataItemType.Guid: return(new Guid(valueData)); case MetadataItemType.Binary: return(valueData); default: throw new ArgumentOutOfRangeException("itemType"); } }
/// <summary>Initializes the metadata item.</summary> /// <param name="name">The name of the attribute.</param> /// <param name="value">The value of the attribute.</param> /// <param name="type">The type of the attribute value.</param> internal MetadataItem(string name, object value, MetadataItemType type) { Name = name; Value = value; Type = type; }
/// <summary>Gets the value of the specified attribute.</summary> /// <param name="itemType">The type of the attribute.</param> /// <param name="valueData">The byte array to be parsed.</param> private static object ParseAttributeValue(MetadataItemType itemType, byte[] valueData) { if (!Enum.IsDefined(typeof(MetadataItemType), itemType)) throw new ArgumentOutOfRangeException("itemType"); if (valueData == null) throw new ArgumentNullException("valueData"); // Convert the attribute value to a byte array based on the item type. switch (itemType) { case MetadataItemType.String: StringBuilder sb = new StringBuilder(valueData.Length); for (int i = 0; i < valueData.Length - 2; i += 2) { sb.Append(Convert.ToString(BitConverter.ToChar(valueData, i))); } string result = sb.ToString(); if (result.EndsWith("\\0")) result = result.Substring(0, result.Length - 2); return result; case MetadataItemType.Boolean: return BitConverter.ToBoolean(valueData, 0); case MetadataItemType.Dword: return BitConverter.ToInt32(valueData, 0); case MetadataItemType.Qword: return BitConverter.ToInt64(valueData, 0); case MetadataItemType.Word: return BitConverter.ToInt16(valueData, 0); case MetadataItemType.Guid: return new Guid(valueData); case MetadataItemType.Binary: return valueData; default: throw new ArgumentOutOfRangeException("itemType"); } }
/// <summary>Initializes the metadata item.</summary> /// <param name="name">The name of the attribute.</param> /// <param name="value">The value of the attribute.</param> /// <param name="type">The type of the attribute value.</param> public MetadataItem(string name, object value, MetadataItemType type) { Name = name; Value = value; Type = type; }