Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / clr / src / BCL / System / Runtime / Versioning / ResourceAttributes.cs / 1 / ResourceAttributes.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Purpose: Resource annotation rules. ** ===========================================================*/ using System; using System.Diagnostics; using Microsoft.Win32; namespace System.Runtime.Versioning { [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Constructor, Inherited = false)] [Conditional("RESOURCE_ANNOTATION_WORK")] public sealed class ResourceConsumptionAttribute : Attribute { private ResourceScope _consumptionScope; private ResourceScope _resourceScope; public ResourceConsumptionAttribute(ResourceScope resourceScope) { _resourceScope = resourceScope; _consumptionScope = _resourceScope; } public ResourceConsumptionAttribute(ResourceScope resourceScope, ResourceScope consumptionScope) { _resourceScope = resourceScope; _consumptionScope = consumptionScope; } public ResourceScope ResourceScope { get { return _resourceScope; } } public ResourceScope ConsumptionScope { get { return _consumptionScope; } } } [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Constructor, Inherited = false)] [Conditional("RESOURCE_ANNOTATION_WORK")] public sealed class ResourceExposureAttribute : Attribute { private ResourceScope _resourceExposureLevel; public ResourceExposureAttribute(ResourceScope exposureLevel) { _resourceExposureLevel = exposureLevel; } public ResourceScope ResourceExposureLevel { get { return _resourceExposureLevel; } } } // Default visibility is Public, which isn't specified in this enum. // Public == the lack of Private or Assembly // Does this actually work? Need to investigate that. [Flags] public enum ResourceScope { None = 0, // Resource type Machine = 0x1, Process = 0x2, AppDomain = 0x4, Library = 0x8, // Visibility Private = 0x10, // Private to this one class. Assembly = 0x20, // Assembly-level, like C#'s "internal" } [Flags] internal enum SxSRequirements { None = 0, AppDomainID = 0x1, ProcessID = 0x2, AssemblyName = 0x4, TypeName = 0x8 } public static class VersioningHelper { // These depend on the exact values given to members of the ResourceScope enum. private static ResourceScope ResTypeMask = ResourceScope.Machine | ResourceScope.Process | ResourceScope.AppDomain | ResourceScope.Library; private static ResourceScope VisibilityMask = ResourceScope.Private | ResourceScope.Assembly; public static String MakeVersionSafeName(String name, ResourceScope from, ResourceScope to) { return MakeVersionSafeName(name, from, to, null); } [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Process, ResourceScope.Process)] public static String MakeVersionSafeName(String name, ResourceScope from, ResourceScope to, Type type) { ResourceScope fromResType = from & ResTypeMask; ResourceScope toResType = to & ResTypeMask; if (fromResType > toResType) throw new ArgumentException(Environment.GetResourceString("Argument_ResourceScopeWrongDirection", fromResType, toResType), "from"); SxSRequirements requires = GetRequirements(to, from); if ((requires & (SxSRequirements.AssemblyName | SxSRequirements.TypeName)) != 0 && type == null) throw new ArgumentNullException("type", Environment.GetResourceString("ArgumentNull_TypeRequiredByResourceScope")); String postfix = ""; const String separator = "_"; if ((requires & SxSRequirements.ProcessID) != 0) postfix += separator + Win32Native.GetCurrentProcessId(); if ((requires & SxSRequirements.AppDomainID) != 0) postfix += separator + AppDomain.CurrentDomain.GetAppDomainId(); if ((requires & SxSRequirements.TypeName) != 0) postfix += separator + type.Name; if ((requires & SxSRequirements.AssemblyName) != 0) postfix += separator + type.Assembly.FullName; return name + postfix; } private static SxSRequirements GetRequirements(ResourceScope consumeAsScope, ResourceScope calleeScope) { SxSRequirements requires = SxSRequirements.None; switch(calleeScope & ResTypeMask) { case ResourceScope.Machine: switch(consumeAsScope & ResTypeMask) { case ResourceScope.Machine: // No work break; case ResourceScope.Process: requires |= SxSRequirements.ProcessID; break; case ResourceScope.AppDomain: requires |= SxSRequirements.AppDomainID | SxSRequirements.ProcessID; break; default: throw new ArgumentException(Environment.GetResourceString("Argument_BadResourceScopeTypeBits", consumeAsScope), "consumeAsScope"); } break; case ResourceScope.Process: if ((consumeAsScope & ResourceScope.AppDomain) != 0) requires |= SxSRequirements.AppDomainID; break; case ResourceScope.AppDomain: // No work break; default: throw new ArgumentException(Environment.GetResourceString("Argument_BadResourceScopeTypeBits", calleeScope), "calleeScope"); } switch(calleeScope & VisibilityMask) { case ResourceScope.None: // Public - implied switch(consumeAsScope & VisibilityMask) { case ResourceScope.None: // Public - implied // No work break; case ResourceScope.Assembly: requires |= SxSRequirements.AssemblyName; break; case ResourceScope.Private: requires |= SxSRequirements.TypeName | SxSRequirements.AssemblyName; break; default: throw new ArgumentException(Environment.GetResourceString("Argument_BadResourceScopeVisibilityBits", consumeAsScope), "consumeAsScope"); } break; case ResourceScope.Assembly: if ((consumeAsScope & ResourceScope.Private) != 0) requires |= SxSRequirements.TypeName; break; case ResourceScope.Private: // No work break; default: throw new ArgumentException(Environment.GetResourceString("Argument_BadResourceScopeVisibilityBits", calleeScope), "calleeScope"); } if (consumeAsScope == calleeScope) { BCLDebug.Assert(requires == SxSRequirements.None, "Computed a strange set of required resource scoping. It's probably wrong."); } return requires; } } }
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XmlSchemaNotation.cs
- MailWebEventProvider.cs
- RuleInfoComparer.cs
- XpsManager.cs
- XmlWrappingReader.cs
- NativeMethods.cs
- UserControl.cs
- MatrixValueSerializer.cs
- BooleanAnimationBase.cs
- TabItemWrapperAutomationPeer.cs
- StrokeNodeOperations2.cs
- Graphics.cs
- CalendarButton.cs
- SystemIPv4InterfaceProperties.cs
- BitmapPalette.cs
- FixedTextPointer.cs
- OutputCacheSettings.cs
- ListBoxItemAutomationPeer.cs
- CodeTypeReferenceExpression.cs
- ComboBoxAutomationPeer.cs
- KeyValueConfigurationCollection.cs
- ScriptResourceHandler.cs
- RenderData.cs
- SoapFaultCodes.cs
- ExpressionVisitorHelpers.cs
- HostingEnvironmentWrapper.cs
- FtpRequestCacheValidator.cs
- DiscoveryClientDocuments.cs
- ConfigurationManagerHelperFactory.cs
- XmlUtil.cs
- WebPartConnectionsCloseVerb.cs
- TextBreakpoint.cs
- BevelBitmapEffect.cs
- SystemIPv6InterfaceProperties.cs
- InternalCache.cs
- BasePattern.cs
- ValidationSummary.cs
- ResXBuildProvider.cs
- MobileTextWriter.cs
- VisualBasicImportReference.cs
- RayMeshGeometry3DHitTestResult.cs
- SafeWaitHandle.cs
- ReliableMessagingVersionConverter.cs
- XmlElementList.cs
- ServicePointManagerElement.cs
- BoolExpression.cs
- ColumnWidthChangingEvent.cs
- RotateTransform3D.cs
- DataBinder.cs
- SmtpException.cs
- XmlSchemaElement.cs
- DataQuery.cs
- DrawingVisualDrawingContext.cs
- SafeThemeHandle.cs
- UxThemeWrapper.cs
- DispatcherOperation.cs
- SiteMapNodeCollection.cs
- RawStylusSystemGestureInputReport.cs
- ProcessModelSection.cs
- NetCodeGroup.cs
- ErrorWrapper.cs
- ChannelFactoryBase.cs
- __Filters.cs
- XmlSerializationReader.cs
- LayoutInformation.cs
- ContextBase.cs
- xmlformatgeneratorstatics.cs
- SectionInformation.cs
- IssuedTokenServiceCredential.cs
- SubqueryTrackingVisitor.cs
- HttpRuntimeSection.cs
- GridSplitter.cs
- XmlSchemaChoice.cs
- ConditionChanges.cs
- ZipIOFileItemStream.cs
- ServiceOperationListItemList.cs
- WebBrowsableAttribute.cs
- DllNotFoundException.cs
- FileReservationCollection.cs
- TextParagraphView.cs
- IntSecurity.cs
- CFGGrammar.cs
- handlecollector.cs
- WebPartCatalogCloseVerb.cs
- InteropTrackingRecord.cs
- LocalizedNameDescriptionPair.cs
- ManagementScope.cs
- ApplicationContext.cs
- FileDialogPermission.cs
- ImageInfo.cs
- FlowPosition.cs
- StringAttributeCollection.cs
- RequestQueryParser.cs
- NestedContainer.cs
- RegexWorker.cs
- FontStretch.cs
- ObjectListItem.cs
- Configuration.cs
- CalendarTable.cs
- CheckableControlBaseAdapter.cs