Пример #1
0
        public static IEnumerable <TEnum> ToEnum <TEnum>(this IPortableDevicePropVariantCollection col) where TEnum : struct // enum
        {
            uint count = 0;

            col.GetCount(ref count);
            for (uint i = 0; i < count; i++)
            {
                PropVariantFacade val = new PropVariantFacade();
                col.GetAt(i, ref val.Value);
                yield return(GetEnumFromAttrGuid <TEnum>(val.ToGuid()));
            }
        }
Пример #2
0
        public static IEnumerable <Guid> ToGuid(this IPortableDevicePropVariantCollection col)
        {
            uint count = 0;

            col.GetCount(ref count);
            for (uint i = 0; i < count; i++)
            {
                using (PropVariantFacade val = new PropVariantFacade())
                {
                    col.GetAt(i, ref val.Value);
                    yield return(val.ToGuid());
                }
            }
        }
Пример #3
0
        public static IEnumerable <KeyValuePair <string, string> > ToKeyValuePair(this IPortableDeviceValues values)
        {
            uint num = 0;

            values?.GetCount(ref num);
            for (uint i = 0; i < num; i++)
            {
                PropertyKey key = new PropertyKey();
                using (PropVariantFacade val = new PropVariantFacade())
                {
                    values.GetAt(i, ref key, ref val.Value);


                    string    fieldName = string.Empty;
                    FieldInfo propField = ComTrace.FindPropertyKeyField(key);
                    if (propField != null)
                    {
                        fieldName = propField.Name;
                    }
                    else
                    {
                        FieldInfo guidField = ComTrace.FindGuidField(key.fmtid);
                        if (guidField != null)
                        {
                            fieldName = $"{guidField.Name}, {key.pid}";
                        }
                        else
                        {
                            fieldName = $"{key.fmtid}, {key.pid}";
                        }
                    }
                    string fieldValue = string.Empty;
                    switch (val.VariantType)
                    {
                    case PropVariantType.VT_CLSID:
                        fieldValue = ComTrace.FindGuidField(val.ToGuid())?.Name ?? val.ToString();
                        break;

                    default:
                        fieldValue = val.ToDebugString();
                        break;
                    }

                    yield return(new KeyValuePair <string, string>(fieldName, fieldValue));
                }
            }
        }
Пример #4
0
        private static void InternalWriteObject(IPortableDeviceValues values)
        {
            string func = new StackTrace().GetFrame(2).GetMethod().Name;

            Trace.WriteLine($"############################### {func}");
            uint num = 0;

            values.GetCount(ref num);
            for (uint i = 0; i < num; i++)
            {
                PropertyKey       key = new PropertyKey();
                PropVariantFacade val = new PropVariantFacade();
                values.GetAt(i, ref key, ref val.Value);

                string    fieldName = string.Empty;
                FieldInfo propField = FindPropertyKeyField(key);
                if (propField != null)
                {
                    fieldName = propField.Name;
                }
                else
                {
                    FieldInfo guidField = FindGuidField(key.fmtid);
                    if (guidField != null)
                    {
                        fieldName = $"{guidField.Name}, {key.pid}";
                    }
                    else
                    {
                        fieldName = $"{key.fmtid}, {key.pid}";
                    }
                }

                switch (val.VariantType)
                {
                case PropVariantType.VT_CLSID:
                    Trace.WriteLine($"##### {fieldName} = {FindGuidField(val.ToGuid())?.Name ?? val.ToString()}");
                    break;

                default:
                    Trace.WriteLine($"##### {fieldName} = {val.ToDebugString()}");
                    break;
                }
            }
        }