Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Dispatcher / CodeGenerator.cs / 1 / CodeGenerator.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
// ***NOTE*** If this code is changed, make corresponding changes in System.Runtime.Serialization.CodeGenerator also
namespace System.ServiceModel.Dispatcher
{
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;
using System.ServiceModel.Diagnostics;
///
/// Critical - generates IL into an ILGenerator that was created under an Assert
/// generated IL must be correct and must not subvert the type system
///
[SecurityCritical(SecurityCriticalScope.Everything)]
internal class CodeGenerator
{
static MethodInfo getTypeFromHandle;
static MethodInfo stringConcat2;
static MethodInfo objectToString;
static MethodInfo boxPointer;
static MethodInfo unboxPointer;
#if USE_REFEMIT
AssemblyBuilder assemblyBuilder;
ModuleBuilder moduleBuilder;
TypeBuilder typeBuilder;
static int typeCounter;
MethodBuilder methodBuilder;
#else
static Module SerializationModule = typeof(CodeGenerator).Module; // Can be replaced by different assembly with SkipVerification set to false
DynamicMethod dynamicMethod;
#if DEBUG
bool allowPrivateMemberAccess;
#endif
#endif
Type delegateType;
ILGenerator ilGen;
ArrayList argList;
Stack blockStack;
Label methodEndLabel;
Hashtable localNames;
int lineNo = 1;
enum CodeGenTrace {None, Save, Tron};
CodeGenTrace codeGenTrace;
internal CodeGenerator()
{
SourceSwitch codeGenSwitch = OperationInvokerTrace.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;
}
static MethodInfo GetTypeFromHandle
{
get
{
if (getTypeFromHandle == null)
getTypeFromHandle = typeof(Type).GetMethod("GetTypeFromHandle");
return getTypeFromHandle;
}
}
static MethodInfo StringConcat2
{
get
{
if (stringConcat2 == null)
stringConcat2 = typeof(string).GetMethod("Concat", new Type[] { typeof(string), typeof(string) });
return stringConcat2;
}
}
static MethodInfo ObjectToString
{
get
{
if (objectToString == null)
objectToString = typeof(object).GetMethod("ToString", new Type[0]);
return objectToString;
}
}
static MethodInfo BoxPointer
{
get
{
if (boxPointer == null)
boxPointer = typeof(Pointer).GetMethod("Box");
return boxPointer;
}
}
static MethodInfo UnboxPointer
{
get
{
if (unboxPointer == null)
unboxPointer = typeof(Pointer).GetMethod("Unbox");
return unboxPointer;
}
}
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();
#if DEBUG
this.allowPrivateMemberAccess = allowPrivateMemberAccess;
#endif
#endif
this.methodEndLabel = ilGen.DefineLabel();
this.blockStack = new Stack();
this.argList = new ArrayList();
for (int i=0;i");
Else();
Call(ObjectToString);
EndIf();
}
}
internal void Concat2()
{
Call(StringConcat2);
}
internal void LoadZeroValueIntoLocal(Type type, LocalBuilder local)
{
if (type.IsValueType)
{
switch (Type.GetTypeCode(type))
{
case TypeCode.Boolean:
case TypeCode.Char:
case TypeCode.SByte:
case TypeCode.Byte:
case TypeCode.Int16:
case TypeCode.UInt16:
case TypeCode.Int32:
case TypeCode.UInt32:
ilGen.Emit(OpCodes.Ldc_I4_0);
Store(local);
break;
case TypeCode.Int64:
case TypeCode.UInt64:
ilGen.Emit(OpCodes.Ldc_I4_0);
ilGen.Emit(OpCodes.Conv_I8);
Store(local);
break;
case TypeCode.Single:
ilGen.Emit(OpCodes.Ldc_R4, 0.0F);
Store(local);
break;
case TypeCode.Double:
ilGen.Emit(OpCodes.Ldc_R8, 0.0);
Store(local);
break;
case TypeCode.Decimal:
case TypeCode.DateTime:
default:
LoadAddress(local);
InitObj(type);
break;
}
}
else
{
Load(null);
Store(local);
}
}
}
internal class ArgBuilder
{
internal int Index;
internal Type ArgType;
internal ArgBuilder(int index, Type argType)
{
this.Index = index;
this.ArgType = argType;
}
}
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;
}
}
}
}
// 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
- PeerEndPoint.cs
- ColumnMapTranslator.cs
- HttpRuntime.cs
- SelectionRange.cs
- InvokePattern.cs
- DocumentOrderComparer.cs
- CodeTryCatchFinallyStatement.cs
- XmlTextReaderImpl.cs
- DefaultTraceListener.cs
- VectorCollectionConverter.cs
- TrustLevelCollection.cs
- ControlBindingsCollection.cs
- AppSettings.cs
- ListControlBuilder.cs
- SubpageParagraph.cs
- ProtectedUri.cs
- Fx.cs
- WorkflowOwnershipException.cs
- WindowsEditBox.cs
- Attributes.cs
- WebHostedComPlusServiceHost.cs
- RoutedEventArgs.cs
- OrderByQueryOptionExpression.cs
- ServiceRouteHandler.cs
- DataGridViewMethods.cs
- BrowserDefinition.cs
- CalendarSelectionChangedEventArgs.cs
- MenuStrip.cs
- FileDialog_Vista.cs
- LogPolicy.cs
- BinaryParser.cs
- ThaiBuddhistCalendar.cs
- MenuCommands.cs
- IResourceProvider.cs
- ListViewInsertionMark.cs
- ToolStripSeparator.cs
- ProvidersHelper.cs
- HScrollProperties.cs
- WebBrowserUriTypeConverter.cs
- TextTrailingCharacterEllipsis.cs
- BaseProcessor.cs
- FixedDocumentPaginator.cs
- GeneralTransform2DTo3D.cs
- FixedSOMFixedBlock.cs
- PolyQuadraticBezierSegment.cs
- WaitForChangedResult.cs
- NullReferenceException.cs
- QueryResponse.cs
- TextTreeFixupNode.cs
- MailDefinition.cs
- ParameterCollection.cs
- TextBox.cs
- ClientFormsAuthenticationCredentials.cs
- XmlSchemaObjectTable.cs
- ModelVisual3D.cs
- TreeNodeBindingCollection.cs
- SimpleBitVector32.cs
- MetadataUtil.cs
- fixedPageContentExtractor.cs
- VerticalAlignConverter.cs
- RadioButtonDesigner.cs
- ToolStripSplitStackLayout.cs
- ConfigurationElementCollection.cs
- MatrixStack.cs
- OuterGlowBitmapEffect.cs
- AutomationProperty.cs
- FileSecurity.cs
- _OverlappedAsyncResult.cs
- XmlSchemas.cs
- FactoryMaker.cs
- Canvas.cs
- dataprotectionpermissionattribute.cs
- BaseDataList.cs
- MessageContractImporter.cs
- TransformedBitmap.cs
- TextDecoration.cs
- ScrollBarRenderer.cs
- RegistrySecurity.cs
- ActivityMarkupSerializationProvider.cs
- Dump.cs
- ReadOnlyDictionary.cs
- DocumentReferenceCollection.cs
- FileDialog_Vista_Interop.cs
- HasCopySemanticsAttribute.cs
- MaskDesignerDialog.cs
- PersistChildrenAttribute.cs
- FlowDocumentReader.cs
- XmlParser.cs
- QuaternionAnimationBase.cs
- XmlSchemaInclude.cs
- EmptyElement.cs
- BitmapDownload.cs
- BindingManagerDataErrorEventArgs.cs
- XmlSchemaAll.cs
- MimeParameters.cs
- SqlDataSourceCommandEventArgs.cs
- DesignerDataTableBase.cs
- Vertex.cs
- UriGenerator.cs
- MinimizableAttributeTypeConverter.cs