Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / AddIn / AddIn / System / Addin / Hosting / Store / AddInAdapter.cs / 1305376 / AddInAdapter.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: AddInAdapter ** ** Purpose: Represents an add-in adapter on disk ** ===========================================================*/ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Globalization; using System.Reflection; using System.Text; using System.AddIn.MiniReflection; using System.Diagnostics.Contracts; namespace System.AddIn { [Serializable] internal sealed class AddInAdapter : PipelineComponent { private List_contracts; private List _constructors; public AddInAdapter(TypeInfo typeInfo, String assemblyLocation) : base(typeInfo, assemblyLocation) { _contracts = new List (); _constructors = new List (); } public List Constructors { get { return _constructors; } } public List Contracts { get { return _contracts; } } public override String ToString() { return String.Format(CultureInfo.CurrentCulture, Res.AddInAdapterToString, Name, BestAvailableLocation); } internal override bool Validate(Type type, Collection warnings) { System.Diagnostics.Contracts.Contract.Assert(type.Assembly.ReflectionOnly && IContractInReflectionLoaderContext.Assembly.ReflectionOnly, "Both the type and IContract should be in the ReflectionOnly loader context"); if (!type.IsMarshalByRef) { warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.AddInAdapterMustBeMBRO, type.AssemblyQualifiedName)); return false; } //if (!type.Implements(typeofIContract)) if (!IContractInReflectionLoaderContext.IsAssignableFrom(type)) { warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.AddInAdapterMustImplementAnAddInContract, type.AssemblyQualifiedName)); return false; } foreach (Type contractInterface in type.GetInterfaces()) { //if (contractInterface.Implements(typeofIContract)) if (IContractInReflectionLoaderContext.IsAssignableFrom(contractInterface)) _contracts.Add(new TypeInfo(contractInterface)); } if (_contracts.Count == 0) { warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.AddInAdapterMustImplementAnAddInContract, type.AssemblyQualifiedName)); return false; } foreach (ConstructorInfo ctor in type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { ParameterInfo[] pars = ctor.GetParameters(); if (pars.Length != 1) { warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.AddInAdapterOneUnusableConstructor, type.AssemblyQualifiedName)); continue; } _constructors.Add(new TypeInfo(pars[0].ParameterType)); } if (_constructors.Count == 0) { warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.AddInAdapterNoUsableConstructors, type.AssemblyQualifiedName)); return false; } return base.Validate(type, warnings); } // Imagine a generic AddInBase (AB ), and an AddInAdapter with a // constructor taking in AB . If we have IntAddIn : AB , // then we should be able to hook this up. internal bool CanConnectTo(AddInBase addInBase) { System.Diagnostics.Contracts.Contract.Requires(addInBase != null); if (!addInBase.TypeInfo.IsGeneric) { if (this.Constructors.Contains(addInBase.TypeInfo)) return true; // return true if we have a constructor that accepts one of addinBase's ActivatableAs base classes if (addInBase._activatableAs != null) { foreach (TypeInfo activatableAsTypeInfo in addInBase._activatableAs) { if (this.Constructors.Contains(activatableAsTypeInfo)) return true; } } } else { return false; } return false; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: AddInAdapter ** ** Purpose: Represents an add-in adapter on disk ** ===========================================================*/ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Globalization; using System.Reflection; using System.Text; using System.AddIn.MiniReflection; using System.Diagnostics.Contracts; namespace System.AddIn { [Serializable] internal sealed class AddInAdapter : PipelineComponent { private List _contracts; private List _constructors; public AddInAdapter(TypeInfo typeInfo, String assemblyLocation) : base(typeInfo, assemblyLocation) { _contracts = new List (); _constructors = new List (); } public List Constructors { get { return _constructors; } } public List Contracts { get { return _contracts; } } public override String ToString() { return String.Format(CultureInfo.CurrentCulture, Res.AddInAdapterToString, Name, BestAvailableLocation); } internal override bool Validate(Type type, Collection warnings) { System.Diagnostics.Contracts.Contract.Assert(type.Assembly.ReflectionOnly && IContractInReflectionLoaderContext.Assembly.ReflectionOnly, "Both the type and IContract should be in the ReflectionOnly loader context"); if (!type.IsMarshalByRef) { warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.AddInAdapterMustBeMBRO, type.AssemblyQualifiedName)); return false; } //if (!type.Implements(typeofIContract)) if (!IContractInReflectionLoaderContext.IsAssignableFrom(type)) { warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.AddInAdapterMustImplementAnAddInContract, type.AssemblyQualifiedName)); return false; } foreach (Type contractInterface in type.GetInterfaces()) { //if (contractInterface.Implements(typeofIContract)) if (IContractInReflectionLoaderContext.IsAssignableFrom(contractInterface)) _contracts.Add(new TypeInfo(contractInterface)); } if (_contracts.Count == 0) { warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.AddInAdapterMustImplementAnAddInContract, type.AssemblyQualifiedName)); return false; } foreach (ConstructorInfo ctor in type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { ParameterInfo[] pars = ctor.GetParameters(); if (pars.Length != 1) { warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.AddInAdapterOneUnusableConstructor, type.AssemblyQualifiedName)); continue; } _constructors.Add(new TypeInfo(pars[0].ParameterType)); } if (_constructors.Count == 0) { warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.AddInAdapterNoUsableConstructors, type.AssemblyQualifiedName)); return false; } return base.Validate(type, warnings); } // Imagine a generic AddInBase (AB ), and an AddInAdapter with a // constructor taking in AB . If we have IntAddIn : AB , // then we should be able to hook this up. internal bool CanConnectTo(AddInBase addInBase) { System.Diagnostics.Contracts.Contract.Requires(addInBase != null); if (!addInBase.TypeInfo.IsGeneric) { if (this.Constructors.Contains(addInBase.TypeInfo)) return true; // return true if we have a constructor that accepts one of addinBase's ActivatableAs base classes if (addInBase._activatableAs != null) { foreach (TypeInfo activatableAsTypeInfo in addInBase._activatableAs) { if (this.Constructors.Contains(activatableAsTypeInfo)) return true; } } } else { return false; } return false; } } } // 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
- ConversionHelper.cs
- DPTypeDescriptorContext.cs
- ExceptionValidationRule.cs
- CalendarButtonAutomationPeer.cs
- QilPatternFactory.cs
- DbParameterCollection.cs
- Propagator.Evaluator.cs
- PeerNameRecord.cs
- AppSettingsExpressionBuilder.cs
- ObjectFullSpanRewriter.cs
- ToolStripContentPanelRenderEventArgs.cs
- MenuStrip.cs
- DelegatingTypeDescriptionProvider.cs
- MetadataArtifactLoaderCompositeFile.cs
- NumberFunctions.cs
- FixedTextView.cs
- InfoCardKeyedHashAlgorithm.cs
- XmlDataDocument.cs
- WebPartConnection.cs
- DesignConnectionCollection.cs
- Rect3D.cs
- FormCollection.cs
- PathFigureCollectionConverter.cs
- HttpApplication.cs
- SamlConditions.cs
- NavigationCommands.cs
- ByteKeyFrameCollection.cs
- WebPartVerb.cs
- CodeThrowExceptionStatement.cs
- TemplateComponentConnector.cs
- SoapIncludeAttribute.cs
- LineInfo.cs
- Triplet.cs
- BindingWorker.cs
- TextWriter.cs
- Utils.cs
- XamlReaderHelper.cs
- StaticExtension.cs
- DataGridViewCellErrorTextNeededEventArgs.cs
- DataGridColumnCollection.cs
- TableLayout.cs
- FontInfo.cs
- MemoryRecordBuffer.cs
- X509ChainElement.cs
- Fonts.cs
- CompositeFontFamily.cs
- InstallerTypeAttribute.cs
- AppDomainInfo.cs
- Stroke.cs
- SecUtil.cs
- QueryContinueDragEvent.cs
- CodeExpressionCollection.cs
- ComponentGuaranteesAttribute.cs
- HwndSubclass.cs
- ScrollableControl.cs
- HwndSource.cs
- EtwTrace.cs
- XmlSecureResolver.cs
- BindingExpressionUncommonField.cs
- TheQuery.cs
- XamlBrushSerializer.cs
- XmlName.cs
- RawStylusInputCustomDataList.cs
- XPathNavigator.cs
- XMLDiffLoader.cs
- CroppedBitmap.cs
- SizeIndependentAnimationStorage.cs
- PropertyDescriptorComparer.cs
- DrawTreeNodeEventArgs.cs
- ResourceProviderFactory.cs
- SerialPort.cs
- SafeNativeMethods.cs
- RightsManagementEncryptionTransform.cs
- CaseExpr.cs
- TextMarkerSource.cs
- OperationFormatUse.cs
- HttpCapabilitiesEvaluator.cs
- DifferencingCollection.cs
- ExternalCalls.cs
- CompModSwitches.cs
- GAC.cs
- ListViewTableCell.cs
- ValidationUtility.cs
- CompilerResults.cs
- SizeFConverter.cs
- EntityTypeEmitter.cs
- CodeNamespaceImport.cs
- TypeBuilder.cs
- ContentDefinition.cs
- Page.cs
- TemplatePropertyEntry.cs
- externdll.cs
- ThaiBuddhistCalendar.cs
- ImageSource.cs
- SQLMembershipProvider.cs
- CfgRule.cs
- ExpressionPrefixAttribute.cs
- PointKeyFrameCollection.cs
- ConvertersCollection.cs
- PolicyException.cs