Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / Serialization / System / Runtime / Serialization / CodeGenerator.cs / 3 / CodeGenerator.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- // ***NOTE*** If this code is changed, make corresponding changes in System.ServiceModel.CodeGenerator also namespace System.Runtime.Serialization { using System; using System.Collections; using System.Globalization; using System.Xml; using System.Reflection; using System.Reflection.Emit; using System.IO; using System.Security; using System.Security.Permissions; using System.Diagnostics; internal class CodeGenerator { ////// Critical - Static fields are marked SecurityCritical or readonly to prevent /// data from being modified or leaked to other components in appdomain. /// [SecurityCritical] static MethodInfo getTypeFromHandle; static MethodInfo GetTypeFromHandle { ////// Critical - fetches the critical getTypeFromHandle field /// Safe - get-only properties only needs to be protected for write; initialized in getter if null. /// [SecurityCritical, SecurityTreatAsSafe] get { if (getTypeFromHandle == null) getTypeFromHandle = typeof(Type).GetMethod("GetTypeFromHandle"); return getTypeFromHandle; } } ////// Critical - Static fields are marked SecurityCritical or readonly to prevent /// data from being modified or leaked to other components in appdomain. /// [SecurityCritical] static MethodInfo stringFormat; static MethodInfo StringFormat { ////// Critical - fetches the critical stringFormat field /// Safe - get-only properties only needs to be protected for write; initialized in getter if null. /// [SecurityCritical, SecurityTreatAsSafe] get { if (stringFormat == null) stringFormat = typeof(string).GetMethod("Format", new Type[] { typeof(string), typeof(object[]) }); return stringFormat; } } ////// Critical - Static fields are marked SecurityCritical or readonly to prevent /// data from being modified or leaked to other components in appdomain. /// [SecurityCritical] static MethodInfo stringConcat2; static MethodInfo StringConcat2 { ////// Critical - fetches the critical stringConcat2 field /// Safe - get-only properties only needs to be protected for write; initialized in getter if null. /// [SecurityCritical, SecurityTreatAsSafe] get { if (stringConcat2 == null) stringConcat2 = typeof(string).GetMethod("Concat", new Type[] { typeof(string), typeof(string) }); return stringConcat2; } } ////// Critical - Static fields are marked SecurityCritical or readonly to prevent /// data from being modified or leaked to other components in appdomain. /// [SecurityCritical] static MethodInfo stringConcat3; static MethodInfo StringConcat3 { ////// Critical - fetches the critical stringConcat3 field /// Safe - get-only properties only needs to be protected for write; initialized in getter if null. /// [SecurityCritical, SecurityTreatAsSafe] get { if (stringConcat3 == null) stringConcat3 = typeof(string).GetMethod("Concat", new Type[] { typeof(string), typeof(string), typeof(string) }); return stringConcat3; } } ////// Critical - Static fields are marked SecurityCritical or readonly to prevent /// data from being modified or leaked to other components in appdomain. /// [SecurityCritical] static MethodInfo objectToString; static MethodInfo ObjectToString { ////// Critical - fetches the critical objectToString field /// Safe - get-only properties only needs to be protected for write; initialized in getter if null. /// [SecurityCritical, SecurityTreatAsSafe] get { if (objectToString == null) objectToString = typeof(object).GetMethod("ToString", new Type[0]); return objectToString; } } ////// Critical - Static fields are marked SecurityCritical or readonly to prevent /// data from being modified or leaked to other components in appdomain. /// [SecurityCritical] static MethodInfo objectEquals; static MethodInfo ObjectEquals { ////// Critical - fetches the critical objectEquals field /// Safe - get-only properties only needs to be protected for write; initialized in getter if null. /// [SecurityCritical, SecurityTreatAsSafe] get { if (objectEquals == null) objectEquals = Globals.TypeOfObject.GetMethod("Equals", BindingFlags.Public | BindingFlags.Static); return objectEquals; } } ////// Critical - Static fields are marked SecurityCritical or readonly to prevent /// data from being modified or leaked to other components in appdomain. /// [SecurityCritical] static MethodInfo arraySetValue; static MethodInfo ArraySetValue { ////// Critical - fetches the critical arraySetValue field /// Safe - get-only properties only needs to be protected for write; initialized in getter if null. /// [SecurityCritical, SecurityTreatAsSafe] get { if (arraySetValue == null) arraySetValue = typeof(Array).GetMethod("SetValue", new Type[] { typeof(object), typeof(int) }); return arraySetValue; } } Type delegateType; #if USE_REFEMIT AssemblyBuilder assemblyBuilder; ModuleBuilder moduleBuilder; TypeBuilder typeBuilder; static int typeCounter; MethodBuilder methodBuilder; #else ////// Critical - Static fields are marked SecurityCritical or readonly to prevent /// data from being modified or leaked to other components in appdomain. /// [SecurityCritical] static Module serializationModule; static Module SerializationModule { ////// Critical - fetches the critical serializationModule field /// Safe - get-only properties only needs to be protected for write; initialized in getter if null. /// [SecurityCritical, SecurityTreatAsSafe] get { if (serializationModule == null) { serializationModule = typeof(CodeGenerator).Module; // could to be replaced by different dll that has SkipVerification set to false } return serializationModule; } } DynamicMethod dynamicMethod; #endif ILGenerator ilGen; ArrayList argList; Stack blockStack; Label methodEndLabel; LocalBuilder stringFormatArray; Hashtable localNames; int lineNo = 1; enum CodeGenTrace {None, Save, Tron}; CodeGenTrace codeGenTrace; internal CodeGenerator() { SourceSwitch codeGenSwitch = SerializationTrace.CodeGenerationSwitch; if ((codeGenSwitch.Level & SourceLevels.Verbose) == SourceLevels.Verbose) codeGenTrace = CodeGenTrace.Tron; else if ((codeGenSwitch.Level & SourceLevels.Information) == SourceLevels.Information) codeGenTrace = CodeGenTrace.Save; else codeGenTrace = CodeGenTrace.None; } #if !USE_REFEMIT internal void BeginMethod(DynamicMethod dynamicMethod, Type delegateType, string methodName, Type[] argTypes, bool allowPrivateMemberAccess) { this.dynamicMethod = dynamicMethod; this.ilGen = this.dynamicMethod.GetILGenerator(); this.delegateType = delegateType; InitILGeneration(methodName, argTypes); } #endif internal void BeginMethod(string methodName, Type delegateType, bool allowPrivateMemberAccess) { MethodInfo signature = delegateType.GetMethod("Invoke"); ParameterInfo[] parameters = signature.GetParameters(); Type[] paramTypes = new Type[parameters.Length]; for (int i = 0; i < parameters.Length; i++) paramTypes[i] = parameters[i].ParameterType; BeginMethod(signature.ReturnType, methodName, paramTypes, allowPrivateMemberAccess); this.delegateType = delegateType; } void BeginMethod(Type returnType, string methodName, Type[] argTypes, bool allowPrivateMemberAccess) { #if USE_REFEMIT string typeName = "Type" + (typeCounter++); InitAssemblyBuilder(typeName + "." + methodName); this.typeBuilder = moduleBuilder.DefineType(typeName, TypeAttributes.Public); this.methodBuilder = typeBuilder.DefineMethod(methodName, MethodAttributes.Public|MethodAttributes.Static, returnType, argTypes); this.ilGen = this.methodBuilder.GetILGenerator(); #else this.dynamicMethod = new DynamicMethod(methodName, returnType, argTypes, SerializationModule, allowPrivateMemberAccess); this.ilGen = this.dynamicMethod.GetILGenerator(); #endif InitILGeneration(methodName, argTypes); } void InitILGeneration(string methodName, Type[] argTypes) { this.methodEndLabel = ilGen.DefineLabel(); this.blockStack = new Stack(); this.argList = new ArrayList(); for (int i=0;i"); Else(); if (type.IsArray) { LocalBuilder arrayVar = DeclareLocal(type, "arrayVar"); Store(arrayVar); Load("{ "); LocalBuilder arrayValueString = DeclareLocal(typeof(string), "arrayValueString"); Store(arrayValueString); LocalBuilder i = DeclareLocal(typeof(int), "i"); For(i, 0, arrayVar); Load(arrayValueString); LoadArrayElement(arrayVar, i); ToString(arrayVar.LocalType.GetElementType()); Load(", "); Concat3(); Store(arrayValueString); EndFor(); Load(arrayValueString); Load("}"); Concat2(); } else Call(ObjectToString); EndIf(); } } internal void Concat2() { Call(StringConcat2); } internal void Concat3() { Call(StringConcat3); } internal Label[] Switch(int labelCount) { SwitchState switchState = new SwitchState(DefineLabel(), DefineLabel()); Label[] caseLabels = new Label[labelCount]; for (int i=0;i 0; return !hasAptca; } void DemandFullTrust() { fullTrustDemanded = true; /* if (codeGenTrace != CodeGenTrace.None) EmitSourceComment("DemandFullTrust() {"); Ldc(PermissionState.Unrestricted); New(permissionSetCtor); Call(permissionSetDemand); if (codeGenTrace != CodeGenTrace.None) EmitSourceComment("}"); */ } static bool IsProtectedWithSecurity(MethodBase method) { return false; //return (method.Attributes & MethodAttributes.HasSecurity) != 0; } #endif } internal class ArgBuilder { internal int Index; internal Type ArgType; internal ArgBuilder(int index, Type argType) { this.Index = index; this.ArgType = argType; } } internal class ForState { LocalBuilder indexVar; Label beginLabel; Label testLabel; Label endLabel; bool requiresEndLabel; object end; internal ForState(LocalBuilder indexVar, Label beginLabel, Label testLabel, object end) { this.indexVar = indexVar; this.beginLabel = beginLabel; this.testLabel = testLabel; this.end = end; } internal LocalBuilder Index { get { return indexVar; } } internal Label BeginLabel { get { return beginLabel; } } internal Label TestLabel { get { return testLabel; } } internal Label EndLabel { get { return endLabel; } set { endLabel = value; } } internal bool RequiresEndLabel { get { return requiresEndLabel; } set { requiresEndLabel = value; } } internal object End { get { return end; } } } internal enum Cmp { LessThan, EqualTo, LessThanOrEqualTo, GreaterThan, NotEqualTo, GreaterThanOrEqualTo } internal class IfState { Label elseBegin; Label endIf; internal Label EndIf { get { return this.endIf; } set { this.endIf= value; } } internal Label ElseBegin { get { return this.elseBegin; } set { this.elseBegin= value; } } } #if NotUsed internal class BitFlagsGenerator { LocalBuilder[] locals; CodeGenerator ilg; int bitCount; internal 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 > 3; } static byte GetBitValue(int bitIndex) { return (byte)(1 << (bitIndex & 7)); } } #endif internal class SwitchState { Label defaultLabel; Label endOfSwitchLabel; bool defaultDefined; internal SwitchState(Label defaultLabel, Label endOfSwitchLabel) { this.defaultLabel = defaultLabel; this.endOfSwitchLabel = endOfSwitchLabel; this.defaultDefined = false; } internal Label DefaultLabel { get { return defaultLabel; } } internal Label EndOfSwitchLabel { get { return endOfSwitchLabel; } } internal bool DefaultDefined { get { return defaultDefined; } set { defaultDefined = value; } } } } // 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
- IsolatedStoragePermission.cs
- PagedControl.cs
- LazyTextWriterCreator.cs
- RegistryKey.cs
- ObjectListTitleAttribute.cs
- ContractMapping.cs
- StateValidator.cs
- DataServiceRequest.cs
- ComplexTypeEmitter.cs
- RegexEditorDialog.cs
- DelegateBodyWriter.cs
- BlurBitmapEffect.cs
- DesignerActionKeyboardBehavior.cs
- Peer.cs
- MediaCommands.cs
- RawKeyboardInputReport.cs
- ListViewItemSelectionChangedEvent.cs
- CmsInterop.cs
- LinkUtilities.cs
- ClientTargetCollection.cs
- ElementAction.cs
- EntityContainer.cs
- EdmTypeAttribute.cs
- DataGridViewDataErrorEventArgs.cs
- EmbeddedMailObject.cs
- sqlnorm.cs
- ListBoxDesigner.cs
- DocumentOrderQuery.cs
- StorageEndPropertyMapping.cs
- ListBindableAttribute.cs
- OpCodes.cs
- ButtonBaseAutomationPeer.cs
- SecureEnvironment.cs
- DoWorkEventArgs.cs
- SmiTypedGetterSetter.cs
- DesignerObjectListAdapter.cs
- VariableQuery.cs
- RadialGradientBrush.cs
- PriorityRange.cs
- TemplateBindingExtensionConverter.cs
- Point3D.cs
- SoapUnknownHeader.cs
- AsyncOperationManager.cs
- SqlClientMetaDataCollectionNames.cs
- EntityModelSchemaGenerator.cs
- GridViewRowPresenterBase.cs
- IndexedString.cs
- DomainConstraint.cs
- ConfigXmlSignificantWhitespace.cs
- MenuItemBindingCollection.cs
- PackageRelationshipSelector.cs
- PartManifestEntry.cs
- Console.cs
- DataColumn.cs
- ClosableStream.cs
- ClientApiGenerator.cs
- QueryGeneratorBase.cs
- BamlCollectionHolder.cs
- DataGridViewRowPostPaintEventArgs.cs
- complextypematerializer.cs
- InputElement.cs
- ListControlBoundActionList.cs
- DecryptRequest.cs
- StreamReader.cs
- ToolStripItemRenderEventArgs.cs
- DataGridViewRowEventArgs.cs
- InitializingNewItemEventArgs.cs
- OracleSqlParser.cs
- AppModelKnownContentFactory.cs
- FilteredReadOnlyMetadataCollection.cs
- TextEndOfParagraph.cs
- ComponentChangingEvent.cs
- DataException.cs
- SchemaContext.cs
- EventLog.cs
- ToolStripTextBox.cs
- SapiRecoInterop.cs
- TextEffectResolver.cs
- BuildManager.cs
- DispatchChannelSink.cs
- _HeaderInfo.cs
- PrePostDescendentsWalker.cs
- CompositeActivityValidator.cs
- Utils.cs
- DateTimeFormatInfoScanner.cs
- DataGridViewRowEventArgs.cs
- BaseTemplateBuildProvider.cs
- WhiteSpaceTrimStringConverter.cs
- TableItemProviderWrapper.cs
- XmlDataSourceView.cs
- ViewCellSlot.cs
- MDIWindowDialog.cs
- ChunkedMemoryStream.cs
- XmlLangPropertyAttribute.cs
- OdbcConnection.cs
- RuntimeResourceSet.cs
- _DigestClient.cs
- QueryReaderSettings.cs
- ConfigErrorGlyph.cs
- ACE.cs