Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / MIT / System / Web / UI / MobileControls / Design / Converters / ChoiceConverter.cs / 1305376 / ChoiceConverter.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.Design.MobileControls.Converters
{
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Globalization;
using System.Reflection;
using System.Web.UI.Design.MobileControls.Util;
using System.Web.UI.MobileControls;
using System.Windows.Forms;
///
///
/// Can filter and retrieve several types of values from controls.
///
///
[
System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)
]
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal class ChoiceConverter: StringConverter
{
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (context != null && context.Instance is Array)
{
return value;
}
if (value is String)
{
return MatchFilterName((string)value, context);
}
return base.ConvertFrom(context, culture, value);
}
///
///
protected virtual Object [] GetChoices(Object instance)
{
bool defaultAdded = false;
DeviceSpecific deviceSpecific;
if (instance is System.Web.UI.MobileControls.StyleSheet)
{
StyleSheet ss = (StyleSheet) instance;
ISite componentSite = ss.Site;
Debug.Assert(componentSite != null, "Expected the component to be sited.");
IDesignerHost designerHost = (IDesignerHost) componentSite.GetService(typeof(IDesignerHost));
Debug.Assert(designerHost != null, "Expected a designer host.");
Object designer = designerHost.GetDesigner(ss);
Debug.Assert(designer != null, "Expected a designer for the stylesheet.");
Debug.Assert(designer is StyleSheetDesigner, "Expected a StyleSheet designer.");
StyleSheetDesigner ssd = (StyleSheetDesigner) designer;
Style style = (Style) ssd.CurrentStyle;
if (null != style)
{
deviceSpecific = style.DeviceSpecific;
}
else
{
deviceSpecific = null;
}
}
else if (instance is System.Web.UI.MobileControls.DeviceSpecific)
{
deviceSpecific = (DeviceSpecific) instance;
}
else if (instance is MobileControl)
{
MobileControl mc = (MobileControl) instance;
deviceSpecific = mc.DeviceSpecific;
}
else
{
// Simply return null if the instance is not recognizable.
return null;
}
ArrayList returnArray = new ArrayList();
// entry that corresponds to null CurrentChoice.
returnArray.Add(SR.GetString(SR.DeviceFilter_NoChoice));
if (null == deviceSpecific)
{
return returnArray.ToArray();
}
Debug.Assert(deviceSpecific.Choices != null);
foreach(DeviceSpecificChoice choice in deviceSpecific.Choices)
{
// Choice must have a Name
if (choice.Filter != null && choice.Filter.Length == 0)
{
if (!defaultAdded)
{
returnArray.Add(SR.GetString(SR.DeviceFilter_DefaultChoice));
defaultAdded = true;
}
}
else
{
if (!choice.Filter.Equals(SR.GetString(SR.DeviceFilter_NoChoice)))
{
returnArray.Add(DesignerUtility.ChoiceToUniqueIdentifier(choice));
}
}
}
returnArray.Sort();
return returnArray.ToArray();
}
///
///
/// Returns a collection of standard values retrieved from the context specified
/// by the specified type descriptor.
///
///
///
/// A type descriptor that specifies the location of the context to convert from.
///
///
///
/// A StandardValuesCollection that represents the standard values collected from
/// the specified context.
///
///
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
if (context == null || context.Instance == null)
{
return null;
}
Object [] objValues = GetChoices(context.Instance);
if (objValues != null)
{
return new StandardValuesCollection(objValues);
}
else
{
return null;
}
}
///
///
/// Gets whether
/// or not the context specified contains exclusive standard values.
///
///
///
/// A type descriptor that indicates the context to convert from.
///
///
///
/// if the specified context contains exclusive standard
/// values, otherwise .
///
///
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
///
///
/// Gets whether or not the specified context contains supported standard
/// values.
///
///
///
/// A type descriptor that indicates the context to convert from.
///
///
///
/// if the specified context conatins supported standard
/// values, otherwise .
///
///
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
private String MatchFilterName(String name, ITypeDescriptorContext context)
{
Debug.Assert(name != null, "Expected an actual device filter name to match.");
// Try a partial match
//
String bestMatch = null;
StandardValuesCollection standardValues = GetStandardValues(context);
if (standardValues == null)
{
return null;
}
IEnumerator e = standardValues.GetEnumerator();
while (e.MoveNext())
{
string filterName = e.Current.ToString();
if (String.Equals(filterName, name, StringComparison.OrdinalIgnoreCase)) {
// For an exact match, return immediately
//
return filterName;
}
else if (e.Current.ToString().StartsWith(name, StringComparison.OrdinalIgnoreCase))
{
if (bestMatch == null || filterName.Length <= bestMatch.Length)
{
bestMatch = filterName;
}
}
}
if (bestMatch == null)
{
// no match... use NoChoice
bestMatch = SR.GetString(SR.DeviceFilter_NoChoice);
}
return bestMatch;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.Design.MobileControls.Converters
{
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Globalization;
using System.Reflection;
using System.Web.UI.Design.MobileControls.Util;
using System.Web.UI.MobileControls;
using System.Windows.Forms;
///
///
/// Can filter and retrieve several types of values from controls.
///
///
[
System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)
]
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal class ChoiceConverter: StringConverter
{
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (context != null && context.Instance is Array)
{
return value;
}
if (value is String)
{
return MatchFilterName((string)value, context);
}
return base.ConvertFrom(context, culture, value);
}
///
///
protected virtual Object [] GetChoices(Object instance)
{
bool defaultAdded = false;
DeviceSpecific deviceSpecific;
if (instance is System.Web.UI.MobileControls.StyleSheet)
{
StyleSheet ss = (StyleSheet) instance;
ISite componentSite = ss.Site;
Debug.Assert(componentSite != null, "Expected the component to be sited.");
IDesignerHost designerHost = (IDesignerHost) componentSite.GetService(typeof(IDesignerHost));
Debug.Assert(designerHost != null, "Expected a designer host.");
Object designer = designerHost.GetDesigner(ss);
Debug.Assert(designer != null, "Expected a designer for the stylesheet.");
Debug.Assert(designer is StyleSheetDesigner, "Expected a StyleSheet designer.");
StyleSheetDesigner ssd = (StyleSheetDesigner) designer;
Style style = (Style) ssd.CurrentStyle;
if (null != style)
{
deviceSpecific = style.DeviceSpecific;
}
else
{
deviceSpecific = null;
}
}
else if (instance is System.Web.UI.MobileControls.DeviceSpecific)
{
deviceSpecific = (DeviceSpecific) instance;
}
else if (instance is MobileControl)
{
MobileControl mc = (MobileControl) instance;
deviceSpecific = mc.DeviceSpecific;
}
else
{
// Simply return null if the instance is not recognizable.
return null;
}
ArrayList returnArray = new ArrayList();
// entry that corresponds to null CurrentChoice.
returnArray.Add(SR.GetString(SR.DeviceFilter_NoChoice));
if (null == deviceSpecific)
{
return returnArray.ToArray();
}
Debug.Assert(deviceSpecific.Choices != null);
foreach(DeviceSpecificChoice choice in deviceSpecific.Choices)
{
// Choice must have a Name
if (choice.Filter != null && choice.Filter.Length == 0)
{
if (!defaultAdded)
{
returnArray.Add(SR.GetString(SR.DeviceFilter_DefaultChoice));
defaultAdded = true;
}
}
else
{
if (!choice.Filter.Equals(SR.GetString(SR.DeviceFilter_NoChoice)))
{
returnArray.Add(DesignerUtility.ChoiceToUniqueIdentifier(choice));
}
}
}
returnArray.Sort();
return returnArray.ToArray();
}
///
///
/// Returns a collection of standard values retrieved from the context specified
/// by the specified type descriptor.
///
///
///
/// A type descriptor that specifies the location of the context to convert from.
///
///
///
/// A StandardValuesCollection that represents the standard values collected from
/// the specified context.
///
///
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
if (context == null || context.Instance == null)
{
return null;
}
Object [] objValues = GetChoices(context.Instance);
if (objValues != null)
{
return new StandardValuesCollection(objValues);
}
else
{
return null;
}
}
///
///
/// Gets whether
/// or not the context specified contains exclusive standard values.
///
///
///
/// A type descriptor that indicates the context to convert from.
///
///
///
/// if the specified context contains exclusive standard
/// values, otherwise .
///
///
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
///
///
/// Gets whether or not the specified context contains supported standard
/// values.
///
///
///
/// A type descriptor that indicates the context to convert from.
///
///
///
/// if the specified context conatins supported standard
/// values, otherwise .
///
///
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
private String MatchFilterName(String name, ITypeDescriptorContext context)
{
Debug.Assert(name != null, "Expected an actual device filter name to match.");
// Try a partial match
//
String bestMatch = null;
StandardValuesCollection standardValues = GetStandardValues(context);
if (standardValues == null)
{
return null;
}
IEnumerator e = standardValues.GetEnumerator();
while (e.MoveNext())
{
string filterName = e.Current.ToString();
if (String.Equals(filterName, name, StringComparison.OrdinalIgnoreCase)) {
// For an exact match, return immediately
//
return filterName;
}
else if (e.Current.ToString().StartsWith(name, StringComparison.OrdinalIgnoreCase))
{
if (bestMatch == null || filterName.Length <= bestMatch.Length)
{
bestMatch = filterName;
}
}
}
if (bestMatch == null)
{
// no match... use NoChoice
bestMatch = SR.GetString(SR.DeviceFilter_NoChoice);
}
return bestMatch;
}
}
}
// 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
- StringUtil.cs
- EncryptedPackageFilter.cs
- WebRequestModulesSection.cs
- ProcessHost.cs
- ConfigurationManager.cs
- KnownColorTable.cs
- FilteredReadOnlyMetadataCollection.cs
- MenuItemCollection.cs
- TextBlockAutomationPeer.cs
- TcpAppDomainProtocolHandler.cs
- DrawingContextWalker.cs
- MouseEventArgs.cs
- ModelUIElement3D.cs
- TreeSet.cs
- LinqToSqlWrapper.cs
- ReadOnlyDataSourceView.cs
- TaskHelper.cs
- PageAdapter.cs
- AuthenticationConfig.cs
- Rectangle.cs
- Graphics.cs
- MsmqIntegrationBindingElement.cs
- QilVisitor.cs
- Converter.cs
- mediaeventshelper.cs
- COM2ComponentEditor.cs
- DBNull.cs
- BamlBinaryReader.cs
- ColumnTypeConverter.cs
- KernelTypeValidation.cs
- LineInfo.cs
- ManipulationLogic.cs
- XmlSchemaValidationException.cs
- CompilerGeneratedAttribute.cs
- FragmentNavigationEventArgs.cs
- XmlILConstructAnalyzer.cs
- NGCSerializer.cs
- HttpClientCertificate.cs
- Knowncolors.cs
- VirtualDirectoryMappingCollection.cs
- BindingSource.cs
- util.cs
- PersonalizationProvider.cs
- ScriptResourceInfo.cs
- RemoteDebugger.cs
- RelativeSource.cs
- GeneralTransform3DGroup.cs
- FormsIdentity.cs
- WebConfigurationHost.cs
- SpeechRecognizer.cs
- ScriptResourceAttribute.cs
- TrackingValidationObjectDictionary.cs
- ListBindingConverter.cs
- ProviderUtil.cs
- XmlObjectSerializerWriteContext.cs
- ToolStripControlHost.cs
- BasicBrowserDialog.designer.cs
- KeyGestureConverter.cs
- PassportIdentity.cs
- DataGridItemCollection.cs
- LabelLiteral.cs
- AppDomainFactory.cs
- XmlDigitalSignatureProcessor.cs
- DiscriminatorMap.cs
- PointLight.cs
- IFlowDocumentViewer.cs
- Paragraph.cs
- SynchronizationLockException.cs
- DataGridTable.cs
- ModelVisual3D.cs
- OdbcEnvironmentHandle.cs
- TextTreeObjectNode.cs
- FixedSOMPageConstructor.cs
- TransformGroup.cs
- TiffBitmapDecoder.cs
- PrePrepareMethodAttribute.cs
- DebugView.cs
- ProfileGroupSettingsCollection.cs
- ServiceModelActivity.cs
- Rect3DValueSerializer.cs
- SecureStringHasher.cs
- ImageListDesigner.cs
- Encoding.cs
- SqlCommandSet.cs
- ProjectionCamera.cs
- CompareInfo.cs
- SerializationTrace.cs
- SoapAttributes.cs
- ListControl.cs
- DATA_BLOB.cs
- Rectangle.cs
- DerivedKeySecurityToken.cs
- XpsFontSerializationService.cs
- AsyncPostBackTrigger.cs
- ClientBuildManager.cs
- ExtenderControl.cs
- PerformanceCountersElement.cs
- LiteralControl.cs
- HttpServerUtilityBase.cs
- PerformanceCounterPermissionAttribute.cs