Imported Upstream version 4.6.0.125

Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-08-03 10:59:49 +00:00
parent a569aebcfd
commit e79aa3c0ed
17047 changed files with 3137615 additions and 392334 deletions

View File

@ -0,0 +1,72 @@
namespace System.Workflow.ComponentModel.Compiler
{
using System;
using System.CodeDom;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Serialization;
#region Class ActivityCodeGenerator
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
public class ActivityCodeGenerator
{
public virtual void GenerateCode(CodeGenerationManager manager, object obj)
{
if (manager == null)
throw new ArgumentNullException("manager");
if (obj == null)
throw new ArgumentNullException("obj");
Activity activity = obj as Activity;
if (activity == null)
throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(Activity).FullName), "obj");
manager.Context.Push(activity);
// Generate code for all the member Binds.
Walker walker = new Walker();
walker.FoundProperty += delegate(Walker w, WalkerEventArgs args)
{
//
ActivityBind bindBase = args.CurrentValue as ActivityBind;
if (bindBase != null)
{
// push
if (args.CurrentProperty != null)
manager.Context.Push(args.CurrentProperty);
manager.Context.Push(args.CurrentPropertyOwner);
// call generate code
foreach (ActivityCodeGenerator codeGenerator in manager.GetCodeGenerators(bindBase.GetType()))
codeGenerator.GenerateCode(manager, args.CurrentValue);
// pops
manager.Context.Pop();
if (args.CurrentProperty != null)
manager.Context.Pop();
}
};
walker.WalkProperties(activity, obj);
manager.Context.Pop();
}
protected CodeTypeDeclaration GetCodeTypeDeclaration(CodeGenerationManager manager, string fullClassName)
{
if (manager == null)
throw new ArgumentNullException("manager");
if (fullClassName == null)
throw new ArgumentNullException("fullClassName");
string namespaceName;
string className;
Helpers.GetNamespaceAndClassName(fullClassName, out namespaceName, out className);
CodeNamespaceCollection codeNamespaces = manager.Context[typeof(CodeNamespaceCollection)] as CodeNamespaceCollection;
if (codeNamespaces == null)
throw new InvalidOperationException(SR.GetString(SR.Error_ContextStackItemMissing, typeof(CodeNamespaceCollection).Name));
CodeNamespace codeNS = null;
return Helpers.GetCodeNamespaceAndClass(codeNamespaces, namespaceName, className, out codeNS);
}
}
#endregion
}

View File

@ -0,0 +1,65 @@
namespace System.Workflow.ComponentModel.Compiler
{
using System;
using System.ComponentModel.Design.Serialization;
using System.Collections;
using System.Collections.Generic;
#region CodeGenerationManager
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
public sealed class CodeGenerationManager : IServiceProvider
{
private Hashtable hashOfGenerators = new Hashtable();
private IServiceProvider serviceProvider = null;
private ContextStack context = null;
public CodeGenerationManager(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
}
public ContextStack Context
{
get
{
if (this.context == null)
this.context = new ContextStack();
return this.context;
}
}
#region IServiceProvider Members
public object GetService(Type serviceType)
{
if (this.serviceProvider == null)
return null;
return this.serviceProvider.GetService(serviceType);
}
#endregion
public ActivityCodeGenerator[] GetCodeGenerators(Type type)
{
if (type == null)
throw new ArgumentNullException("type");
if (this.hashOfGenerators.Contains(type))
return ((List<ActivityCodeGenerator>)this.hashOfGenerators[type]).ToArray();
List<ActivityCodeGenerator> generators = new List<ActivityCodeGenerator>();
// Return validators for other types such as Bind, XmolDocument, etc.
foreach (ActivityCodeGenerator generator in ComponentDispenser.CreateComponents(type, typeof(ActivityCodeGeneratorAttribute)))
{
generators.Add(generator);
}
this.hashOfGenerators[type] = generators;
return generators.ToArray();
}
}
#endregion
}

View File

@ -0,0 +1,39 @@
namespace System.Workflow.ComponentModel.Compiler
{
[AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = false, Inherited = true)]
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
public sealed class ActivityCodeGeneratorAttribute : Attribute
{
string codeGeneratorTypeName = null;
public ActivityCodeGeneratorAttribute(Type codeGeneratorType)
{
if (codeGeneratorType == null)
throw new ArgumentNullException("codeGeneratorType");
if (!typeof(ActivityCodeGenerator).IsAssignableFrom(codeGeneratorType))
throw new ArgumentException(SR.GetString(SR.Error_NotCodeGeneratorType), "codeGeneratorType");
if (codeGeneratorType.GetConstructor(new Type[0] { }) == null)
throw new ArgumentException(SR.GetString(SR.Error_MissingDefaultConstructor, codeGeneratorType.FullName), "codeGeneratorType");
this.codeGeneratorTypeName = codeGeneratorType.AssemblyQualifiedName;
}
public ActivityCodeGeneratorAttribute(string codeGeneratorTypeName)
{
if (codeGeneratorTypeName == null)
throw new ArgumentNullException("codeGeneratorTypeName");
this.codeGeneratorTypeName = codeGeneratorTypeName;
}
public string CodeGeneratorTypeName
{
get
{
return this.codeGeneratorTypeName;
}
}
}
}

View File

@ -0,0 +1,32 @@
using System.Workflow.ComponentModel.Design;
namespace System.Workflow.ComponentModel.Compiler
{
#region Class CompositeActivityCodeGenerator
using System.Workflow.ComponentModel.Design;
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
public class CompositeActivityCodeGenerator : ActivityCodeGenerator
{
public override void GenerateCode(CodeGenerationManager manager, object obj)
{
if (manager == null)
throw new ArgumentNullException("manager");
if (obj == null)
throw new ArgumentNullException("obj");
CompositeActivity compositeActivity = obj as CompositeActivity;
if (compositeActivity == null)
throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(CompositeActivity).FullName), "obj");
base.GenerateCode(manager, obj);
foreach (Activity child in Helpers.GetAllEnabledActivities(compositeActivity))
{
foreach (ActivityCodeGenerator codeGenerator in manager.GetCodeGenerators(child.GetType()))
codeGenerator.GenerateCode(manager, child);
}
}
}
#endregion
}

View File

