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
- XPathPatternParser.cs
- ExpressionNormalizer.cs
- InvokeGenerator.cs
- XmlNode.cs
- Signature.cs
- OdbcConnectionFactory.cs
- CreateUserErrorEventArgs.cs
- EventNotify.cs
- Typeface.cs
- Zone.cs
- DispatchWrapper.cs
- ScriptControl.cs
- HMACSHA512.cs
- ThicknessAnimation.cs
- CorrelationManager.cs
- JavaScriptObjectDeserializer.cs
- ContainerVisual.cs
- HotSpot.cs
- SqlRecordBuffer.cs
- CommandBindingCollection.cs
- SmtpLoginAuthenticationModule.cs
- TextTrailingWordEllipsis.cs
- NetworkInformationPermission.cs
- HashCoreRequest.cs
- PropertyPathWorker.cs
- CodeTypeParameterCollection.cs
- ObjectQuery_EntitySqlExtensions.cs
- SharedConnectionInfo.cs
- PropertyMetadata.cs
- SiteOfOriginContainer.cs
- SharedPerformanceCounter.cs
- StyleTypedPropertyAttribute.cs
- ComAdminWrapper.cs
- CursorConverter.cs
- Size3DValueSerializer.cs
- baseaxisquery.cs
- GlyphTypeface.cs
- XmlSerializerNamespaces.cs
- XmlValidatingReader.cs
- CheckBoxField.cs
- StrokeCollection.cs
- CommonObjectSecurity.cs
- OLEDB_Enum.cs
- shaperfactoryquerycacheentry.cs
- CLSCompliantAttribute.cs
- CqlGenerator.cs
- Storyboard.cs
- DictionaryTraceRecord.cs
- PublisherMembershipCondition.cs
- TextRunCache.cs
- SByte.cs
- AttributeUsageAttribute.cs
- AbstractExpressions.cs
- SolidBrush.cs
- FontWeight.cs
- TreeViewImageIndexConverter.cs
- XamlNamespaceHelper.cs
- XmlNodeReader.cs
- MemberDescriptor.cs
- ValidatedControlConverter.cs
- BuildProvider.cs
- MembershipPasswordException.cs
- DesignerTextViewAdapter.cs
- ActiveDocumentEvent.cs
- COM2Enum.cs
- XPathNodeInfoAtom.cs
- CustomAttributeBuilder.cs
- ApplicationServiceHelper.cs
- FormsIdentity.cs
- ImageIndexConverter.cs
- StyleSheetRefUrlEditor.cs
- ProtocolElement.cs
- PositiveTimeSpanValidator.cs
- FragmentQuery.cs
- LayoutUtils.cs
- ClientTargetCollection.cs
- MaterialGroup.cs
- GeneralTransform3D.cs
- UrlMappingCollection.cs
- EntityUtil.cs
- EncoderFallback.cs
- IBuiltInEvidence.cs
- ClipboardData.cs
- LayoutEngine.cs
- RoleManagerEventArgs.cs
- ConsoleCancelEventArgs.cs
- Memoizer.cs
- ReferenceEqualityComparer.cs
- MessageSmuggler.cs
- CollectionView.cs
- SerTrace.cs
- X509AsymmetricSecurityKey.cs
- TextDpi.cs
- WindowInteractionStateTracker.cs
- PropertyGridEditorPart.cs
- SQLBinary.cs
- ColorConverter.cs
- HwndHost.cs
- BitmapPalettes.cs
- EncryptedKey.cs