Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / View / AssemblyContextControlItem.cs / 1305376 / AssemblyContextControlItem.cs
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//---------------------------------------------------------------
namespace System.Activities.Presentation.Hosting
{
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime;
using System.Diagnostics.CodeAnalysis;
using System.Activities.Presentation.Hosting;
using System.IO;
using System.Linq;
//This class is required by the TypeBrowser - it allows browsing defined types either in VS scenario or in
//rehosted scenario. The types are divided into two categories - types defined in local assembly (i.e. the one
//contained in current project - for that assembly, types are loaded using GetTypes() method), and all other
//referenced types - for them, type list is loaded using GetExportedTypes() method.
//
//if this object is not set in desinger's Items collection or both members are null, the type
//browser will not display "Browse for types" option.
[Fx.Tag.XamlVisible(false)]
public sealed class AssemblyContextControlItem : ContextItem
{
public AssemblyName LocalAssemblyName
{ get; set; }
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "This is by design")]
public IList ReferencedAssemblyNames
{
get;
set;
}
public override Type ItemType
{
get { return typeof(AssemblyContextControlItem); }
}
public IEnumerable AllAssemblyNamesInContext
{
get
{
if ((LocalAssemblyName != null) && LocalAssemblyName.CodeBase != null && (File.Exists(new Uri(LocalAssemblyName.CodeBase).LocalPath)))
{
yield return LocalAssemblyName.FullName;
}
foreach (AssemblyName assemblyName in GetEnvironmentAssemblyNames())
{
//avoid returning local name twice
if (LocalAssemblyName == null || !assemblyName.FullName.Equals(LocalAssemblyName.FullName, StringComparison.Ordinal))
{
yield return assemblyName.FullName;
}
}
}
}
public IEnumerable GetEnvironmentAssemblyNames()
{
if (this.ReferencedAssemblyNames != null)
{
return this.ReferencedAssemblyNames;
}
else
{
List assemblyNames = new List();
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
if (!assembly.IsDynamic)
{
assemblyNames.Add(assembly.GetName());
}
}
return assemblyNames;
}
}
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
Justification = "Multi-Targeting makes sense")]
public IEnumerable GetEnvironmentAssemblies (IMultiTargetingSupportService multiTargetingService)
{
if (this.ReferencedAssemblyNames == null)
{
return AppDomain.CurrentDomain.GetAssemblies().Where(assembly => !assembly.IsDynamic);
}
else
{
List assemblies = new List();
foreach (AssemblyName assemblyName in this.ReferencedAssemblyNames)
{
Assembly assembly = GetAssembly(assemblyName, multiTargetingService);
if (assembly != null)
{
assemblies.Add(assembly);
}
}
return assemblies;
}
}
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
Justification = "Multi-Targeting makes sense")]
public static Assembly GetAssembly(AssemblyName assemblyName, IMultiTargetingSupportService multiTargetingService)
{
Assembly assembly = null;
try
{
if (multiTargetingService != null)
{
assembly = multiTargetingService.GetReflectionAssembly(assemblyName);
}
else
{
assembly = Assembly.Load(assemblyName);
}
}
catch (FileNotFoundException)
{
//this exception may occur if current project is not compiled yet
}
catch (FileLoadException)
{
//the assembly could not be loaded, ignore the error
}
catch (BadImageFormatException)
{
//bad assembly
}
return assembly;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//---------------------------------------------------------------
namespace System.Activities.Presentation.Hosting
{
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime;
using System.Diagnostics.CodeAnalysis;
using System.Activities.Presentation.Hosting;
using System.IO;
using System.Linq;
//This class is required by the TypeBrowser - it allows browsing defined types either in VS scenario or in
//rehosted scenario. The types are divided into two categories - types defined in local assembly (i.e. the one
//contained in current project - for that assembly, types are loaded using GetTypes() method), and all other
//referenced types - for them, type list is loaded using GetExportedTypes() method.
//
//if this object is not set in desinger's Items collection or both members are null, the type
//browser will not display "Browse for types" option.
[Fx.Tag.XamlVisible(false)]
public sealed class AssemblyContextControlItem : ContextItem
{
public AssemblyName LocalAssemblyName
{ get; set; }
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "This is by design")]
public IList ReferencedAssemblyNames
{
get;
set;
}
public override Type ItemType
{
get { return typeof(AssemblyContextControlItem); }
}
public IEnumerable AllAssemblyNamesInContext
{
get
{
if ((LocalAssemblyName != null) && LocalAssemblyName.CodeBase != null && (File.Exists(new Uri(LocalAssemblyName.CodeBase).LocalPath)))
{
yield return LocalAssemblyName.FullName;
}
foreach (AssemblyName assemblyName in GetEnvironmentAssemblyNames())
{
//avoid returning local name twice
if (LocalAssemblyName == null || !assemblyName.FullName.Equals(LocalAssemblyName.FullName, StringComparison.Ordinal))
{
yield return assemblyName.FullName;
}
}
}
}
public IEnumerable GetEnvironmentAssemblyNames()
{
if (this.ReferencedAssemblyNames != null)
{
return this.ReferencedAssemblyNames;
}
else
{
List assemblyNames = new List();
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
if (!assembly.IsDynamic)
{
assemblyNames.Add(assembly.GetName());
}
}
return assemblyNames;
}
}
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
Justification = "Multi-Targeting makes sense")]
public IEnumerable GetEnvironmentAssemblies (IMultiTargetingSupportService multiTargetingService)
{
if (this.ReferencedAssemblyNames == null)
{
return AppDomain.CurrentDomain.GetAssemblies().Where(assembly => !assembly.IsDynamic);
}
else
{
List assemblies = new List();
foreach (AssemblyName assemblyName in this.ReferencedAssemblyNames)
{
Assembly assembly = GetAssembly(assemblyName, multiTargetingService);
if (assembly != null)
{
assemblies.Add(assembly);
}
}
return assemblies;
}
}
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly",
Justification = "Multi-Targeting makes sense")]
public static Assembly GetAssembly(AssemblyName assemblyName, IMultiTargetingSupportService multiTargetingService)
{
Assembly assembly = null;
try
{
if (multiTargetingService != null)
{
assembly = multiTargetingService.GetReflectionAssembly(assemblyName);
}
else
{
assembly = Assembly.Load(assemblyName);
}
}
catch (FileNotFoundException)
{
//this exception may occur if current project is not compiled yet
}
catch (FileLoadException)
{
//the assembly could not be loaded, ignore the error
}
catch (BadImageFormatException)
{
//bad assembly
}
return assembly;
}
}
}
// 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
- OpenTypeMethods.cs
- SoapObjectWriter.cs
- HelpInfo.cs
- HtmlInputPassword.cs
- EncryptedKeyIdentifierClause.cs
- RangeValuePatternIdentifiers.cs
- RadioButtonFlatAdapter.cs
- XmlSerializerSection.cs
- HasCopySemanticsAttribute.cs
- SqlRetyper.cs
- RepeaterItem.cs
- DataSourceXmlTextReader.cs
- XmlMembersMapping.cs
- LocalIdKeyIdentifierClause.cs
- PopupControlService.cs
- GrammarBuilderRuleRef.cs
- IdleTimeoutMonitor.cs
- SubstitutionList.cs
- TargetInvocationException.cs
- RijndaelManaged.cs
- System.Data.OracleClient_BID.cs
- BufferedWebEventProvider.cs
- ActivityStatusChangeEventArgs.cs
- AuthenticatedStream.cs
- PropertyGridCommands.cs
- JumpList.cs
- XmlDictionaryWriter.cs
- ResourceDictionary.cs
- SecurityElementBase.cs
- Composition.cs
- WebPartActionVerb.cs
- MetadataExporter.cs
- _AcceptOverlappedAsyncResult.cs
- EnumMember.cs
- ServiceDescriptionSerializer.cs
- XsltFunctions.cs
- AppDomainFactory.cs
- GridViewItemAutomationPeer.cs
- ChooseAction.cs
- GeometryDrawing.cs
- OracleDataReader.cs
- CalendarButtonAutomationPeer.cs
- SettingsSection.cs
- UnsafeNativeMethods.cs
- ActivationArguments.cs
- MapPathBasedVirtualPathProvider.cs
- ObjectDisposedException.cs
- EdmProperty.cs
- HtmlElementEventArgs.cs
- CodeExpressionStatement.cs
- ErrorFormatterPage.cs
- ExtenderProviderService.cs
- MSAAWinEventWrap.cs
- PathSegmentCollection.cs
- BitVector32.cs
- LassoHelper.cs
- EndPoint.cs
- Win32SafeHandles.cs
- FaultImportOptions.cs
- WebPartDisplayModeCancelEventArgs.cs
- DataBinding.cs
- HashCryptoHandle.cs
- _Win32.cs
- ProfilePropertyMetadata.cs
- JavaScriptSerializer.cs
- TableLayout.cs
- SoapException.cs
- BypassElement.cs
- nulltextcontainer.cs
- CallContext.cs
- ConfigXmlSignificantWhitespace.cs
- WeakHashtable.cs
- FilteredAttributeCollection.cs
- EdmEntityTypeAttribute.cs
- ColorAnimationUsingKeyFrames.cs
- DBConnection.cs
- KeyGestureConverter.cs
- SurrogateChar.cs
- XmlSerializerFormatAttribute.cs
- ConfigurationStrings.cs
- FormViewCommandEventArgs.cs
- StandardToolWindows.cs
- MenuStrip.cs
- RemoteWebConfigurationHostServer.cs
- CollectionViewGroupInternal.cs
- SQLInt64.cs
- DataControlButton.cs
- MethodImplAttribute.cs
- HMAC.cs
- EntityCommandDefinition.cs
- CurrentChangedEventManager.cs
- DefaultHttpHandler.cs
- PieceDirectory.cs
- URL.cs
- HandlerFactoryWrapper.cs
- AlternationConverter.cs
- DeploymentSectionCache.cs
- SizeChangedEventArgs.cs
- HttpDictionary.cs
- DefaultMemberAttribute.cs