@ -0,0 +1,167 @@
namespace System.Workflow.ComponentModel.Compiler
{
using System.Xml;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.Xml.Serialization;
using System.Text.RegularExpressions;
internal sealed class WorkflowCompilerConfigurationSectionGroup : ConfigurationSectionGroup
{
public WorkflowCompilerConfigurationSectionGroup()
{
}
}
internal sealed class AuthorizedTypesSectionHandler : IConfigurationSectionHandler
{
const string TargetFxVersionAttribute = "version";
#region IConfigurationSectionHandler Members
object IConfigurationSectionHandler.Create(object parent, object configContext, XmlNode section)
{
Dictionary<string, IList<AuthorizedType>> authorizedTypes = new Dictionary<string, IList<AuthorizedType>>();
XmlAttributeOverrides authorizedTypeOverrides = new XmlAttributeOverrides();
XmlAttributes authorizedTypeAttributes = new XmlAttributes();
authorizedTypeAttributes.XmlRoot = new XmlRootAttribute("authorizedType");
authorizedTypeOverrides.Add(typeof(AuthorizedType), authorizedTypeAttributes);
XmlSerializer xmlSerializer = new XmlSerializer(typeof(AuthorizedType), authorizedTypeOverrides);
foreach (XmlNode targetFx in section.ChildNodes)
{
XmlAttribute versionAttribute = targetFx.Attributes.GetNamedItem(TargetFxVersionAttribute) as XmlAttribute;
if (versionAttribute != null)
{
string version = versionAttribute.Value;
if (!string.IsNullOrEmpty(version))
{
IList<AuthorizedType> versionTypes;
if (!authorizedTypes.TryGetValue(version, out versionTypes))
{
versionTypes = new List<AuthorizedType>();
authorizedTypes.Add(version, versionTypes);
}
foreach (XmlNode authorizedTypeNode in targetFx.ChildNodes)
{
AuthorizedType authorizedType = xmlSerializer.Deserialize(new XmlNodeReader(authorizedTypeNode)) as AuthorizedType;
if (authorizedType != null)
{
versionTypes.Add(authorizedType);
}
}
}
}
}
return authorizedTypes;
}
#endregion
}
[XmlType("authorizedType")]
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
public sealed class AuthorizedType
{
private string assemblyName;
private string namespaceName;
private string typeName;
private bool isAuthorized;
private Regex regex;
[XmlAttribute]
public string Assembly
{
get
{
return this.assemblyName;
}
set
{
this.assemblyName = value;
}
}
[XmlAttribute]
public string Namespace
{
get
{
return this.namespaceName;
}
set
{
this.namespaceName = value;
}
}
[XmlAttribute]
public string TypeName
{
get
{
return this.typeName;
}
set
{
this.typeName = value;
}
}
[XmlAttribute]
public string Authorized
{
get
{
return this.isAuthorized.ToString();
}
set
{
this.isAuthorized = bool.Parse(value);
}
}
[XmlIgnore]
public Regex RegularExpression
{
get
{
if (this.regex == null)
{
this.regex = new Regex(MakeRegex(string.Format(CultureInfo.InvariantCulture, "{0}.{1}, {2}", new object[] { this.namespaceName, this.typeName, this.assemblyName })), RegexOptions.Compiled);
return this.regex;
}
return this.regex;
}
}
private static string MakeRegex(string inputString)
{
// RegEx uses the following as meta characters:
// [\^$.|?*+()
// Of these we translate * and ? to DOS wildcard equivalents in RegEx.
// We escape rest of the Regex meta characters to thwart any luring
// attacks caused by malformed inputString using meta characters.
string outputString = inputString.Replace(@"\", @"\\");
outputString = outputString.Replace("[", @"\[");
outputString = outputString.Replace("^", @"\^");
outputString = outputString.Replace("$", @"\$");
outputString = outputString.Replace("|", @"\|");
outputString = outputString.Replace("+", @"\+");
outputString = outputString.Replace("(", @"\(");
outputString = outputString.Replace(")", @"\)");
outputString = outputString.Replace(".", @"\x2E");
outputString = outputString.Replace("*", @"[\w\x60\x2E]{0,}");
outputString = outputString.Replace("?", @"\w{1,1}");
// Make whitespaces optional
outputString = outputString.Replace(" ", @"\s{0,}");
return outputString;
}
}
}

View File

@ -0,0 +1,256 @@
namespace System.Workflow.ComponentModel.Compiler
{
using System;
using System.Runtime.InteropServices;
internal sealed class PDBReader : IDisposable
{
#region Data Members
private const string IMetaDataImportGuid = "7DAC8207-D3AE-4c75-9B67-92801A497D44";
private ISymUnmanagedReader symReader;
#endregion
#region Constructor and Dispose
public PDBReader(string assemblyPath)
{
object metaDataImport = null;
IMetaDataDispenser dispenser = null;
try
{
Guid metaDataImportIID = new Guid(IMetaDataImportGuid);
dispenser = (IMetaDataDispenser)(new MetaDataDispenser());
dispenser.OpenScope(assemblyPath, 0, ref metaDataImportIID, out metaDataImport);
this.symReader = (ISymUnmanagedReader)(new CorSymReader_SxS());
this.symReader.Initialize(metaDataImport, assemblyPath, null, null);
}
finally
{
// Release COM objects so that files don't remain locked.
if (metaDataImport != null)
Marshal.ReleaseComObject(metaDataImport);
if (dispenser != null)
Marshal.ReleaseComObject(dispenser);
}
}
~PDBReader()
{
Dispose();
}
void IDisposable.Dispose()
{
Dispose();
GC.SuppressFinalize(this);
}
private void Dispose()
{
if (this.symReader != null)
{
Marshal.ReleaseComObject(this.symReader);
this.symReader = null;
}
}
#endregion
#region Public methods
public void GetSourceLocationForOffset(uint methodDef, uint offset, out string fileLocation, out uint line, out uint column)
{
fileLocation = null;
line = 0;
column = 0;
ISymUnmanagedMethod symMethod = null;
ISymUnmanagedDocument[] documents = null;
uint sequencePointCount = 0;
try
{
symMethod = this.symReader.GetMethod(methodDef);
sequencePointCount = symMethod.GetSequencePointCount();
documents = new ISymUnmanagedDocument[sequencePointCount];
uint[] offsets = new uint[sequencePointCount];
uint[] lines = new uint[sequencePointCount];
uint[] columns = new uint[sequencePointCount];
uint[] endLines = new uint[sequencePointCount];
uint[] endColumns = new uint[sequencePointCount];
symMethod.GetSequencePoints(sequencePointCount, out sequencePointCount, offsets, documents, lines, columns, endLines, endColumns);
uint index = 1;
for (; index < sequencePointCount; index++)
{ if (offsets[index] > offset) break; }
index = index - 1;
// Work Around: AkashS - The SymReader returns bad line-column data for unconditional branch
// instructions. The line number is whacky and the column number is 0. Need to verify why this is so.
// We just look for a good sequence point data, it should be close enough in the source code.
while (columns[index] == 0 && index > 0)
index--;
while (index < sequencePointCount && columns[index] == 0)
index++;
// What more can we do?
if (index >= sequencePointCount || columns[index] == 0)
index = 0;
// End Work around
line = lines[index];
column = columns[index];
ISymUnmanagedDocument document = documents[index];
uint urlLength = 261;
string url = new string('\0', (int)urlLength);
document.GetURL(urlLength, out urlLength, url);
fileLocation = url.Substring(0, (int)urlLength - 1);
}
finally
{
// Release COM objects so that files don't remain locked.
for (uint i = 0; i < sequencePointCount; i++)
if (documents[i] != null)
Marshal.ReleaseComObject(documents[i]);
if (symMethod != null)
Marshal.ReleaseComObject(symMethod);
}
}
#endregion
}
#region Interop declarations
//
// Note:
// These interop declaration are sufficient for our purposes of reading the symbol information from
// the PDB. They are not complete otherwise!
//
[ComImport, Guid("0A3976C5-4529-4ef8-B0B0-42EED37082CD")]
internal class CorSymReader_SxS
{ }
[ComImport,
CoClass(typeof(CorSymReader_SxS)),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("B4CE6286-2A6B-3712-A3B7-1EE1DAD467B5")]
internal interface ISymUnmanagedReader
{
// NYI.
void GetDocument();
void GetDocuments();
void GetUserEntryPoint();
ISymUnmanagedMethod GetMethod(uint methodDef);
// NYI.
void GetMethodByVersion();
void GetVariables();
void GetGlobalVariables();
void GetMethodFromDocumentPosition();
void GetSymAttribute();
void GetNamespaces();
// Incomplete - We don't use the Stream
void Initialize([In, MarshalAs(UnmanagedType.IUnknown)] object metaDataImport, [In, MarshalAs(UnmanagedType.LPWStr)] string pdbPath, [In, MarshalAs(UnmanagedType.LPWStr)] string searchPath, [In, MarshalAs(UnmanagedType.IUnknown)] object stream);
// NYI.
void UpdateSymbolStore();
void ReplaceSymbolStore();
void GetSymbolStoreFileName();
void GetMethodsFromDocumentPosition();
void GetDocumentVersion();
void GetMethodVersion();
}
[ComImport,
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("B62B923C-B500-3158-A543-24F307A8B7E1")]
internal interface ISymUnmanagedMethod
{
uint GetToken();
uint GetSequencePointCount();
// Incomplete - Don't need to define ISymUnmanagedScope.
object GetRootScope();
// Incomplete - Don't need to define ISymUnmanagedScope.
object GetScopeFromOffset(uint offset);
uint GetOffset([In, MarshalAs(UnmanagedType.IUnknown)] ISymUnmanagedDocument document, uint line, uint column);
void GetRanges([In, MarshalAs(UnmanagedType.IUnknown)] ISymUnmanagedDocument document, uint line, uint column, uint rangeCount, [Out] out uint actualRangeCount, [In, Out, MarshalAs(UnmanagedType.LPArray)] uint[] ranges);
// NYI.
void GetParameters();
// NYI.
void GetNamespace();
void GetSourceStartEnd([In, Out, MarshalAs(UnmanagedType.LPArray)] ISymUnmanagedDocument[] documents, [In, Out, MarshalAs(UnmanagedType.LPArray)] uint[] lines, [In, Out, MarshalAs(UnmanagedType.LPArray)] uint[] columns, [Out, MarshalAs(UnmanagedType.Bool)] out bool positionsDefined);
void GetSequencePoints(uint pointsCount, [Out] out uint actualPointsCount, [In, Out, MarshalAs(UnmanagedType.LPArray)] uint[] offsets, [In, Out, MarshalAs(UnmanagedType.LPArray)] ISymUnmanagedDocument[] documents, [In, Out, MarshalAs(UnmanagedType.LPArray)] uint[] lines, [In, Out, MarshalAs(UnmanagedType.LPArray)] uint[] columns, [In, Out, MarshalAs(UnmanagedType.LPArray)] uint[] endLines, [In, Out, MarshalAs(UnmanagedType.LPArray)] uint[] endColumns);
}
[ComImport,
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("40DE4037-7C81-3E1E-B022-AE1ABFF2CA08")]
internal interface ISymUnmanagedDocument
{
void GetURL(uint urlLength, [Out] out uint actualUrlLength, [In, Out, MarshalAs(UnmanagedType.LPWStr)] string url);
// The rest are NYI.
void GetDocumentType();
void GetLanguage();
void GetLanguageVendor();
void GetCheckSumAlgorithmId();
void GetCheckSum();
void FindClosestLine();
void HasEmbeddedSource();
void GetSourceLength();
void GetSourceRange();
}
[ComImport,
Guid("E5CB7A31-7512-11d2-89CE-0080C792E5D8")]
internal class MetaDataDispenser
{
}
[ComImport,
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
CoClass(typeof(MetaDataDispenser)),
Guid("809C652E-7396-11d2-9771-00A0C9B4D50C")]
internal interface IMetaDataDispenser
{
// NYI
void DefineScope();
// Incomplete - I don't really need to define IMetaDataImport.
void OpenScope([In, MarshalAs(UnmanagedType.LPWStr)] string scope, uint flags, [In] ref Guid riid, [Out, MarshalAs(UnmanagedType.IUnknown)] out object unknown);
// NYI
void OpenScopeOnMemory();
}
#endregion
}

View File

@ -0,0 +1,90 @@
namespace System.Workflow.ComponentModel.Compiler
{
using System;
using System.Reflection;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Design;
#region Class Assembly resolver
// In the cases where the WorkflowCompiler is invoked directly, we need to deserialize the
// xoml before we can create the real TypeProvider, hence it is necessary to look at the
// referenced assemblies for any types that fail to load. In the VS scenarios, the TypeProvider
// has already been created and the WorkflowMarkupSerializer will use it first.
internal sealed class ReferencedAssemblyResolver
{
private StringCollection referencedAssemblies = new StringCollection();
private Assembly localAssembly;
private bool resolving = false;
public ReferencedAssemblyResolver(StringCollection referencedAssemblies, Assembly localAssembly)
{
this.referencedAssemblies = referencedAssemblies;
this.localAssembly = localAssembly;
}
public Assembly ResolveEventHandler(object sender, ResolveEventArgs args)
{
return ResolveAssembly(args.Name);
}
internal void SetLocalAssembly(Assembly localAsm)
{
this.localAssembly = localAsm;
}
private Assembly ResolveAssembly(string name)
{
if (this.resolving)
return null;
// First look for the local assembly.
if (this.localAssembly != null && name == this.localAssembly.FullName)
return this.localAssembly;
try
{
this.resolving = true;
AssemblyName assemblyName = new AssemblyName(name);
// Then try the referenced assemblies.
foreach (string assemblyPath in this.referencedAssemblies)
{
try
{
AssemblyName referenceAssemblyName = AssemblyName.GetAssemblyName(assemblyPath);
if (referenceAssemblyName != null && ParseHelpers.AssemblyNameEquals(referenceAssemblyName, assemblyName))
{
Assembly reference = null;
try
{
reference = Assembly.Load(referenceAssemblyName);
}
catch
{
reference = Assembly.LoadFrom(assemblyPath);
}
return reference;
}
}
catch
{
// Eat up any exceptions!
}
}
}
finally
{
this.resolving = false;
}
return null;
}
}
#endregion
}

View File

@ -0,0 +1,144 @@
namespace System.Workflow.ComponentModel.Compiler
{
using System;
using System.Collections.Generic;
using System.Reflection;
using System.ComponentModel.Design;
using System.IO;
internal class AssemblyLoader
{
private Assembly assembly = null;
private AssemblyName assemblyName = null;
private TypeProvider typeProvider = null;
private bool isLocalAssembly;
internal AssemblyLoader(TypeProvider typeProvider, string filePath)
{
this.isLocalAssembly = false;
this.typeProvider = typeProvider;
if (File.Exists(filePath))
{
AssemblyName asmName = AssemblyName.GetAssemblyName(filePath);
if (asmName != null)
{
// Try loading the assembly using type resolution service first.
ITypeResolutionService trs = (ITypeResolutionService)typeProvider.GetService(typeof(ITypeResolutionService));
if (trs != null)
{
try
{
this.assembly = trs.GetAssembly(asmName);
//
if (this.assembly == null && asmName.GetPublicKeyToken() != null && (asmName.GetPublicKeyToken().GetLength(0) == 0) && asmName.GetPublicKey() != null && (asmName.GetPublicKey().GetLength(0) == 0))
{
AssemblyName partialName = (AssemblyName)asmName.Clone();
partialName.SetPublicKey(null);
partialName.SetPublicKeyToken(null);
this.assembly = trs.GetAssembly(partialName);
}
}
catch
{
// Eat up any exceptions!
}
}
// If type resolution service wasn't available or it failed use Assembly.Load
if (this.assembly == null)
{
try
{
if (MultiTargetingInfo.MultiTargetingUtilities.IsFrameworkReferenceAssembly(filePath))
{
this.assembly = Assembly.Load(asmName.FullName);
}
else
{
this.assembly = Assembly.Load(asmName);
}
}
catch
{
// Eat up any exceptions!
}
}
}
// If Assembly.Load also failed, use Assembly.LoadFrom
if (this.assembly == null)
{
this.assembly = Assembly.LoadFrom(filePath);
}
}
else
{
// TypeProvider will handle this and report the error
throw new FileNotFoundException();
}
}
internal AssemblyLoader(TypeProvider typeProvider, Assembly assembly, bool isLocalAssembly)
{
this.isLocalAssembly = isLocalAssembly;
this.typeProvider = typeProvider;
this.assembly = assembly;
}
internal Type GetType(string typeName)
{
//
if (this.assembly != null)
{
Type type = null;
try
{
type = this.assembly.GetType(typeName);
}
catch (ArgumentException)
{
// we eat these exeptions in our type system
}
if ((type != null) && (type.IsPublic || type.IsNestedPublic || (this.isLocalAssembly && type.Attributes != TypeAttributes.NestedPrivate)))
return type;
}
return null;
}
internal Type[] GetTypes()
{
List<Type> filteredTypes = new List<Type>();
if (this.assembly != null)
{
//
foreach (Type type in this.assembly.GetTypes())
{
//
if (type.IsPublic || (this.isLocalAssembly && type.Attributes != TypeAttributes.NestedPrivate))
filteredTypes.Add(type);
}
}
return filteredTypes.ToArray();
}
// we cache the AssemblyName as Assembly.GetName() is expensive
internal AssemblyName AssemblyName
{
get
{
if (this.assemblyName == null)
this.assemblyName = this.assembly.GetName(true);
return this.assemblyName;
}
}
internal Assembly Assembly
{
get
{
return this.assembly;
}
}
}
}

View File

@ -0,0 +1,248 @@
namespace System.Workflow.ComponentModel.Compiler
{
using System;
using System.CodeDom;
using System.Collections;
using System.Globalization;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Collections.ObjectModel;
/// <summary>
/// Summary description for AttributeInfo.
/// </summary>
[CLSCompliant(false)]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property, AllowMultiple = true)]
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
public sealed class AttributeInfoAttribute : Attribute
{
private AttributeInfo attributeInfo;
internal AttributeInfoAttribute(AttributeInfo attributeInfo)
{
if (attributeInfo == null)
throw new ArgumentNullException("attributeInfo");
this.attributeInfo = attributeInfo;
}
internal static AttributeInfoAttribute CreateAttributeInfoAttribute(Type attributeType, string[] argumentNames, object[] argumentValues)
{
return new AttributeInfoAttribute(new AttributeInfo(attributeType, argumentNames, argumentValues));
}
public AttributeInfo AttributeInfo
{
get
{
return this.attributeInfo;
}
}
}
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
public sealed class AttributeInfo
{
#region Members and Constructors
private Type attributeType;
private string[] argumentNames;
private object[] argumentValues;
internal AttributeInfo(Type attributeType, string[] argumentNames, object[] argumentValues)
{
this.attributeType = attributeType;
this.argumentNames = (string[])argumentNames.Clone();
this.argumentValues = (object[])argumentValues.Clone();
}
#endregion
#region Properties
public Type AttributeType
{
get
{
return attributeType;
}
}
public ReadOnlyCollection<object> ArgumentValues
{
get
{
List<object> arguments = new List<object>(this.argumentValues);
return arguments.AsReadOnly();
}
}
public bool Creatable
{
get
{
if (attributeType.Assembly == null)
return false;
foreach (object argument in argumentValues)
{
if (argument is Exception)
return false;
}
return true;
}
}
#endregion
#region Public methods
public Attribute CreateAttribute()
{
if (!Creatable)
throw new InvalidOperationException(SR.GetString(SR.CannotCreateAttribute));
List<string> propertyNames = new List<string>();
ArrayList propertyValues = new ArrayList();
ArrayList constructorArguments = new ArrayList();
// go over the arguments, seperate named vs. non-named arguments
for (int loop = 0; loop < argumentNames.Length; loop++)
{
if ((argumentNames[loop] == null) || (argumentNames[loop].Length == 0))
constructorArguments.Add(argumentValues[loop]);
else
{
propertyNames.Add(argumentNames[loop]);
propertyValues.Add(argumentValues[loop]);
}
}
// creating the Attribute
Attribute attribute = (Attribute)Activator.CreateInstance(attributeType, constructorArguments.ToArray());
// setting named properties
for (int loop = 0; loop < propertyNames.Count; loop++)
{
//
attributeType.GetProperty(propertyNames[loop]).SetValue(attribute, propertyValues[loop], null);
}
return attribute;
}
public object GetArgumentValueAs(IServiceProvider serviceProvider, int argumentIndex, Type requestedType)
{
if (argumentIndex >= this.ArgumentValues.Count || argumentIndex < 0)
throw new ArgumentException(SR.GetString(SR.Error_InvalidArgumentIndex), "argumentIndex");
if (requestedType == null)
throw new ArgumentNullException("requestedType");
SupportedLanguages language = CompilerHelpers.GetSupportedLanguage(serviceProvider);
if (requestedType == typeof(string))
{
string returnValue = this.ArgumentValues[argumentIndex] as string;
// string values read by the code-dom parser are double escaped, so
// remove the 2nd escaping (we need to leave the escaping in at parse time)
// in case the attribute argument is never processed and emitted as
// the code snippet
if (returnValue != null)
{
try
{
returnValue = Regex.Unescape(returnValue);
}
catch
{
}
}
if (returnValue != null)
{
if (returnValue.EndsWith("\"", StringComparison.Ordinal))
returnValue = returnValue.Substring(0, returnValue.Length - 1);
if (language == SupportedLanguages.CSharp && returnValue.StartsWith("@\"", StringComparison.Ordinal))
returnValue = returnValue.Substring(2, returnValue.Length - 2);
else if (returnValue.StartsWith("\"", StringComparison.Ordinal))
returnValue = returnValue.Substring(1, returnValue.Length - 1);
}
return returnValue;
}
else if (requestedType.IsEnum)
{
string parseableValue = "";
bool firstValue = true;
foreach (string enumValue in (this.ArgumentValues[argumentIndex] as string).Split(new string[] { language == SupportedLanguages.CSharp ? "|" : "Or" }, StringSplitOptions.RemoveEmptyEntries))
{
if (!firstValue)
parseableValue += ",";
int valueSep = enumValue.LastIndexOf('.');
if (valueSep != -1)
parseableValue += enumValue.Substring(valueSep + 1);
else
parseableValue += enumValue;
firstValue = false;
}
return Enum.Parse(requestedType, parseableValue);
}
else if (requestedType == typeof(bool))
{
return System.Convert.ToBoolean(this.ArgumentValues[argumentIndex], CultureInfo.InvariantCulture);
}
else if (requestedType == typeof(Type))
{
string typeName = "";
if (this.ArgumentValues[argumentIndex] is CodeTypeOfExpression)
typeName = DesignTimeType.GetTypeNameFromCodeTypeReference((this.ArgumentValues[argumentIndex] as CodeTypeOfExpression).Type, null);
ITypeProvider typeProvider = serviceProvider.GetService(typeof(ITypeProvider)) as ITypeProvider;
if (typeProvider == null)
throw new Exception(SR.GetString(SR.General_MissingService, typeof(ITypeProvider).ToString()));
Type returnType = ParseHelpers.ParseTypeName(typeProvider, language, typeName);
if (returnType == null)
{
// Try to parse the attribute value manually
string[] genericParamTypeNames = null;
string baseTypeName = string.Empty;
string elementDecorators = string.Empty;
if (ParseHelpers.ParseTypeName(typeName, language == SupportedLanguages.CSharp ? ParseHelpers.ParseTypeNameLanguage.CSharp : ParseHelpers.ParseTypeNameLanguage.VB, out baseTypeName, out genericParamTypeNames, out elementDecorators))
{
if (baseTypeName != null && genericParamTypeNames != null)
{
string parsedTypeName = baseTypeName + "`" + genericParamTypeNames.Length.ToString(CultureInfo.InvariantCulture) + "[";
foreach (string genericArg in genericParamTypeNames)
{
if (genericArg != genericParamTypeNames[0])
parsedTypeName += ",";
Type genericArgType = ParseHelpers.ParseTypeName(typeProvider, language, genericArg);
if (genericArgType != null)
parsedTypeName += "[" + genericArgType.FullName + "]";
else
parsedTypeName += "[" + genericArg + "]";
}
parsedTypeName += "]";
returnType = ParseHelpers.ParseTypeName(typeProvider, language, parsedTypeName);
}
}
}
return returnType;
}
return null;
}
#endregion
}
}

