Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / Common / AuthoringOM / Compiler / TypeSystem / CodeDomLoader.cs / 1305376 / CodeDomLoader.cs
namespace System.Workflow.ComponentModel.Compiler
{
using System;
using System.CodeDom;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Diagnostics;
internal class CodeDomLoader: IDisposable
{
private TypeProvider typeProvider = null;
private CodeCompileUnit codeCompileUnit = null;
private List types = new List();
internal CodeDomLoader(TypeProvider typeProvider, CodeCompileUnit codeCompileUnit)
{
this.typeProvider = typeProvider;
this.codeCompileUnit = codeCompileUnit;
AddTypes();
}
internal void Refresh(EventHandler refresher)
{
RemoveTypes();
refresher(this.typeProvider, EventArgs.Empty);
AddTypes();
}
private void AddTypes()
{
if (this.typeProvider != null && this.types != null)
{
this.types.Clear();
foreach (CodeNamespace codeNamespace in this.codeCompileUnit.Namespaces)
{
foreach (CodeTypeDeclaration codeTypeDeclaration in codeNamespace.Types)
{
// Look for partial type
string typename = Helper.EnsureTypeName(codeTypeDeclaration.Name);
if(codeNamespace.Name.Length > 0)
typename = (Helper.EnsureTypeName(codeNamespace.Name) + "." + typename);
DesignTimeType partialType = this.typeProvider.GetType(typename, false) as DesignTimeType;
if ( partialType == null )
{
partialType = new DesignTimeType(null, codeTypeDeclaration.Name, codeNamespace.Imports, codeNamespace.Name, this.typeProvider);
this.types.Add(partialType);
this.typeProvider.AddType(partialType);
}
partialType.AddCodeTypeDeclaration(codeTypeDeclaration);
}
}
Queue nestedQueue = new Queue(this.types);
while (nestedQueue.Count != 0)
{
Type type = nestedQueue.Dequeue() as Type;
if(type.DeclaringType != null)
this.types.Add(type);
foreach (Type nestedType2 in type.GetNestedTypes(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
nestedQueue.Enqueue(nestedType2);
}
}
}
private void RemoveTypes()
{
if (this.typeProvider != null && this.types != null)
{
this.typeProvider.RemoveTypes(this.types.ToArray());
this.types.Clear();
}
}
#region IDisposable Members
public void Dispose()
{
RemoveTypes();
this.typeProvider = null;
this.types = null;
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
namespace System.Workflow.ComponentModel.Compiler
{
using System;
using System.CodeDom;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Diagnostics;
internal class CodeDomLoader: IDisposable
{
private TypeProvider typeProvider = null;
private CodeCompileUnit codeCompileUnit = null;
private List types = new List();
internal CodeDomLoader(TypeProvider typeProvider, CodeCompileUnit codeCompileUnit)
{
this.typeProvider = typeProvider;
this.codeCompileUnit = codeCompileUnit;
AddTypes();
}
internal void Refresh(EventHandler refresher)
{
RemoveTypes();
refresher(this.typeProvider, EventArgs.Empty);
AddTypes();
}
private void AddTypes()
{
if (this.typeProvider != null && this.types != null)
{
this.types.Clear();
foreach (CodeNamespace codeNamespace in this.codeCompileUnit.Namespaces)
{
foreach (CodeTypeDeclaration codeTypeDeclaration in codeNamespace.Types)
{
// Look for partial type
string typename = Helper.EnsureTypeName(codeTypeDeclaration.Name);
if(codeNamespace.Name.Length > 0)
typename = (Helper.EnsureTypeName(codeNamespace.Name) + "." + typename);
DesignTimeType partialType = this.typeProvider.GetType(typename, false) as DesignTimeType;
if ( partialType == null )
{
partialType = new DesignTimeType(null, codeTypeDeclaration.Name, codeNamespace.Imports, codeNamespace.Name, this.typeProvider);
this.types.Add(partialType);
this.typeProvider.AddType(partialType);
}
partialType.AddCodeTypeDeclaration(codeTypeDeclaration);
}
}
Queue nestedQueue = new Queue(this.types);
while (nestedQueue.Count != 0)
{
Type type = nestedQueue.Dequeue() as Type;
if(type.DeclaringType != null)
this.types.Add(type);
foreach (Type nestedType2 in type.GetNestedTypes(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
nestedQueue.Enqueue(nestedType2);
}
}
}
private void RemoveTypes()
{
if (this.typeProvider != null && this.types != null)
{
this.typeProvider.RemoveTypes(this.types.ToArray());
this.types.Clear();
}
}
#region IDisposable Members
public void Dispose()
{
RemoveTypes();
this.typeProvider = null;
this.types = null;
}
#endregion
}
}
// 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
- LookupBindingPropertiesAttribute.cs
- Funcletizer.cs
- Context.cs
- TreeNode.cs
- CodeTypeReference.cs
- NamedPermissionSet.cs
- AuthenticationException.cs
- ToolStripSeparatorRenderEventArgs.cs
- ClientScriptManager.cs
- SqlXml.cs
- IndentTextWriter.cs
- PostBackTrigger.cs
- DataGridParentRows.cs
- PointValueSerializer.cs
- UseAttributeSetsAction.cs
- LabelDesigner.cs
- _FtpDataStream.cs
- PenLineJoinValidation.cs
- FormsAuthenticationUserCollection.cs
- CodeMethodMap.cs
- ContainerFilterService.cs
- ConfigXmlCDataSection.cs
- InvalidComObjectException.cs
- IsolatedStorageFilePermission.cs
- FixedSOMTable.cs
- DrawingGroupDrawingContext.cs
- PasswordBox.cs
- PlanCompiler.cs
- PhysicalFontFamily.cs
- GroupBoxRenderer.cs
- GlobalizationAssembly.cs
- X509Utils.cs
- EllipseGeometry.cs
- LayoutEditorPart.cs
- HandleCollector.cs
- WindowPattern.cs
- EntityDataSourceContextCreatedEventArgs.cs
- ListBase.cs
- DataColumnChangeEvent.cs
- PerformanceCounterPermissionEntry.cs
- SiteMapDesignerDataSourceView.cs
- AutoGeneratedFieldProperties.cs
- StringResourceManager.cs
- SystemIPGlobalProperties.cs
- SetState.cs
- TableParaClient.cs
- SizeConverter.cs
- DataGridCell.cs
- AnnotationComponentChooser.cs
- QuadraticBezierSegment.cs
- LightweightCodeGenerator.cs
- httpapplicationstate.cs
- DesignDataSource.cs
- TextLineResult.cs
- TextParagraphCache.cs
- TickBar.cs
- BindingNavigator.cs
- ComponentCache.cs
- HtmlFormParameterReader.cs
- HtmlElementErrorEventArgs.cs
- Double.cs
- HTMLTextWriter.cs
- ExpressionBindings.cs
- XmlNavigatorStack.cs
- _TLSstream.cs
- QilStrConcatenator.cs
- XmlObjectSerializerWriteContext.cs
- DispatcherProcessingDisabled.cs
- ClipboardProcessor.cs
- TypeUtils.cs
- AppliesToBehaviorDecisionTable.cs
- SessionPageStateSection.cs
- _ServiceNameStore.cs
- AsyncStreamReader.cs
- sapiproxy.cs
- ListViewTableRow.cs
- SmtpAuthenticationManager.cs
- ProfileService.cs
- InheritanceContextChangedEventManager.cs
- UrlPath.cs
- Duration.cs
- StringConverter.cs
- SynchronizedRandom.cs
- IMembershipProvider.cs
- PickDesigner.xaml.cs
- StateMachineWorkflow.cs
- ColumnPropertiesGroup.cs
- VisualStyleTypesAndProperties.cs
- BuildProvider.cs
- QilPatternFactory.cs
- SmtpReplyReaderFactory.cs
- TrailingSpaceComparer.cs
- ExpressionPrefixAttribute.cs
- ISFClipboardData.cs
- OleDbConnectionFactory.cs
- TraceListener.cs
- SQLDecimal.cs
- X509Logo.cs
- WebPartConnectionsCancelVerb.cs
- XmlCharacterData.cs