Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / Base / Core / PropertyEditing / newitemfactory.cs / 1305376 / newitemfactory.cs
namespace System.Activities.Presentation.PropertyEditing {
using System;
using System.Windows;
using System.Reflection;
using System.IO;
using System.Windows.Markup;
using System.Windows.Media.Imaging;
using System.Windows.Controls;
using System.Activities.Presentation.Internal;
using System.Diagnostics.CodeAnalysis;
using System.Activities.Presentation;
///
/// Base class that represents a factory for creating new items for a collection or
/// for a property value. 3rd party control developers may choose to derive from this class
/// to override the default behavior of specifying names and images that are used by
/// collection editor and sub-property editor when creating instances of custom controls.
///
class NewItemFactory {
private Type[] NoTypes = new Type[0];
///
/// Default constructor
///
public NewItemFactory() { }
///
/// Returns an object that can be set as the Content of a ContentControl
/// and that will be used an icon for the requested type by the property editing host.
/// The default implementation of this method uses naming convention, searching for
/// the embedded resources in the same assembly as the control, that are named the
/// same as the control (including namespace), followed by ".Icon", followed by
/// the extension for the file type itself. Currently, only ".png", ".bmp", ".gif",
/// ".jpg", and ".jpeg" extensions are recognized.
///
/// Type of the object to look up
/// The desired size of the image to retrieve. If multiple
/// images are available this method retrieves the image that most closely
/// resembles the requested size. However, it is not guaranteed to return an image
/// that matches the desired size exactly.
/// An image for the specified type.
/// If type is null
public virtual object GetImage(Type type, Size desiredSize) {
if (type == null)
throw FxTrace.Exception.ArgumentNull("type");
return ManifestImages.GetImage(type, desiredSize);
}
///
/// Returns the name for the item this factory adds for the passed in type. This is
/// the name that will be used in the "Add Item" drop down to identify the type being added.
/// The default implementation returns the short type name.
///
/// Type to retrieve the display name for.
/// The display name for the specified type
/// If type is null
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "The intended usage in the larger scope of the class is the stronger type")]
public virtual string GetDisplayName(Type type)
{
if (type == null)
throw FxTrace.Exception.ArgumentNull("type");
return type.Name;
}
///
/// Returns an instance of an item that is added to the collection for the passed in Type.
/// The default implementation looks for public constructors that take no arguments.
/// If no such constructors are found, null is returned.
///
/// Type of the object to create
/// Instance of the specified type, or null if no appropriate constructor was found
///
/// If type is null
public virtual object CreateInstance(Type type) {
if (type == null)
throw FxTrace.Exception.ArgumentNull("type");
ConstructorInfo ctor = type.GetConstructor(
BindingFlags.Public | BindingFlags.Instance,
null,
NoTypes,
null);
return ctor == null ? null : ctor.Invoke(null);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
namespace System.Activities.Presentation.PropertyEditing {
using System;
using System.Windows;
using System.Reflection;
using System.IO;
using System.Windows.Markup;
using System.Windows.Media.Imaging;
using System.Windows.Controls;
using System.Activities.Presentation.Internal;
using System.Diagnostics.CodeAnalysis;
using System.Activities.Presentation;
///
/// Base class that represents a factory for creating new items for a collection or
/// for a property value. 3rd party control developers may choose to derive from this class
/// to override the default behavior of specifying names and images that are used by
/// collection editor and sub-property editor when creating instances of custom controls.
///
class NewItemFactory {
private Type[] NoTypes = new Type[0];
///
/// Default constructor
///
public NewItemFactory() { }
///
/// Returns an object that can be set as the Content of a ContentControl
/// and that will be used an icon for the requested type by the property editing host.
/// The default implementation of this method uses naming convention, searching for
/// the embedded resources in the same assembly as the control, that are named the
/// same as the control (including namespace), followed by ".Icon", followed by
/// the extension for the file type itself. Currently, only ".png", ".bmp", ".gif",
/// ".jpg", and ".jpeg" extensions are recognized.
///
/// Type of the object to look up
/// The desired size of the image to retrieve. If multiple
/// images are available this method retrieves the image that most closely
/// resembles the requested size. However, it is not guaranteed to return an image
/// that matches the desired size exactly.
/// An image for the specified type.
/// If type is null
public virtual object GetImage(Type type, Size desiredSize) {
if (type == null)
throw FxTrace.Exception.ArgumentNull("type");
return ManifestImages.GetImage(type, desiredSize);
}
///
/// Returns the name for the item this factory adds for the passed in type. This is
/// the name that will be used in the "Add Item" drop down to identify the type being added.
/// The default implementation returns the short type name.
///
/// Type to retrieve the display name for.
/// The display name for the specified type
/// If type is null
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "The intended usage in the larger scope of the class is the stronger type")]
public virtual string GetDisplayName(Type type)
{
if (type == null)
throw FxTrace.Exception.ArgumentNull("type");
return type.Name;
}
///
/// Returns an instance of an item that is added to the collection for the passed in Type.
/// The default implementation looks for public constructors that take no arguments.
/// If no such constructors are found, null is returned.
///
/// Type of the object to create
/// Instance of the specified type, or null if no appropriate constructor was found
///
/// If type is null
public virtual object CreateInstance(Type type) {
if (type == null)
throw FxTrace.Exception.ArgumentNull("type");
ConstructorInfo ctor = type.GetConstructor(
BindingFlags.Public | BindingFlags.Instance,
null,
NoTypes,
null);
return ctor == null ? null : ctor.Invoke(null);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CollectionViewGroupInternal.cs
- SelectionRangeConverter.cs
- ObjectAnimationUsingKeyFrames.cs
- TextRangeEditLists.cs
- EncodingTable.cs
- ZipIOZip64EndOfCentralDirectoryBlock.cs
- EncoderReplacementFallback.cs
- EntityContainerEntitySetDefiningQuery.cs
- HttpModuleActionCollection.cs
- ConfigXmlAttribute.cs
- RealProxy.cs
- UInt32.cs
- TokenBasedSet.cs
- StringArrayConverter.cs
- RepeaterCommandEventArgs.cs
- ValidationErrorCollection.cs
- XhtmlTextWriter.cs
- ApplyImportsAction.cs
- AppDomainCompilerProxy.cs
- OleDbDataAdapter.cs
- SoapCommonClasses.cs
- IsolatedStoragePermission.cs
- CheckedPointers.cs
- MetadataArtifactLoaderComposite.cs
- PageEventArgs.cs
- XmlUnspecifiedAttribute.cs
- BehaviorEditorPart.cs
- bidPrivateBase.cs
- OleDbStruct.cs
- EditorPart.cs
- Decoder.cs
- Helpers.cs
- ExpressionBuilder.cs
- ClipboardData.cs
- ActivityExecutionContext.cs
- RawTextInputReport.cs
- NativeDirectoryServicesQueryAPIs.cs
- WizardStepBase.cs
- NameGenerator.cs
- DrawingState.cs
- IMembershipProvider.cs
- PenContext.cs
- CompositeFontFamily.cs
- LayoutEditorPart.cs
- _UriSyntax.cs
- EntityContainerEntitySetDefiningQuery.cs
- ListControlActionList.cs
- SqlResolver.cs
- CurrentChangingEventManager.cs
- AxisAngleRotation3D.cs
- Symbol.cs
- ErrorsHelper.cs
- PathTooLongException.cs
- TextReturnReader.cs
- SByte.cs
- NotFiniteNumberException.cs
- PointHitTestResult.cs
- TileModeValidation.cs
- SqlDataSourceAdvancedOptionsForm.cs
- PipeStream.cs
- WebColorConverter.cs
- ProfileProvider.cs
- CheckStoreFileValidityRequest.cs
- FrameSecurityDescriptor.cs
- SqlGatherProducedAliases.cs
- Command.cs
- GeneralTransform2DTo3DTo2D.cs
- oledbconnectionstring.cs
- LinqDataSourceUpdateEventArgs.cs
- OpenTypeCommon.cs
- ProtocolsConfigurationEntry.cs
- coordinatorscratchpad.cs
- CommentEmitter.cs
- ClientSponsor.cs
- PropertyFilterAttribute.cs
- MultipleViewProviderWrapper.cs
- RecordManager.cs
- InitiatorSessionSymmetricTransportSecurityProtocol.cs
- XNodeValidator.cs
- StreamSecurityUpgradeAcceptor.cs
- CodeAttributeArgument.cs
- DriveNotFoundException.cs
- QuotedPrintableStream.cs
- SchemaNamespaceManager.cs
- X500Name.cs
- QuotedStringFormatReader.cs
- typedescriptorpermission.cs
- CompensationParticipant.cs
- ContextMenu.cs
- HtmlControl.cs
- DebugController.cs
- Clipboard.cs
- _LazyAsyncResult.cs
- SqlInternalConnectionSmi.cs
- ProfileSettings.cs
- PictureBox.cs
- ElementUtil.cs
- GeneralTransform2DTo3DTo2D.cs
- XsltLoader.cs
- ContentElement.cs