View File

@ -0,0 +1,88 @@
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<Type> types = new List<Type>();
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
}
}

View File

@ -0,0 +1,180 @@
namespace System.Workflow.ComponentModel.Compiler
{
using System;
using System.CodeDom;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
#region DesignTimeEventInfo
internal sealed class DesignTimeEventInfo : EventInfo
{
#region Members and Constructors
private string name;
private DesignTimeMethodInfo addMethod = null;
private DesignTimeMethodInfo removeMethod = null;
private Attribute[] attributes = null;
private MemberAttributes memberAttributes;
private DesignTimeType declaringType;
private CodeMemberEvent codeDomEvent;
internal DesignTimeEventInfo(DesignTimeType declaringType, CodeMemberEvent codeDomEvent)
{
if (declaringType == null)
{
throw new ArgumentNullException("Declaring Type");
}
if (codeDomEvent == null)
{
throw new ArgumentNullException("codeDomEvent");
}
this.declaringType = declaringType;
this.codeDomEvent = codeDomEvent;
this.name = Helper.EnsureTypeName(codeDomEvent.Name);
this.memberAttributes = codeDomEvent.Attributes;
this.addMethod = null;
this.removeMethod = null;
}
#endregion
#region Event Info overrides
public override MethodInfo GetAddMethod(bool nonPublic)
{
if (this.addMethod == null)
{
Type handlerType = declaringType.ResolveType(DesignTimeType.GetTypeNameFromCodeTypeReference(this.codeDomEvent.Type, declaringType));
if (handlerType != null)
{
CodeMemberMethod codeAddMethod = new CodeMemberMethod();
codeAddMethod.Name = "add_" + this.name;
codeAddMethod.ReturnType = new CodeTypeReference(typeof(void));
codeAddMethod.Parameters.Add(new CodeParameterDeclarationExpression(this.codeDomEvent.Type, "Handler"));
codeAddMethod.Attributes = this.memberAttributes;
this.addMethod = new DesignTimeMethodInfo(this.declaringType, codeAddMethod, true);
}
}
return this.addMethod;
}
public override MethodInfo GetRemoveMethod(bool nonPublic)
{
if (this.removeMethod == null)
{
Type handlerType = declaringType.ResolveType(DesignTimeType.GetTypeNameFromCodeTypeReference(this.codeDomEvent.Type, declaringType));
if (handlerType != null)
{
CodeMemberMethod codeRemoveMethod = new CodeMemberMethod();
codeRemoveMethod.Name = "remove_" + this.name;
codeRemoveMethod.ReturnType = new CodeTypeReference(typeof(void));
codeRemoveMethod.Parameters.Add(new CodeParameterDeclarationExpression(handlerType, "Handler"));
codeRemoveMethod.Attributes = this.memberAttributes;
this.removeMethod = new DesignTimeMethodInfo(declaringType, codeRemoveMethod, true);
}
}
return this.removeMethod;
}
public override MethodInfo GetRaiseMethod(bool nonPublic)
{
return null;
}
public override EventAttributes Attributes
{
//We're not interested in this flag
get
{
return default(EventAttributes);
}
}
#endregion
#region MemberInfo Overrides
public override string Name
{
get
{
return this.name;
}
}
public override Type DeclaringType
{
get
{
return this.declaringType;
}
}
public override Type ReflectedType
{
get
{
return this.declaringType;
}
}
public override object[] GetCustomAttributes(bool inherit)
{
return GetCustomAttributes(typeof(object), inherit);
}
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
{
if (attributeType == null)
throw new ArgumentNullException("attributeType");
if (this.attributes == null)
this.attributes = Helper.LoadCustomAttributes(this.codeDomEvent.CustomAttributes, this.DeclaringType as DesignTimeType);
return Helper.GetCustomAttributes(attributeType, inherit, this.attributes, this);
}
public override bool IsDefined(Type attributeType, bool inherit)
{
if (attributeType == null)
throw new ArgumentNullException("attributeType");
if (this.attributes == null)
this.attributes = Helper.LoadCustomAttributes(this.codeDomEvent.CustomAttributes, this.DeclaringType as DesignTimeType);
if (Helper.IsDefined(attributeType, inherit, attributes, this))
return true;
return false;
}
#endregion
#region Helpers
internal bool IsPublic
{
get
{
return ((memberAttributes & MemberAttributes.Public) != 0);
}
}
internal bool IsStatic
{
get
{
return ((memberAttributes & MemberAttributes.Static) != 0);
}
}
#endregion
}
#endregion
}

