internal KnownFolderDefinition(IKnownFolder nativeKnownFolder)
        {
            if (nativeKnownFolder == null)
            {
                throw new ArgumentNullException("nativeKnownFolder");
            }

            this.nativeDefinition = KNOWNFOLDER_DEFINITION.FromKnownFolder(nativeKnownFolder);
        }
        public static KNOWNFOLDER_DEFINITION FromKnownFolder(IKnownFolder knownFolder)
        {
            if (knownFolder == null)
            {
                throw new ArgumentNullException("knownFolder");
            }

            KNOWNFOLDER_DEFINITION def;

            using (var handles = new KnownFolderDefinitionHandles())
            {
                KNOWNFOLDER_DEFINITION_RAW rawDef;

                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                }
                finally
                {
                    knownFolder.GetFolderDefinition(out rawDef);
                    try
                    {
                        handles.SecureHandles(ref rawDef);
                    }
                    finally
                    {
                        // in case SecureHandles throws
                        rawDef.FreeKnownFolderDefinitionFields();
                    }
                }

                def = new KNOWNFOLDER_DEFINITION(ref rawDef, handles);
            }

            return(def);
        }
        public static KNOWNFOLDER_DEFINITION FromKnownFolder(IKnownFolder knownFolder)
        {
            if (knownFolder == null)
            {
                throw new ArgumentNullException("knownFolder");
            }

            KNOWNFOLDER_DEFINITION def;

            using (var handles = new KnownFolderDefinitionHandles())
            {
                KNOWNFOLDER_DEFINITION_RAW rawDef;

                RuntimeHelpers.PrepareConstrainedRegions();
                try
                {
                }
                finally
                {
                    knownFolder.GetFolderDefinition(out rawDef);
                    try
                    {
                        handles.SecureHandles(ref rawDef);
                    }
                    finally
                    {
                        // in case SecureHandles throws
                        rawDef.FreeKnownFolderDefinitionFields();
                    }
                }

                def = new KNOWNFOLDER_DEFINITION(ref rawDef, handles);
            }

            return def;
        }