public static IEnumerable <KeyValuePair <Guid, _MF_ATTRIBUTE_TYPE> > Enumerate(this IMFAttributes obj) { if (obj == null) { yield break; } for (int i = 0; i < Count(obj); i++) { obj.GetItemByIndex((uint)i, out Guid guid, null).ThrowOnError(); obj.GetItemType(guid, out var type).ThrowOnError(); yield return(new KeyValuePair <Guid, _MF_ATTRIBUTE_TYPE>(guid, type)); } }
public static bool TryGet <T>(this IMFAttributes obj, Guid key, IFormatProvider provider, out T value) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } if (obj.GetItemType(key, out var type).IsError) { value = default(T); return(false); } T item; switch (type) { case _MF_ATTRIBUTE_TYPE.MF_ATTRIBUTE_BLOB: if (typeof(T) == typeof(byte[])) { value = (T)(object)GetBlob(obj, key); return(true); } var bytes = GetBlob(obj, key); if (!Conversions.TryChangeType(bytes, provider, out item)) { value = default(T); return(false); } value = item; return(true); case _MF_ATTRIBUTE_TYPE.MF_ATTRIBUTE_DOUBLE: var dbl = GetDouble(obj, key); if (!Conversions.TryChangeType(dbl, provider, out item)) { value = default(T); return(false); } value = item; return(true); case _MF_ATTRIBUTE_TYPE.MF_ATTRIBUTE_GUID: var guid = GetGuid(obj, key); if (!Conversions.TryChangeType(guid, provider, out item)) { value = default(T); return(false); } value = item; return(true); case _MF_ATTRIBUTE_TYPE.MF_ATTRIBUTE_STRING: var s = GetString(obj, key); if (!Conversions.TryChangeType(s, provider, out item)) { value = default(T); return(false); } value = item; return(true); case _MF_ATTRIBUTE_TYPE.MF_ATTRIBUTE_UINT32: var ui = GetUInt32(obj, key); if (!Conversions.TryChangeType(ui, provider, out item)) { value = default(T); return(false); } value = item; return(true); case _MF_ATTRIBUTE_TYPE.MF_ATTRIBUTE_UINT64: var ul = GetUInt64(obj, key); if (!Conversions.TryChangeType(ul, provider, out item)) { value = default(T); return(false); } value = item; return(true); case _MF_ATTRIBUTE_TYPE.MF_ATTRIBUTE_IUNKNOWN: var comType = ComObject.GetGenericComObjectComType(typeof(T)); if (comType == null) { value = (T)GetUnknown(obj, key, typeof(T).GUID); return(value != null); } var unk = GetUnknown(obj, key, comType.GUID); if (unk == null) { value = default(T); return(false); } value = (T)(object)ComObject.WrapAsGeneric(comType, unk); return(true); default: throw new NotSupportedException(); } }
public HResult GetItemType(Guid guidKey, out MFAttributeType pType) { return(m_Attribs.GetItemType(guidKey, out pType)); }