View File

@ -0,0 +1,137 @@
#pragma warning disable 1634, 1691
namespace System.Workflow.ComponentModel.Compiler
{
using System;
using System.CodeDom;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
#region DesignTimeFieldInfo
internal sealed class DesignTimeFieldInfo : FieldInfo
{
#region Members and Constructors
private Attribute[] attributes = null;
private FieldAttributes fieldAttributes;
private DesignTimeType declaringType;
private CodeMemberField codeDomField;
internal DesignTimeFieldInfo(DesignTimeType declaringType, CodeMemberField codeDomField)
{
if (declaringType == null)
{
throw new ArgumentNullException("Declaring Type");
}
if (codeDomField == null)
{
throw new ArgumentNullException("codeDomEvent");
}
this.declaringType = declaringType;
this.codeDomField = codeDomField;
fieldAttributes = Helper.ConvertToFieldAttributes(codeDomField.Attributes);
}
#endregion
#region FieldInfo overrides
public override RuntimeFieldHandle FieldHandle
{
get
{
// not interested in Runtime information
#pragma warning suppress 56503
throw new NotImplementedException(TypeSystemSR.GetString("Error_RuntimeNotSupported"));
}
}
public override Type FieldType
{
get
{
return declaringType.ResolveType(DesignTimeType.GetTypeNameFromCodeTypeReference(this.codeDomField.Type, declaringType));
}
}
public override Object GetValue(object obj)
{
// We don't need to get into instance probing
throw new NotImplementedException(TypeSystemSR.GetString("Error_RuntimeNotSupported"));
}
public override void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture)
{
// We don't need to get into instance probing
throw new NotImplementedException(TypeSystemSR.GetString("Error_RuntimeNotSupported"));
}
public override FieldAttributes Attributes
{
get { return this.fieldAttributes; }
}
#endregion
#region MemberInfo Overrides
public override string Name
{
get
{
return Helper.EnsureTypeName(this.codeDomField.Name);
}
}
public override Type DeclaringType
{
get
{
return this.declaringType;
}
}
public override Type ReflectedType
{
get
{
return this.declaringType;
}
}
public override object[] GetCustomAttributes(bool inherit)
{
return GetCustomAttributes(typeof(object), inherit);
}
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
{
if (attributeType == null)
throw new ArgumentNullException("attributeType");
if (this.attributes == null)
this.attributes = Helper.LoadCustomAttributes(this.codeDomField.CustomAttributes, this.DeclaringType as DesignTimeType);
return Helper.GetCustomAttributes(attributeType, inherit, this.attributes, this);
}
public override bool IsDefined(Type attributeType, bool inherit)
{
if (attributeType == null)
throw new ArgumentNullException("attributeType");
if (this.attributes == null)
this.attributes = Helper.LoadCustomAttributes(this.codeDomField.CustomAttributes, this.DeclaringType as DesignTimeType);
if (Helper.IsDefined(attributeType, inherit, attributes, this))
return true;
return false;
}
#endregion
}
#endregion
}

