Пример #1
0
        public static IEnumerable <string> ToStrings(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.ToString());
                }
            }
        }
Пример #2
0
        public static void WriteObject(IPortableDevicePropVariantCollection collection)
        {
            Trace.WriteLine("###############################");
            uint num = 0;

            collection.GetCount(ref num);
            for (uint index = 0; index < num; index++)
            {
                using (PropVariantFacade val = new PropVariantFacade())
                {
                    collection.GetAt(index, ref val.Value);

                    Trace.WriteLine($"##### {val.ToString()}");
                }
            }
        }
Пример #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}";
                    }
                }


                //string fieldName = string.Empty; // field?.Name ?? $"{key.fmtid}, {key.pid}";
                //if (field?.Name == null)
                //{
                //    if (key.fmtid == WPD.PROPERTIES_MTP_VENDOR_EXTENDED_DEVICE_PROPS)
                //    {

                //    }
                //    else
                //    {
                //        fieldName = $"{key.fmtid}, {key.pid}";
                //    }
                //}
                //else
                //{
                //    fieldName = field.Name;
                //}
                switch (val.VariantType)
                {
                case PropVariantType.VT_CLSID:
                    Trace.WriteLine($"##### {fieldName} = {FindGuidField(val.ToGuid())?.Name ?? val.ToString()}");
                    break;

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