Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Framework / System / Windows / namescope.cs / 1 / namescope.cs
/****************************************************************************\
*
* File: NameScope.cs
*
* Used to store mapping information for names occuring
* within the logical tree section.
*
* Copyright (C) 2005 by Microsoft Corporation. All rights reserved.
*
\***************************************************************************/
using System;
using System.Windows;
using System.Collections;
using System.Collections.Specialized;
using System.Globalization;
using System.Windows.Markup;
using System.ComponentModel;
using MS.Internal;
namespace System.Windows
{
///
/// Used to store mapping information for names occuring
/// within the logical tree section.
///
public class NameScope : INameScope
{
#region INameScope
///
/// Register Name-Object Map
///
/// name to be registered
/// object mapped to name
public void RegisterName(string name, object scopedElement)
{
if (name == null)
throw new ArgumentNullException("name");
if (scopedElement == null)
throw new ArgumentNullException("scopedElement");
if (name == String.Empty)
throw new ArgumentException(SR.Get(SRID.NameScopeNameNotEmptyString));
if (!NameValidationHelper.IsValidIdentifierName(name))
{
throw new ArgumentException(SR.Get(SRID.NameScopeInvalidIdentifierName, name));
}
if (_nameMap == null)
{
_nameMap = new HybridDictionary();
_nameMap[name] = scopedElement;
}
else
{
object nameContext = _nameMap[name];
// first time adding the Name, set it
if (nameContext == null)
{
_nameMap[name] = scopedElement;
}
else if (scopedElement != nameContext)
{
throw new ArgumentException(SR.Get(SRID.NameScopeDuplicateNamesNotAllowed, name));
}
}
if( TraceNameScope.IsEnabled )
{
TraceNameScope.TraceActivityItem( TraceNameScope.RegisterName,
this,
name,
scopedElement );
}
}
///
/// Unregister Name-Object Map
///
/// name to be registered
public void UnregisterName(string name)
{
if (name == null)
throw new ArgumentNullException("name");
if (name == String.Empty)
throw new ArgumentException(SR.Get(SRID.NameScopeNameNotEmptyString));
if (_nameMap != null && _nameMap[name] != null)
{
_nameMap.Remove(name);
}
else
{
throw new ArgumentException(SR.Get(SRID.NameScopeNameNotFound, name));
}
if( TraceNameScope.IsEnabled )
{
TraceNameScope.TraceActivityItem( TraceNameScope.UnregisterName,
this, name );
}
}
///
/// Find - Find the corresponding object given a Name
///
/// Name for which context needs to be retrieved
/// corresponding Context if found, else null
public object FindName(string name)
{
if (_nameMap == null || name == null || name == String.Empty)
return null;
return _nameMap[name];
}
#endregion INameScope
#region InternalMethods
internal static INameScope NameScopeFromObject(object obj)
{
INameScope nameScope = obj as INameScope;
if (nameScope == null)
{
DependencyObject objAsDO = obj as DependencyObject;
if (objAsDO != null)
{
nameScope = GetNameScope(objAsDO);
}
}
return nameScope;
}
#endregion InternalMethods
#region DependencyProperties
///
/// NameScope property. This is an attached property.
/// This property allows the dynamic attachment of NameScopes
///
public static readonly DependencyProperty NameScopeProperty
= DependencyProperty.RegisterAttached(
"NameScope",
typeof(INameScope),
typeof(NameScope));
///
/// Helper for setting NameScope property on a DependencyObject.
///
/// Dependency Object to set NameScope property on.
/// NameScope property value.
public static void SetNameScope(DependencyObject dependencyObject, INameScope value)
{
if (dependencyObject == null)
{
throw new ArgumentNullException("dependencyObject");
}
dependencyObject.SetValue(NameScopeProperty, value);
}
///
/// Helper for reading NameScope property from a DependencyObject.
///
/// DependencyObject to read NameScope property from.
/// NameScope property value.
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public static INameScope GetNameScope(DependencyObject dependencyObject)
{
if (dependencyObject == null)
{
throw new ArgumentNullException("dependencyObject");
}
return ((INameScope)dependencyObject.GetValue(NameScopeProperty));
}
#endregion DependencyProperties
#region Data
// This is a HybridDictionary of Name-Object maps
private HybridDictionary _nameMap;
#endregion Data
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
/****************************************************************************\
*
* File: NameScope.cs
*
* Used to store mapping information for names occuring
* within the logical tree section.
*
* Copyright (C) 2005 by Microsoft Corporation. All rights reserved.
*
\***************************************************************************/
using System;
using System.Windows;
using System.Collections;
using System.Collections.Specialized;
using System.Globalization;
using System.Windows.Markup;
using System.ComponentModel;
using MS.Internal;
namespace System.Windows
{
///
/// Used to store mapping information for names occuring
/// within the logical tree section.
///
public class NameScope : INameScope
{
#region INameScope
///
/// Register Name-Object Map
///
/// name to be registered
/// object mapped to name
public void RegisterName(string name, object scopedElement)
{
if (name == null)
throw new ArgumentNullException("name");
if (scopedElement == null)
throw new ArgumentNullException("scopedElement");
if (name == String.Empty)
throw new ArgumentException(SR.Get(SRID.NameScopeNameNotEmptyString));
if (!NameValidationHelper.IsValidIdentifierName(name))
{
throw new ArgumentException(SR.Get(SRID.NameScopeInvalidIdentifierName, name));
}
if (_nameMap == null)
{
_nameMap = new HybridDictionary();
_nameMap[name] = scopedElement;
}
else
{
object nameContext = _nameMap[name];
// first time adding the Name, set it
if (nameContext == null)
{
_nameMap[name] = scopedElement;
}
else if (scopedElement != nameContext)
{
throw new ArgumentException(SR.Get(SRID.NameScopeDuplicateNamesNotAllowed, name));
}
}
if( TraceNameScope.IsEnabled )
{
TraceNameScope.TraceActivityItem( TraceNameScope.RegisterName,
this,
name,
scopedElement );
}
}
///
/// Unregister Name-Object Map
///
/// name to be registered
public void UnregisterName(string name)
{
if (name == null)
throw new ArgumentNullException("name");
if (name == String.Empty)
throw new ArgumentException(SR.Get(SRID.NameScopeNameNotEmptyString));
if (_nameMap != null && _nameMap[name] != null)
{
_nameMap.Remove(name);
}
else
{
throw new ArgumentException(SR.Get(SRID.NameScopeNameNotFound, name));
}
if( TraceNameScope.IsEnabled )
{
TraceNameScope.TraceActivityItem( TraceNameScope.UnregisterName,
this, name );
}
}
///
/// Find - Find the corresponding object given a Name
///
/// Name for which context needs to be retrieved
/// corresponding Context if found, else null
public object FindName(string name)
{
if (_nameMap == null || name == null || name == String.Empty)
return null;
return _nameMap[name];
}
#endregion INameScope
#region InternalMethods
internal static INameScope NameScopeFromObject(object obj)
{
INameScope nameScope = obj as INameScope;
if (nameScope == null)
{
DependencyObject objAsDO = obj as DependencyObject;
if (objAsDO != null)
{
nameScope = GetNameScope(objAsDO);
}
}
return nameScope;
}
#endregion InternalMethods
#region DependencyProperties
///
/// NameScope property. This is an attached property.
/// This property allows the dynamic attachment of NameScopes
///
public static readonly DependencyProperty NameScopeProperty
= DependencyProperty.RegisterAttached(
"NameScope",
typeof(INameScope),
typeof(NameScope));
///
/// Helper for setting NameScope property on a DependencyObject.
///
/// Dependency Object to set NameScope property on.
/// NameScope property value.
public static void SetNameScope(DependencyObject dependencyObject, INameScope value)
{
if (dependencyObject == null)
{
throw new ArgumentNullException("dependencyObject");
}
dependencyObject.SetValue(NameScopeProperty, value);
}
///
/// Helper for reading NameScope property from a DependencyObject.
///
/// DependencyObject to read NameScope property from.
/// NameScope property value.
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public static INameScope GetNameScope(DependencyObject dependencyObject)
{
if (dependencyObject == null)
{
throw new ArgumentNullException("dependencyObject");
}
return ((INameScope)dependencyObject.GetValue(NameScopeProperty));
}
#endregion DependencyProperties
#region Data
// This is a HybridDictionary of Name-Object maps
private HybridDictionary _nameMap;
#endregion Data
}
}
// 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
- BitHelper.cs
- ToolTipService.cs
- EditorPartCollection.cs
- OrderByQueryOptionExpression.cs
- PoisonMessageException.cs
- LocalClientSecuritySettings.cs
- PointKeyFrameCollection.cs
- Int16Converter.cs
- XDRSchema.cs
- XmlAnyElementAttribute.cs
- UniqueIdentifierService.cs
- DateTimeOffsetConverter.cs
- ReadWriteObjectLock.cs
- TextChange.cs
- DomNameTable.cs
- Assembly.cs
- XamlParser.cs
- CodeSubDirectory.cs
- ImageListStreamer.cs
- BindingExpression.cs
- DiscoveryService.cs
- XPathEmptyIterator.cs
- Visitor.cs
- WebPartEditorOkVerb.cs
- ScrollEvent.cs
- IncrementalHitTester.cs
- NotImplementedException.cs
- ConfigurationLocationCollection.cs
- IndependentlyAnimatedPropertyMetadata.cs
- CellParaClient.cs
- IPCCacheManager.cs
- CollectionConverter.cs
- HtmlControlPersistable.cs
- XmlSchemaValidationException.cs
- GridViewRowCollection.cs
- DetailsViewDesigner.cs
- GlyphTypeface.cs
- ServiceRoute.cs
- EntityDataSourceQueryBuilder.cs
- Activation.cs
- XamlToRtfParser.cs
- ProcessHostMapPath.cs
- LoginUtil.cs
- SemaphoreFullException.cs
- PanelStyle.cs
- DataGridColumn.cs
- ExpressionQuoter.cs
- DistributedTransactionPermission.cs
- XpsImageSerializationService.cs
- TextTabProperties.cs
- TransportChannelFactory.cs
- SqlReferenceCollection.cs
- DescendentsWalker.cs
- BrowserCapabilitiesCodeGenerator.cs
- MulticastOption.cs
- ExpressionEditorAttribute.cs
- ConditionCollection.cs
- ActiveDocumentEvent.cs
- OutgoingWebRequestContext.cs
- ListCollectionView.cs
- EventManager.cs
- ForEachDesigner.xaml.cs
- KeyboardDevice.cs
- JsonFormatReaderGenerator.cs
- Literal.cs
- UnmanagedMarshal.cs
- InProcStateClientManager.cs
- XsltCompileContext.cs
- SoapHeader.cs
- ScrollBarAutomationPeer.cs
- SqlClientWrapperSmiStreamChars.cs
- DataGridViewComboBoxEditingControl.cs
- UmAlQuraCalendar.cs
- ArrayWithOffset.cs
- URLMembershipCondition.cs
- TouchesCapturedWithinProperty.cs
- Padding.cs
- WpfPayload.cs
- Clipboard.cs
- XmlDataSourceNodeDescriptor.cs
- NativeObjectSecurity.cs
- ErrorHandler.cs
- EventToken.cs
- SingleSelectRootGridEntry.cs
- DataObjectPastingEventArgs.cs
- DetailsViewUpdateEventArgs.cs
- Int32.cs
- ExternalFile.cs
- SqlServer2KCompatibilityAnnotation.cs
- SkewTransform.cs
- PTProvider.cs
- EditorBrowsableAttribute.cs
- InstanceBehavior.cs
- XmlSchemaFacet.cs
- ControlBuilder.cs
- ReadOnlyDictionary.cs
- SoapFault.cs
- _UriTypeConverter.cs
- Error.cs
- NetStream.cs