View File

@ -0,0 +1,312 @@
namespace System.Workflow.ComponentModel.Compiler
{
using System;
using System.CodeDom;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Text;
using System.Collections;
using System.Collections.Generic;
internal static class Helper
{
internal static ParameterAttributes ConvertToParameterAttributes(FieldDirection direction)
{
ParameterAttributes paramAttributes = ParameterAttributes.None;
// Only few param attributes are supported
switch (direction)
{
case FieldDirection.In:
paramAttributes = ParameterAttributes.In;
break;
case FieldDirection.Out:
paramAttributes = ParameterAttributes.Out;
break;
default:
paramAttributes = default(ParameterAttributes);
break;
}
return paramAttributes;
}
internal static MethodAttributes ConvertToMethodAttributes(MemberAttributes memberAttributes)
{
MethodAttributes methodAttributes = MethodAttributes.ReuseSlot;
// convert access attributes
if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.Assembly)
methodAttributes |= MethodAttributes.Assembly;
else if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.Family)
methodAttributes |= MethodAttributes.Family;
else if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.FamilyAndAssembly)
methodAttributes |= MethodAttributes.FamANDAssem;
else if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.FamilyOrAssembly)
methodAttributes |= MethodAttributes.FamORAssem;
else if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.Private)
methodAttributes |= MethodAttributes.Private;
else if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.Public)
methodAttributes |= MethodAttributes.Public;
// covert scope attributes
if ((memberAttributes & MemberAttributes.ScopeMask) == MemberAttributes.Abstract)
methodAttributes |= MethodAttributes.Abstract;
else if ((memberAttributes & MemberAttributes.ScopeMask) == MemberAttributes.Final)
methodAttributes |= MethodAttributes.Final;
else if ((memberAttributes & MemberAttributes.ScopeMask) == MemberAttributes.Static)
methodAttributes |= MethodAttributes.Static;
//else if ((memberAttributes & MemberAttributes.ScopeMask) == MemberAttributes.Override)
// methodAttributes |= MethodAttributes.ReuseSlot;//
// convert vtable slot
if ((memberAttributes & MemberAttributes.VTableMask) == MemberAttributes.New)
methodAttributes |= MethodAttributes.NewSlot;
//if ((memberAttributes & MemberAttributes.VTableMask) == MemberAttributes.Overloaded)
// methodAttributes |= MethodAttributes.HideBySig; //
return methodAttributes;
}
internal static FieldAttributes ConvertToFieldAttributes(MemberAttributes memberAttributes)
{
FieldAttributes fieldAttributes = default(FieldAttributes);
if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.Assembly)
fieldAttributes |= FieldAttributes.Assembly;
else if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.Family)
fieldAttributes |= FieldAttributes.Family;
else if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.FamilyAndAssembly)
fieldAttributes |= FieldAttributes.FamANDAssem;
else if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.FamilyOrAssembly)
fieldAttributes |= FieldAttributes.FamORAssem;
else if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.Private)
fieldAttributes |= FieldAttributes.Private;
else if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.Public)
fieldAttributes |= FieldAttributes.Public;
if ((memberAttributes & MemberAttributes.ScopeMask) == MemberAttributes.Const)
fieldAttributes |= (FieldAttributes.Static | FieldAttributes.Literal);
else if ((memberAttributes & MemberAttributes.ScopeMask) == MemberAttributes.Static)
fieldAttributes |= FieldAttributes.Static;
return fieldAttributes;
}
internal static TypeAttributes ConvertToTypeAttributes(MemberAttributes memberAttributes, Type declaringType)
{
TypeAttributes typeAttributes = default(TypeAttributes);
// convert access attributes
if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.Assembly)
typeAttributes |= ((declaringType != null) ? TypeAttributes.NestedAssembly : TypeAttributes.NotPublic);
else if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.Family)
typeAttributes |= ((declaringType != null) ? TypeAttributes.NestedFamily : TypeAttributes.NotPublic);
else if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.FamilyAndAssembly)
typeAttributes |= ((declaringType != null) ? TypeAttributes.NestedFamANDAssem : TypeAttributes.NotPublic);
else if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.FamilyOrAssembly)
typeAttributes |= ((declaringType != null) ? TypeAttributes.NestedFamORAssem : TypeAttributes.NotPublic);
else if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.Private)
typeAttributes |= ((declaringType != null) ? TypeAttributes.NestedPrivate : TypeAttributes.NotPublic);
else if ((memberAttributes & MemberAttributes.AccessMask) == MemberAttributes.Public)
typeAttributes |= ((declaringType != null) ? TypeAttributes.NestedPublic : TypeAttributes.Public);
// covert scope attributes
if ((memberAttributes & MemberAttributes.ScopeMask) == MemberAttributes.Abstract)
typeAttributes |= TypeAttributes.Abstract;
else if ((memberAttributes & MemberAttributes.ScopeMask) == MemberAttributes.Final)
typeAttributes |= TypeAttributes.Sealed;
else if ((memberAttributes & MemberAttributes.Static) == MemberAttributes.Static)
typeAttributes |= (TypeAttributes.Abstract | TypeAttributes.Sealed);
return typeAttributes;
}
internal static bool IncludeAccessor(MethodInfo accessor, bool nonPublic)
{
if (accessor == null)
return false;
if (nonPublic)
return true;
if (accessor.IsPublic)
return true;
return false;
}
internal static Attribute[] LoadCustomAttributes(CodeAttributeDeclarationCollection codeAttributeCollection, DesignTimeType declaringType)
{
if (declaringType == null)
throw new ArgumentNullException("declaringType");
if (codeAttributeCollection == null)
return new Attribute[0];
List<Attribute> attributes = new List<Attribute>();
// walk through the attributes
foreach (CodeAttributeDeclaration codeAttribute in codeAttributeCollection)
{
String[] argumentNames = new String[codeAttribute.Arguments.Count];
object[] argumentValues = new object[codeAttribute.Arguments.Count];
Type attributeType = declaringType.ResolveType(codeAttribute.Name);
if (attributeType != null)
{
int index = 0;
// walk through tha arguments
foreach (CodeAttributeArgument codeArgument in codeAttribute.Arguments)
{
argumentNames[index] = codeArgument.Name;
if (codeArgument.Value is CodePrimitiveExpression)
argumentValues[index] = (codeArgument.Value as CodePrimitiveExpression).Value;
else if (codeArgument.Value is CodeTypeOfExpression)
argumentValues[index] = codeArgument.Value;
else if (codeArgument.Value is CodeSnippetExpression)
argumentValues[index] = (codeArgument.Value as CodeSnippetExpression).Value;
else
argumentValues[index] = new ArgumentException(SR.GetString(SR.Error_TypeSystemAttributeArgument));
index++;
}
bool alreadyExists = false;
foreach (AttributeInfoAttribute attribInfo in attributes)
{
if (attribInfo.AttributeInfo.AttributeType.FullName.Equals(attributeType.FullName))
{
alreadyExists = true;
break;
}
}
//
bool allowMultiple = false;
if (alreadyExists && attributeType.Assembly != null)
{
object[] usageAttribs = attributeType.GetCustomAttributes(typeof(System.AttributeUsageAttribute), true);
if (usageAttribs != null && usageAttribs.Length > 0)
{
AttributeUsageAttribute usage = usageAttribs[0] as AttributeUsageAttribute;
allowMultiple = usage.AllowMultiple;
}
}
// now create and add the placeholder attribute
if (!alreadyExists || allowMultiple)
attributes.Add(AttributeInfoAttribute.CreateAttributeInfoAttribute(attributeType, argumentNames, argumentValues));
}
}
return attributes.ToArray();
}
internal static object[] GetCustomAttributes(Type attributeType, bool inherit, Attribute[] attributes, MemberInfo memberInfo)
{
if (attributeType == null)
throw new ArgumentNullException("attributeType");
ArrayList attributeList = new ArrayList();
ArrayList attributeTypes = new ArrayList();
if (attributeType == typeof(object))
{
attributeList.AddRange(attributes);
}
else
{
foreach (AttributeInfoAttribute attribute in attributes)
{
if (attribute.AttributeInfo.AttributeType == attributeType)
{
attributeList.Add(attribute);
attributeTypes.Add(attributeType);
}
}
}
if (inherit)
{
MemberInfo baseMemberInfo = null;
// we need to get a base type or the overriden member that might declare additional attributes
if (memberInfo is Type)
baseMemberInfo = ((Type)memberInfo).BaseType;
else
baseMemberInfo = ((DesignTimeType)memberInfo.DeclaringType).GetBaseMember(memberInfo.GetType(), memberInfo.DeclaringType.BaseType, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance, new DesignTimeType.MemberSignature(memberInfo));
// Add base attributes
if (baseMemberInfo != null)
{
object[] baseAttributes = baseMemberInfo.GetCustomAttributes(attributeType, inherit);
// check that attributes are not repeated
foreach (Attribute baseAttribute in baseAttributes)
{
if (!(baseAttribute is AttributeInfoAttribute) || (!attributeTypes.Contains(((AttributeInfoAttribute)baseAttribute).AttributeInfo.AttributeType)))
attributeList.Add(baseAttribute);
}
}
}
return attributeList.ToArray();
}
internal static bool IsDefined(Type attributeType, bool inherit, Attribute[] attributes, MemberInfo memberInfo)
{
if (attributeType == null)
throw new ArgumentNullException("attributeType");
foreach (Attribute attribute in attributes)
{
// check to see if a type is wrapped in an AttributeInfoAttribute
if ((attribute is AttributeInfoAttribute) && ((attribute as AttributeInfoAttribute).AttributeInfo.AttributeType == attributeType))
return true;
}
MemberInfo baseMemberInfo = null;
// we need to get a base type or the overriden member that might declare additional attributes
if (memberInfo is Type)
baseMemberInfo = ((Type)memberInfo).BaseType;
else
baseMemberInfo = ((DesignTimeType)memberInfo.DeclaringType).GetBaseMember(memberInfo.GetType(), memberInfo.DeclaringType.BaseType, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance, new DesignTimeType.MemberSignature(memberInfo));
// Add base attributes
if (baseMemberInfo != null)
return baseMemberInfo.IsDefined(attributeType, inherit);
return false;
}
internal static string EnsureTypeName(string typeName)
{
if (typeName == null || typeName.Length == 0)
return typeName;
if (typeName.IndexOf('.') == -1)
{
if (typeName.StartsWith("@", StringComparison.Ordinal))
typeName = typeName.Substring(1);
else if (typeName.StartsWith("[", StringComparison.Ordinal) && typeName.EndsWith("]", StringComparison.Ordinal))
typeName = typeName.Substring(1, typeName.Length - 1);
}
else
{
string[] tokens = typeName.Split(new char[] { '.' });
typeName = string.Empty;
int i;
for (i = 0; i < tokens.Length - 1; i++)
{
typeName += EnsureTypeName(tokens[i]);
typeName += ".";
}
typeName += EnsureTypeName(tokens[i]);
}
return typeName;
}
}
}

