Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / Activities / Common / CompilerHelpers.cs / 1305376 / CompilerHelpers.cs
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
// WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
// THE ENTIRE RISK OF USE OR RESULTS IN CONNECTION WITH THE USE OF THIS CODE
// AND INFORMATION REMAINS WITH THE USER.
//
/**********************************************************************
* NOTE: A copy of this file exists at: WF\Common\Shared
* The two files must be kept in [....]. Any change made here must also
* be made to WF\Common\Shared\CompilerHelpers.cs
*********************************************************************/
namespace System.Workflow.Activities.Common
{
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Workflow.ComponentModel;
using Microsoft.CSharp;
using Microsoft.VisualBasic;
using System.Reflection;
using Microsoft.Win32;
using System.Security;
using System.ComponentModel;
using System.IO;
using System.Diagnostics.CodeAnalysis;
using System.Workflow.ComponentModel.Compiler;
internal enum SupportedLanguages
{
VB,
CSharp
}
internal static class CompilerHelpers
{
private const string CompilerVersionKeyword = "CompilerVersion";
private static Dictionary> providers = null;
private static object providersLock = new object();
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal static CodeDomProvider CreateCodeProviderInstance(Type type)
{
return CreateCodeProviderInstance(type, string.Empty);
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal static CodeDomProvider CreateCodeProviderInstance(Type type, string compilerVersion)
{
CodeDomProvider provider = null;
if (string.IsNullOrEmpty(compilerVersion))
{
if (type == typeof(CSharpCodeProvider))
provider = new CSharpCodeProvider();
else if (type == typeof(VBCodeProvider))
provider = new VBCodeProvider();
else
provider = (CodeDomProvider)Activator.CreateInstance(type);
}
else
{
//otherwise pass the compiler version parameter into it
Dictionary options = new Dictionary();
options.Add(CompilerHelpers.CompilerVersionKeyword, compilerVersion);
provider = (CodeDomProvider)Activator.CreateInstance(type, new object[] { options });
}
return provider;
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
static CodeDomProvider GetCodeProviderInstance(Type type, string compilerVersion)
{
CodeDomProvider provider;
lock (providersLock)
{
if (providers == null)
{
providers = new Dictionary>();
}
Dictionary typedProviders;
if (!providers.TryGetValue(type, out typedProviders))
{
typedProviders = new Dictionary();
providers.Add(type, typedProviders);
}
if (!typedProviders.TryGetValue(compilerVersion, out provider))
{
provider = CreateCodeProviderInstance(type, compilerVersion);
typedProviders.Add(compilerVersion, provider);
}
}
return provider;
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal static CodeDomProvider GetCodeDomProvider(SupportedLanguages language)
{
return CompilerHelpers.GetCodeDomProvider(language, string.Empty);
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal static CodeDomProvider GetCodeDomProvider(SupportedLanguages language, string compilerVersion)
{
if (language == SupportedLanguages.CSharp)
{
return GetCodeProviderInstance(typeof(CSharpCodeProvider), compilerVersion);
}
else
{
return GetCodeProviderInstance(typeof(VBCodeProvider), compilerVersion);
}
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal static SupportedLanguages GetSupportedLanguage(IServiceProvider serviceProvider)
{
SupportedLanguages supportedLanguage = SupportedLanguages.CSharp;
IWorkflowCompilerOptionsService workflowCompilerOptions = serviceProvider.GetService(typeof(IWorkflowCompilerOptionsService)) as IWorkflowCompilerOptionsService;
if (workflowCompilerOptions != null)
supportedLanguage = GetSupportedLanguage(workflowCompilerOptions.Language);
return supportedLanguage;
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal static SupportedLanguages GetSupportedLanguage(string language)
{
SupportedLanguages supportedLanguage = SupportedLanguages.CSharp;
if (!String.IsNullOrEmpty(language) &&
(string.Compare(language, "VB", StringComparison.OrdinalIgnoreCase) == 0 ||
string.Compare(language, "VisualBasic", StringComparison.OrdinalIgnoreCase) == 0))
supportedLanguage = SupportedLanguages.VB;
return supportedLanguage;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
// WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
// THE ENTIRE RISK OF USE OR RESULTS IN CONNECTION WITH THE USE OF THIS CODE
// AND INFORMATION REMAINS WITH THE USER.
//
/**********************************************************************
* NOTE: A copy of this file exists at: WF\Common\Shared
* The two files must be kept in [....]. Any change made here must also
* be made to WF\Common\Shared\CompilerHelpers.cs
*********************************************************************/
namespace System.Workflow.Activities.Common
{
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Workflow.ComponentModel;
using Microsoft.CSharp;
using Microsoft.VisualBasic;
using System.Reflection;
using Microsoft.Win32;
using System.Security;
using System.ComponentModel;
using System.IO;
using System.Diagnostics.CodeAnalysis;
using System.Workflow.ComponentModel.Compiler;
internal enum SupportedLanguages
{
VB,
CSharp
}
internal static class CompilerHelpers
{
private const string CompilerVersionKeyword = "CompilerVersion";
private static Dictionary> providers = null;
private static object providersLock = new object();
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal static CodeDomProvider CreateCodeProviderInstance(Type type)
{
return CreateCodeProviderInstance(type, string.Empty);
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal static CodeDomProvider CreateCodeProviderInstance(Type type, string compilerVersion)
{
CodeDomProvider provider = null;
if (string.IsNullOrEmpty(compilerVersion))
{
if (type == typeof(CSharpCodeProvider))
provider = new CSharpCodeProvider();
else if (type == typeof(VBCodeProvider))
provider = new VBCodeProvider();
else
provider = (CodeDomProvider)Activator.CreateInstance(type);
}
else
{
//otherwise pass the compiler version parameter into it
Dictionary options = new Dictionary();
options.Add(CompilerHelpers.CompilerVersionKeyword, compilerVersion);
provider = (CodeDomProvider)Activator.CreateInstance(type, new object[] { options });
}
return provider;
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
static CodeDomProvider GetCodeProviderInstance(Type type, string compilerVersion)
{
CodeDomProvider provider;
lock (providersLock)
{
if (providers == null)
{
providers = new Dictionary>();
}
Dictionary typedProviders;
if (!providers.TryGetValue(type, out typedProviders))
{
typedProviders = new Dictionary();
providers.Add(type, typedProviders);
}
if (!typedProviders.TryGetValue(compilerVersion, out provider))
{
provider = CreateCodeProviderInstance(type, compilerVersion);
typedProviders.Add(compilerVersion, provider);
}
}
return provider;
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal static CodeDomProvider GetCodeDomProvider(SupportedLanguages language)
{
return CompilerHelpers.GetCodeDomProvider(language, string.Empty);
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal static CodeDomProvider GetCodeDomProvider(SupportedLanguages language, string compilerVersion)
{
if (language == SupportedLanguages.CSharp)
{
return GetCodeProviderInstance(typeof(CSharpCodeProvider), compilerVersion);
}
else
{
return GetCodeProviderInstance(typeof(VBCodeProvider), compilerVersion);
}
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal static SupportedLanguages GetSupportedLanguage(IServiceProvider serviceProvider)
{
SupportedLanguages supportedLanguage = SupportedLanguages.CSharp;
IWorkflowCompilerOptionsService workflowCompilerOptions = serviceProvider.GetService(typeof(IWorkflowCompilerOptionsService)) as IWorkflowCompilerOptionsService;
if (workflowCompilerOptions != null)
supportedLanguage = GetSupportedLanguage(workflowCompilerOptions.Language);
return supportedLanguage;
}
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal static SupportedLanguages GetSupportedLanguage(string language)
{
SupportedLanguages supportedLanguage = SupportedLanguages.CSharp;
if (!String.IsNullOrEmpty(language) &&
(string.Compare(language, "VB", StringComparison.OrdinalIgnoreCase) == 0 ||
string.Compare(language, "VisualBasic", StringComparison.OrdinalIgnoreCase) == 0))
supportedLanguage = SupportedLanguages.VB;
return supportedLanguage;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Geometry.cs
- ObjectPersistData.cs
- SettingsPropertyWrongTypeException.cs
- ProfileProvider.cs
- URL.cs
- FormParameter.cs
- objectresult_tresulttype.cs
- ExpandoClass.cs
- ValueExpressions.cs
- WebPartDescriptionCollection.cs
- BaseProcessProtocolHandler.cs
- DeviceSpecificDialogCachedState.cs
- CellRelation.cs
- EdmProperty.cs
- Version.cs
- AlignmentYValidation.cs
- SequentialWorkflowRootDesigner.cs
- CurrentChangingEventArgs.cs
- VariableQuery.cs
- AttributeParameterInfo.cs
- COM2EnumConverter.cs
- OracleConnectionFactory.cs
- IntSecurity.cs
- QueryStringParameter.cs
- RbTree.cs
- COM2TypeInfoProcessor.cs
- SettingsProperty.cs
- ExtendedPropertiesHandler.cs
- NavigationCommands.cs
- XmlRootAttribute.cs
- PtsContext.cs
- SqlDataSourceCache.cs
- DataGridViewCellStyleChangedEventArgs.cs
- NTAccount.cs
- IPCCacheManager.cs
- MemoryRecordBuffer.cs
- ContentDisposition.cs
- IdleTimeoutMonitor.cs
- RootNamespaceAttribute.cs
- NumberFunctions.cs
- SchemaType.cs
- Message.cs
- AccessControlList.cs
- RegisteredExpandoAttribute.cs
- RuleEngine.cs
- EnumCodeDomSerializer.cs
- HuffmanTree.cs
- DataGridGeneralPage.cs
- EntityDesignerBuildProvider.cs
- ExtensibleSyndicationObject.cs
- TypographyProperties.cs
- SingleObjectCollection.cs
- MILUtilities.cs
- HttpHeaderCollection.cs
- UdpChannelFactory.cs
- CodeTypeMember.cs
- UpdateCompiler.cs
- TreeNodeConverter.cs
- SecurityPermission.cs
- NestPullup.cs
- SiteMapProvider.cs
- DataBinder.cs
- MultiAsyncResult.cs
- XmlWrappingReader.cs
- UIElement.cs
- OLEDB_Enum.cs
- Rules.cs
- FormatterServices.cs
- SequentialOutput.cs
- IPAddress.cs
- Transform3DCollection.cs
- Win32.cs
- MethodToken.cs
- Simplifier.cs
- DbgUtil.cs
- BitmapVisualManager.cs
- MenuBindingsEditor.cs
- OptimisticConcurrencyException.cs
- XmlQualifiedNameTest.cs
- FixedSOMElement.cs
- AddInDeploymentState.cs
- XmlNullResolver.cs
- TextServicesCompartmentContext.cs
- AutoResizedEvent.cs
- ProcessHostConfigUtils.cs
- MarkupCompilePass1.cs
- RequiredFieldValidator.cs
- EventProviderWriter.cs
- MsiStyleLogWriter.cs
- PropertyTabAttribute.cs
- EasingKeyFrames.cs
- SQLDateTime.cs
- TemplateBuilder.cs
- DbConnectionOptions.cs
- dataprotectionpermissionattribute.cs
- EntityDataSourceQueryBuilder.cs
- RichTextBoxAutomationPeer.cs
- StreamInfo.cs
- Expressions.cs
- FontUnitConverter.cs