Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Base / MS / Internal / Utilities.cs / 1305600 / Utilities.cs
/**************************************************************************\
Copyright Microsoft Corporation. All Rights Reserved.
\**************************************************************************/
namespace MS.Internal
{
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security;
using MS.Win32;
///
/// General utility class for macro-type functions.
///
internal static class Utilities
{
private static readonly Version _osVersion = Environment.OSVersion.Version;
internal static bool IsOSVistaOrNewer
{
get { return _osVersion >= new Version(6, 0); }
}
internal static bool IsOSWindows7OrNewer
{
get { return _osVersion >= new Version(6, 1); }
}
internal static bool IsCompositionEnabled
{
///
/// Critical -- calls into an unsafe native method.
/// TreatAsSafe -- the call to DwmIsCompositionEnabled simply returns a boolean
/// through an out parameter, it is safe information to expose
///
[SecurityCritical, SecurityTreatAsSafe]
get
{
if (!IsOSVistaOrNewer)
{
return false;
}
Int32 isDesktopCompositionEnabled = 0;
UnsafeNativeMethods.HRESULT.Check(UnsafeNativeMethods.DwmIsCompositionEnabled(out isDesktopCompositionEnabled));
return isDesktopCompositionEnabled != 0;
}
}
internal static void SafeDispose(ref T disposable) where T : IDisposable
{
// Dispose can safely be called on an object multiple times.
IDisposable t = disposable;
disposable = default(T);
if (null != t)
{
t.Dispose();
}
}
///
/// Critical - Suppresses unmanaged code security. Calls Marshal.ReleaseComObject which has a LinkDemand.
///
[SuppressUnmanagedCodeSecurity, SecurityCritical]
internal static void SafeRelease(ref T comObject) where T : class
{
T t = comObject;
comObject = default(T);
if (null != t)
{
Debug.Assert(Marshal.IsComObject(t));
Marshal.ReleaseComObject(t);
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
/**************************************************************************\
Copyright Microsoft Corporation. All Rights Reserved.
\**************************************************************************/
namespace MS.Internal
{
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security;
using MS.Win32;
///
/// General utility class for macro-type functions.
///
internal static class Utilities
{
private static readonly Version _osVersion = Environment.OSVersion.Version;
internal static bool IsOSVistaOrNewer
{
get { return _osVersion >= new Version(6, 0); }
}
internal static bool IsOSWindows7OrNewer
{
get { return _osVersion >= new Version(6, 1); }
}
internal static bool IsCompositionEnabled
{
///
/// Critical -- calls into an unsafe native method.
/// TreatAsSafe -- the call to DwmIsCompositionEnabled simply returns a boolean
/// through an out parameter, it is safe information to expose
///
[SecurityCritical, SecurityTreatAsSafe]
get
{
if (!IsOSVistaOrNewer)
{
return false;
}
Int32 isDesktopCompositionEnabled = 0;
UnsafeNativeMethods.HRESULT.Check(UnsafeNativeMethods.DwmIsCompositionEnabled(out isDesktopCompositionEnabled));
return isDesktopCompositionEnabled != 0;
}
}
internal static void SafeDispose(ref T disposable) where T : IDisposable
{
// Dispose can safely be called on an object multiple times.
IDisposable t = disposable;
disposable = default(T);
if (null != t)
{
t.Dispose();
}
}
///
/// Critical - Suppresses unmanaged code security. Calls Marshal.ReleaseComObject which has a LinkDemand.
///
[SuppressUnmanagedCodeSecurity, SecurityCritical]
internal static void SafeRelease(ref T comObject) where T : class
{
T t = comObject;
comObject = default(T);
if (null != t)
{
Debug.Assert(Marshal.IsComObject(t));
Marshal.ReleaseComObject(t);
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Matrix3D.cs
- XpsSerializerFactory.cs
- NameValueSectionHandler.cs
- DataListCommandEventArgs.cs
- ViewStateAttachedPropertyFeature.cs
- MenuAdapter.cs
- CodeGen.cs
- InstanceLockQueryResult.cs
- StrongName.cs
- DataSourceCacheDurationConverter.cs
- WindowsListViewSubItem.cs
- NativeCppClassAttribute.cs
- StreamingContext.cs
- _HeaderInfoTable.cs
- COM2Enum.cs
- XmlLanguageConverter.cs
- COM2ExtendedTypeConverter.cs
- PolicyVersion.cs
- CrossSiteScriptingValidation.cs
- XhtmlBasicPanelAdapter.cs
- RectAnimationClockResource.cs
- ResourceSetExpression.cs
- LinqDataSourceView.cs
- SetIterators.cs
- PopupRootAutomationPeer.cs
- RequiredAttributeAttribute.cs
- WebPartEditorCancelVerb.cs
- EntityTemplateFactory.cs
- BaseDataList.cs
- FrameworkReadOnlyPropertyMetadata.cs
- ViewStateException.cs
- Win32.cs
- DbConnectionStringCommon.cs
- TypeDependencyAttribute.cs
- DropSource.cs
- documentsequencetextpointer.cs
- ReachUIElementCollectionSerializer.cs
- LineBreak.cs
- TreeViewImageKeyConverter.cs
- BuilderPropertyEntry.cs
- HandlerBase.cs
- SqlParameterCollection.cs
- DesignBindingPicker.cs
- DocumentSchemaValidator.cs
- MatrixCamera.cs
- PageCopyCount.cs
- ImmutableObjectAttribute.cs
- Timeline.cs
- SafeNativeMemoryHandle.cs
- DiscoveryServerProtocol.cs
- WorkerRequest.cs
- HtmlInputSubmit.cs
- BufferBuilder.cs
- RadioButtonBaseAdapter.cs
- PenThread.cs
- MouseGestureConverter.cs
- ConfigPathUtility.cs
- IERequestCache.cs
- GeometryGroup.cs
- TypeSemantics.cs
- EditCommandColumn.cs
- InsufficientMemoryException.cs
- RunWorkerCompletedEventArgs.cs
- WindowsScroll.cs
- DataServiceHostFactory.cs
- ECDsaCng.cs
- QueueProcessor.cs
- XmlSortKey.cs
- HandlerWithFactory.cs
- NativeMethods.cs
- Popup.cs
- DelegatedStream.cs
- DependencyPropertyKind.cs
- TextEditorMouse.cs
- DataServiceHost.cs
- TreeBuilderXamlTranslator.cs
- AnimatedTypeHelpers.cs
- InheritedPropertyChangedEventArgs.cs
- OdbcDataReader.cs
- Compensate.cs
- ListDictionaryInternal.cs
- CodeCastExpression.cs
- URLString.cs
- AttachedProperty.cs
- GridLengthConverter.cs
- GroupBoxAutomationPeer.cs
- BoundingRectTracker.cs
- HttpCapabilitiesSectionHandler.cs
- CodeCompileUnit.cs
- UnicodeEncoding.cs
- MenuItemStyleCollection.cs
- SymDocumentType.cs
- CodeSnippetTypeMember.cs
- EncoderReplacementFallback.cs
- RepeaterItem.cs
- TransportListener.cs
- StringValidator.cs
- ToolCreatedEventArgs.cs
- EntryIndex.cs
- RuleProcessor.cs