View File

@ -0,0 +1,22 @@
namespace System.Workflow.ComponentModel.Compiler
{
using System;
using System.CodeDom;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
[Obsolete("The System.Workflow.* types are deprecated. Instead, please use the new types from System.Activities.*")]
public interface ITypeProvider
{
Type GetType(string name);
Type GetType(string name, bool throwOnError);
Type[] GetTypes();
Assembly LocalAssembly { get; }
ICollection<Assembly> ReferencedAssemblies { get; }
IDictionary<object, Exception> TypeLoadErrors { get; }
event EventHandler TypesChanged;
event EventHandler TypeLoadErrorsChanged;
}
}

View File

@ -0,0 +1,308 @@
#pragma warning disable 1634, 1691
namespace System.Workflow.ComponentModel.Compiler
{
using System;
using System.CodeDom;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
#region DesignTimeConstructorInfo
/// <summary>
/// This class takes care of static and non-static constructors
/// </summary>
internal sealed class DesignTimeConstructorInfo : ConstructorInfo
{
#region Members and Constructors
private CodeMemberMethod codeConstructor = null;
// Data associated with a bound ctor
private DesignTimeType declaringType = null;
// Data associated with this ctor
private ParameterInfo[] parameters = null;
private Attribute[] attributes = null;
internal DesignTimeConstructorInfo(DesignTimeType declaringType, CodeMemberMethod codeConstructor)
{
this.declaringType = declaringType;
this.codeConstructor = codeConstructor;
}
#endregion
#region ConstructorInfo overrides
public override Object Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
{
throw new NotImplementedException(TypeSystemSR.GetString("Error_RuntimeNotSupported"));
}
#endregion
#region MethodBase Overrides
public override ParameterInfo[] GetParameters()
{
if (this.parameters == null)
{
// Get the parameters
CodeParameterDeclarationExpressionCollection parameters = codeConstructor.Parameters;
ParameterInfo[] paramArray = new ParameterInfo[parameters.Count];
for (int index = 0; index < parameters.Count; index++)
{
paramArray[index] = new DesignTimeParameterInfo(parameters[index], index, this);
}
this.parameters = paramArray;
}
return this.parameters; //
}
public override MethodImplAttributes GetMethodImplementationFlags()
{
return MethodImplAttributes.IL;
}
public override RuntimeMethodHandle MethodHandle
{
get
{
// not interested in Runtime information
#pragma warning suppress 56503
throw new NotImplementedException(TypeSystemSR.GetString("Error_RuntimeNotSupported"));
}
}
public override MethodAttributes Attributes
{
get
{
return Helper.ConvertToMethodAttributes(this.codeConstructor.Attributes);
}
}
public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
{
throw new NotImplementedException(TypeSystemSR.GetString("Error_RuntimeNotSupported"));
}
#endregion
#region MemberInfo Overrides
public override string Name
{
get
{
return ".ctor";
}
}
public override Type DeclaringType
{
get
{
return this.declaringType;
}
}
public override Type ReflectedType
{
get
{
return this.declaringType;
}
}
public override object[] GetCustomAttributes(bool inherit)
{
return GetCustomAttributes(typeof(object), inherit);
}
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
{
if (attributeType == null)
throw new ArgumentNullException("attributeType");
if (this.attributes == null)
this.attributes = Helper.LoadCustomAttributes(this.codeConstructor.CustomAttributes, this.DeclaringType as DesignTimeType);
return Helper.GetCustomAttributes(attributeType, inherit, this.attributes, this);
}
public override bool IsDefined(Type attributeType, bool inherit)
{
if (attributeType == null)
throw new ArgumentNullException("attributeType");
if (this.attributes == null)
this.attributes = Helper.LoadCustomAttributes(this.codeConstructor.CustomAttributes, this.DeclaringType as DesignTimeType);
if (Helper.IsDefined(attributeType, inherit, attributes, this))
return true;
return false;
}
#endregion
}
#endregion
#region DesignTimeMethodInfo
internal class DesignTimeMethodInfo : MethodInfo
{
#region Members and Constructors
private CodeMemberMethod methodInfo;
private ParameterInfo[] parameters;
// Data assocaited with a bound object
private DesignTimeType declaringType;
private Attribute[] attributes = null;
private ParameterInfo returnParam = null;
private bool isSpecialName = false;
internal DesignTimeMethodInfo(DesignTimeType declaringType, CodeMemberMethod methodInfo, bool isSpecialName)
{
this.declaringType = declaringType;
this.methodInfo = methodInfo;
this.isSpecialName = isSpecialName;
}
internal DesignTimeMethodInfo(DesignTimeType declaringType, CodeMemberMethod methodInfo)
{
this.declaringType = declaringType;
this.methodInfo = methodInfo;
}
#endregion
#region Method Info overrides
public override Type ReturnType
{
get
{
return declaringType.ResolveType(DesignTimeType.GetTypeNameFromCodeTypeReference(this.methodInfo.ReturnType, declaringType));
}
}
public override ICustomAttributeProvider ReturnTypeCustomAttributes
{
get
{
return null;
}
}
public override MethodInfo GetBaseDefinition()
{
throw new NotImplementedException();
}
public override ParameterInfo ReturnParameter
{
get
{
if (this.returnParam == null)
this.returnParam = new DesignTimeParameterInfo(this.methodInfo.ReturnType, this);
return this.returnParam;
}
}
#endregion
#region MethodBase Overrides
public override ParameterInfo[] GetParameters()
{
if (this.parameters == null)
{
// Get the parameters
CodeParameterDeclarationExpressionCollection parameters = this.methodInfo.Parameters;
ParameterInfo[] paramArray = new ParameterInfo[parameters.Count];
for (int index = 0; index < parameters.Count; index++)
{
paramArray[index] = new DesignTimeParameterInfo(parameters[index], index, this);
}
this.parameters = paramArray;
}
return this.parameters; //
}
public override MethodImplAttributes GetMethodImplementationFlags()
{
return MethodImplAttributes.IL;
}
public override RuntimeMethodHandle MethodHandle
{
get
{
// not interested in Runtime information
#pragma warning suppress 56503
throw new NotImplementedException(TypeSystemSR.GetString("Error_RuntimeNotSupported"));
}
}
public override MethodAttributes Attributes
{
get
{
return Helper.ConvertToMethodAttributes(this.methodInfo.Attributes) | (this.isSpecialName ? MethodAttributes.SpecialName : 0);
}
}
public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
{
throw new NotImplementedException(TypeSystemSR.GetString("Error_RuntimeNotSupported"));
}
#endregion
#region MemberInfo Overrides
public override string Name
{
get
{
return Helper.EnsureTypeName(this.methodInfo.Name);
}
}
public override Type DeclaringType
{
get
{
return this.declaringType;
}
}
public override Type ReflectedType
{
get
{
return this.declaringType;
}
}
public override object[] GetCustomAttributes(bool inherit)
{
return GetCustomAttributes(typeof(object), inherit);
}
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
{
if (attributeType == null)
throw new ArgumentNullException("attributeType");
if (this.attributes == null)
if (this.methodInfo == null)
this.attributes = new Attribute[0];
else
this.attributes = Helper.LoadCustomAttributes(this.methodInfo.CustomAttributes, this.DeclaringType as DesignTimeType);
return Helper.GetCustomAttributes(attributeType, inherit, this.attributes, this);
}
public override bool IsDefined(Type attributeType, bool inherit)
{
if (attributeType == null)
throw new ArgumentNullException("attributeType");
if (this.attributes == null)
this.attributes = Helper.LoadCustomAttributes(this.methodInfo.CustomAttributes, this.DeclaringType as DesignTimeType);
if (Helper.IsDefined(attributeType, inherit, attributes, this))
return true;
return false;
}
#endregion
}
#endregion
}

