Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / Runtime / Serialization / BitFlagsGenerator.cs / 1 / BitFlagsGenerator.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Runtime.Serialization { using System; using System.Reflection; using System.Reflection.Emit; using System.Security; //// Critical - works on CodeGenerator objects, which require Critical access // [SecurityRequiresReview(SecurityCriticalScope.Everything)] class BitFlagsGenerator { int bitCount; CodeGenerator ilg; LocalBuilder[] locals; public BitFlagsGenerator(int bitCount, CodeGenerator ilg, string localName) { this.ilg = ilg; this.bitCount = bitCount; int localCount = (bitCount + 7) / 8; locals = new LocalBuilder[localCount]; for (int i = 0; i < locals.Length; i++) { locals[i] = ilg.DeclareLocal(typeof(byte), localName + i, (byte) 0); } } public static bool IsBitSet(byte[] bytes, int bitIndex) { int byteIndex = GetByteIndex(bitIndex); byte bitValue = GetBitValue(bitIndex); return (bytes[byteIndex] & bitValue) == bitValue; } public static void SetBit(byte[] bytes, int bitIndex) { int byteIndex = GetByteIndex(bitIndex); byte bitValue = GetBitValue(bitIndex); bytes[byteIndex] |= bitValue; } public int GetBitCount() { return bitCount; } public LocalBuilder GetLocal(int i) { return locals[i]; } public int GetLocalCount() { return locals.Length; } public void Load(int bitIndex) { LocalBuilder local = locals[GetByteIndex(bitIndex)]; byte bitValue = GetBitValue(bitIndex); ilg.Load(local); ilg.Load(bitValue); ilg.And(); ilg.Load(bitValue); ilg.Ceq(); } public void LoadArray() { LocalBuilder localArray = ilg.DeclareLocal(Globals.TypeOfByteArray, "localArray"); ilg.NewArray(typeof(byte), locals.Length); ilg.Store(localArray); for (int i = 0; i < locals.Length; i++) { ilg.StoreArrayElement(localArray, i, locals[i]); } ilg.Load(localArray); } public void Store(int bitIndex, bool value) { LocalBuilder local = locals[GetByteIndex(bitIndex)]; byte bitValue = GetBitValue(bitIndex); if (value) { ilg.Load(local); ilg.Load(bitValue); ilg.Or(); ilg.Stloc(local); } else { ilg.Load(local); ilg.Load(bitValue); ilg.Not(); ilg.And(); ilg.Stloc(local); } } static byte GetBitValue(int bitIndex) { return (byte)(1 << (bitIndex & 7)); } static int GetByteIndex(int bitIndex) { return bitIndex >> 3; } } } // 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
- FlowchartDesignerCommands.cs
- HttpCachePolicyBase.cs
- MaskInputRejectedEventArgs.cs
- CallInfo.cs
- ConstructorBuilder.cs
- LinkTarget.cs
- oledbmetadatacolumnnames.cs
- precedingquery.cs
- WebBrowserDocumentCompletedEventHandler.cs
- DataObjectFieldAttribute.cs
- QueryUtil.cs
- SafePEFileHandle.cs
- BindingGraph.cs
- HttpPostLocalhostServerProtocol.cs
- CompositeDataBoundControl.cs
- DetailsViewInsertedEventArgs.cs
- FontNamesConverter.cs
- CellCreator.cs
- SerializationSectionGroup.cs
- DataBindingsDialog.cs
- RuleRefElement.cs
- SamlAuthenticationClaimResource.cs
- BasicExpandProvider.cs
- SecureUICommand.cs
- TemplateBamlTreeBuilder.cs
- DemultiplexingClientMessageFormatter.cs
- ApplicationSecurityInfo.cs
- BaseWebProxyFinder.cs
- ContentFilePart.cs
- mda.cs
- Itemizer.cs
- DivideByZeroException.cs
- VisualStyleElement.cs
- SelectedGridItemChangedEvent.cs
- RulePatternOps.cs
- SecurityDocument.cs
- SqlMethods.cs
- WebScriptMetadataMessageEncoderFactory.cs
- HyperLink.cs
- WebPartVerbsEventArgs.cs
- WebContext.cs
- SystemIPAddressInformation.cs
- CharEnumerator.cs
- FontEditor.cs
- Icon.cs
- ContainerVisual.cs
- XmlSchemaImport.cs
- CollectionContainer.cs
- BaseEntityWrapper.cs
- StringUtil.cs
- StreamReader.cs
- CoreSwitches.cs
- SessionStateSection.cs
- HttpRuntimeSection.cs
- ScalarConstant.cs
- Column.cs
- BrowserCapabilitiesCodeGenerator.cs
- DataReaderContainer.cs
- DecoderExceptionFallback.cs
- IxmlLineInfo.cs
- EventSource.cs
- ProtocolReflector.cs
- CodeCatchClauseCollection.cs
- SqlCharStream.cs
- LiteralTextContainerControlBuilder.cs
- PackUriHelper.cs
- OleDbConnectionInternal.cs
- Item.cs
- X509RecipientCertificateClientElement.cs
- XamlToRtfParser.cs
- GeometryDrawing.cs
- DataGridCommandEventArgs.cs
- RunInstallerAttribute.cs
- HotSpot.cs
- MetadataArtifactLoaderComposite.cs
- RuleSettingsCollection.cs
- TemplateInstanceAttribute.cs
- CqlErrorHelper.cs
- SqlNotificationRequest.cs
- HttpListenerPrefixCollection.cs
- PeerObject.cs
- ScopelessEnumAttribute.cs
- RoleManagerModule.cs
- IncrementalHitTester.cs
- RoleBoolean.cs
- EngineSite.cs
- HyperLinkColumn.cs
- HttpResponseHeader.cs
- SoundPlayer.cs
- Expressions.cs
- BaseDataBoundControl.cs
- UrlMapping.cs
- ConsoleKeyInfo.cs
- TreeIterators.cs
- ServiceActivationException.cs
- base64Transforms.cs
- Rotation3DAnimationBase.cs
- LinkArea.cs
- MenuAutomationPeer.cs
- RequestCacheManager.cs