View File

@ -0,0 +1,58 @@
namespace System.Workflow.ComponentModel.Compiler
{
using System;
using System.CodeDom;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
#region DesignTimeParameterInfo
internal sealed class DesignTimeParameterInfo : ParameterInfo
{
#region Members and Constructors
private CodeTypeReference codeParameterType;
private bool isRef = false;
internal DesignTimeParameterInfo(CodeParameterDeclarationExpression codeParameter, int position, MemberInfo member)
{
this.MemberImpl = member;
this.NameImpl = Helper.EnsureTypeName(codeParameter.Name);
this.codeParameterType = codeParameter.Type;
this.AttrsImpl = Helper.ConvertToParameterAttributes(codeParameter.Direction);
this.isRef = (codeParameter.Direction == FieldDirection.Ref);
this.PositionImpl = position;
}
// return param ctor
internal DesignTimeParameterInfo(CodeTypeReference codeParameterType, MemberInfo member)
{
this.MemberImpl = member;
this.NameImpl = null;
this.codeParameterType = codeParameterType;
this.AttrsImpl = ParameterAttributes.None;
this.PositionImpl = -1;
}
#endregion
#region Pararmeter Info overrides
public override Type ParameterType
{
get
{
string type = DesignTimeType.GetTypeNameFromCodeTypeReference(this.codeParameterType, (this.Member.DeclaringType as DesignTimeType));
if ((this.AttrsImpl & ParameterAttributes.Out) > 0 || this.isRef)
type += '&'; // Append with & for (ref & out) parameter types
this.ClassImpl = (this.Member.DeclaringType as DesignTimeType).ResolveType(type);
return base.ParameterType;
}
}
#endregion
}
#endregion
}

View File

@ -0,0 +1,359 @@
#pragma warning disable 1634, 1691
namespace System.Workflow.ComponentModel.Compiler
{
using System;
using System.CodeDom;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
#region DesignTimePropertyInfo
internal sealed class DesignTimePropertyInfo : PropertyInfo
{
#region Members and Constructors
private Attribute[] attributes = null;
private CodeMemberProperty property = null;
private DesignTimeType declaringType = null;
private MethodInfo getMethod = null;
private MethodInfo setMethod = null;
internal DesignTimePropertyInfo(DesignTimeType declaringType, CodeMemberProperty property)
{
this.property = property;
this.declaringType = declaringType;
}
#endregion
internal CodeMemberProperty CodeMemberProperty
{
get
{
return this.property;
}
}
#region Property Info overrides
public override Type PropertyType
{
get
{
return declaringType.ResolveType(DesignTimeType.GetTypeNameFromCodeTypeReference(this.property.Type, declaringType));
}
}
public override void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)
{
throw new NotImplementedException(TypeSystemSR.GetString("Error_RuntimeNotSupported"));
}
public override MethodInfo[] GetAccessors(bool nonPublic)
{
ArrayList accessorList = new ArrayList();
if (Helper.IncludeAccessor(this.GetGetMethod(nonPublic), nonPublic))
accessorList.Add(this.getMethod);
if (Helper.IncludeAccessor(this.GetSetMethod(nonPublic), nonPublic))
accessorList.Add(this.setMethod);
return accessorList.ToArray(typeof(MethodInfo)) as MethodInfo[];
}
public override MethodInfo GetGetMethod(bool nonPublic)
{
if (this.CanRead && this.getMethod == null)
{
String accessor = "get_" + this.Name;
this.getMethod = new PropertyMethodInfo(true, accessor, this);
}
// now check to see if getMethod is public
if (nonPublic || ((this.getMethod != null) && ((this.getMethod.Attributes & MethodAttributes.Public) == MethodAttributes.Public)))
return this.getMethod;
return null;
}
public override MethodInfo GetSetMethod(bool nonPublic)
{
if (this.CanWrite && this.setMethod == null)
{
String accessor = "set_" + this.Name;
this.setMethod = new PropertyMethodInfo(false, accessor, this);
}
// now check to see if getMethod is public
if (nonPublic || ((this.setMethod != null) && ((this.setMethod.Attributes & MethodAttributes.Public) == MethodAttributes.Public)))
return this.setMethod;
return null;
}
public override ParameterInfo[] GetIndexParameters()
{
int numParams = 0;
ParameterInfo[] methParams = null;
// First try to get the Get method.
MethodInfo methodInfo = this.GetGetMethod(true);
if (methodInfo != null)
{
// There is a Get method so use it.
methParams = methodInfo.GetParameters();
numParams = methParams.Length;
}
else
{
// If there is no Get method then use the Set method.
methodInfo = GetSetMethod(true);
if (methodInfo != null)
{
methParams = methodInfo.GetParameters();
// Exclude value parameter
numParams = methParams.Length - 1;
}
}
// Now copy over the parameter info's and change their
// owning member info to the current property info.
ParameterInfo[] propParams = new ParameterInfo[numParams];
for (int i = 0; i < numParams; i++)
propParams[i] = methParams[i];
return propParams; //
}
public override PropertyAttributes Attributes
{
get
{
return PropertyAttributes.None;
}
}
public override bool CanRead
{
get
{
return this.property.HasGet;
}
}
public override bool CanWrite
{
get
{
return this.property.HasSet;
}
}
public override object GetValue(object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture)
{
throw new NotImplementedException(TypeSystemSR.GetString("Error_RuntimeNotSupported"));
}
public override string Name
{
get
{
return Helper.EnsureTypeName(this.property.Name);
}
}
public override Type DeclaringType
{
get
{
return this.declaringType;
}
}
public override Type ReflectedType
{
get
{
return this.declaringType;
}
}
#endregion
#region MemberInfo Overrides
public override object[] GetCustomAttributes(bool inherit)
{
return GetCustomAttributes(typeof(object), inherit);
}
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
{
if (attributeType == null)
throw new ArgumentNullException("attributeType");
if (this.attributes == null)
this.attributes = Helper.LoadCustomAttributes(this.property.CustomAttributes, this.DeclaringType as DesignTimeType);
return Helper.GetCustomAttributes(attributeType, inherit, this.attributes, this);
}
public override bool IsDefined(Type attributeType, bool inherit)
{
if (attributeType == null)
throw new ArgumentNullException("attributeType");
if (this.attributes == null)
this.attributes = Helper.LoadCustomAttributes(this.property.CustomAttributes, this.DeclaringType as DesignTimeType);
if (Helper.IsDefined(attributeType, inherit, attributes, this))
return true;
return false;
}
#endregion
#region PropertyInfo MethodInfo classes
private sealed class PropertyMethodInfo : MethodInfo
{
private string name = String.Empty;
private DesignTimePropertyInfo property = null;
private ParameterInfo[] parameters = null;
private bool isGetter = false;
internal PropertyMethodInfo(bool isGetter, string name, DesignTimePropertyInfo property)
{
this.isGetter = isGetter;
this.name = name;
this.property = property;
}
public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
{
throw new NotImplementedException(TypeSystemSR.GetString("Error_RuntimeNotSupported"));
}
internal bool IsGetter
{
get
{
return this.isGetter;
}
}
#region MemberInfo Overrides
public override string Name
{
get
{
return Helper.EnsureTypeName(this.name);
}
}
public override Type DeclaringType
{
get
{
return this.property.declaringType;
}
}
public override Type ReflectedType
{
get
{
return this.property.declaringType;
}
}
public override object[] GetCustomAttributes(bool inherit)
{
return GetCustomAttributes(typeof(object), inherit);
}
public override object[] GetCustomAttributes(Type attributeType, bool inherit)
{
return new Object[0];
}
public override bool IsDefined(Type attributeType, bool inherit)
{
return false;
}
#endregion
#region Method Info overrides
public override ParameterInfo ReturnParameter
{
get
{
#pragma warning suppress 56503
throw new NotImplementedException();
}
}
public override Type ReturnType
{
get
{
if (this.isGetter)
return ((DesignTimeType)this.DeclaringType).ResolveType(DesignTimeType.GetTypeNameFromCodeTypeReference(this.property.CodeMemberProperty.Type, ((DesignTimeType)this.DeclaringType)));
return typeof(void);
}
}
public override ICustomAttributeProvider ReturnTypeCustomAttributes
{
get
{
#pragma warning suppress 56503
throw new NotImplementedException();
}
}
public override MethodInfo GetBaseDefinition()
{
throw new NotImplementedException();
}
#endregion
#region MethodBase Overrides
public override ParameterInfo[] GetParameters()
{
if (this.parameters == null)
{
// Get the parameters
CodeParameterDeclarationExpressionCollection parameters = this.property.CodeMemberProperty.Parameters;
ParameterInfo[] paramArray = new ParameterInfo[this.IsGetter ? parameters.Count : parameters.Count + 1];
for (int index = 0; index < parameters.Count; index++)
{
paramArray[index] = new DesignTimeParameterInfo(parameters[index], index, this.property);
}
if (!this.IsGetter)
{
CodeParameterDeclarationExpression valueParameter = new CodeParameterDeclarationExpression(this.property.CodeMemberProperty.Type.BaseType, "value");
valueParameter.Direction = FieldDirection.In;
paramArray[parameters.Count] = new DesignTimeParameterInfo(valueParameter, 0, this.property);
}
this.parameters = paramArray;
}
return this.parameters; //
}
public override MethodImplAttributes GetMethodImplementationFlags()
{
return MethodImplAttributes.IL;
}
public override RuntimeMethodHandle MethodHandle
{
get
{
// not interested in Runtime information
#pragma warning suppress 56503
throw new NotImplementedException(TypeSystemSR.GetString("Error_RuntimeNotSupported"));
}
}
public override MethodAttributes Attributes
{
get
{
return (Helper.ConvertToMethodAttributes(this.property.CodeMemberProperty.Attributes) |
MethodAttributes.SpecialName);
}
}
#endregion
}
#endregion
}
#endregion
}

Some files were not shown because too many files have changed in this diff Show More