/// <summary> /// Searches the radio button group and adds this radio button to the specified /// group. /// </summary> protected void InitializeGroup() { if (_elementState != ElementState.Running && _elementState != ElementState.Preparing) { return; } if (_radioButtonGroup != null) { // Remove from last group, if the group name changed _radioButtonGroup.Remove(this); } _radioButtonGroup = null; if (!string.IsNullOrEmpty(GroupName)) { INameScope ns = FindGroupNamescope(); if (ns == null) { return; } _radioButtonGroup = ns.FindName(GroupName) as ICollection <RadioButton>; if (_radioButtonGroup == null) { _radioButtonGroup = new List <RadioButton>(); ns.RegisterName(GroupName, _radioButtonGroup); } if (!_radioButtonGroup.Contains(this)) { _radioButtonGroup.Add(this); } } }
void INameScope.RegisterName(string name, object scopedElement) { INameScope scope = GetNameScope(); if (null != scope) { scope.RegisterName(name, scopedElement); } }
public static void RegisterName(DependencyObject dependencyObject, string name, object scopedElement) { INameScope nameScope = FrameworkElement.FindScope(dependencyObject); if (nameScope != null) { nameScope.RegisterName(name, scopedElement); } }
void INameScope.RegisterName(string name, object scopedElement, IXmlLineInfo xmlLineInfo) { INameScope namescope = GetNameScope(); if (namescope == null) { throw new InvalidOperationException("this element is not in a namescope"); } namescope.RegisterName(name, scopedElement, xmlLineInfo); }
//static readonly BindingFlags static_flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static; protected override void OnWriteEndMember() { var xm = CurrentMember; var state = object_states.Peek(); if (xm == XamlLanguage.PositionalParameters) { var l = (List <object>)state.Value; state.Value = escaped_objects.Pop(); state.IsInstantiated = true; PopulateObject(true, l); return; } else if (xm == XamlLanguage.Arguments) { if (state.FactoryMethod != null) { var contents = (List <object>)state.Value; var mi = state.Type.UnderlyingType.GetRuntimeMethods().FirstOrDefault(r => r.Name == state.FactoryMethod && r.IsStatic && r.GetParameters().Length == contents.Count); if (mi == null) { throw new XamlObjectWriterException(String.Format("Specified static factory method '{0}' for type '{1}' was not found", state.FactoryMethod, state.Type)); } state.Value = mi.Invoke(null, contents.ToArray()); } else { PopulateObject(true, (List <object>)state.Value); } state.IsInstantiated = true; escaped_objects.Pop(); } else if (xm == XamlLanguage.Initialization) { // ... and no need to do anything. The object value to pop *is* the return value. } else { XamlMember aliasedName = state.Type.GetAliasedProperty(XamlLanguage.Name); if (xm == XamlLanguage.Name || xm == aliasedName) { string name = (string)CurrentMemberState.Value; name_scope.RegisterName(name, state.Value); // if x:Name is used, then we set the backing property defined by RuntimeNamePropertyAttribute xm = aliasedName ?? xm; } if (!xm.IsReadOnly) // exclude read-only object such as collection item. { SetValue(xm, CurrentMemberState.Value); } } }
/// <summary> /// Registers the name - element combination from the /// NameScope that the current element belongs to. /// </summary> /// <param name="name">Name of the element</param> /// <param name="scopedElement">Element where name is defined</param> public void RegisterName(string name, object scopedElement) { INameScope nameScope = FrameworkElement.FindScope(this); if (nameScope != null) { nameScope.RegisterName(name, scopedElement); } else { throw new InvalidOperationException(SR.Get(SRID.NameScopeNotFound, name, "register")); } }
public void RegisterName(string name, object scopedElement) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (scopedElement == null) { throw new ArgumentNullException(nameof(scopedElement)); } if (name.Length == 0) { throw new ArgumentException(SR.Get(SRID.NameScopeNameNotEmptyString)); } if (!NameValidationHelper.IsValidIdentifierName(name)) { throw new ArgumentException(SR.Get(SRID.NameScopeInvalidIdentifierName, name)); } if (_underlyingNameScope != null) { _names.Add(name); _underlyingNameScope.RegisterName(name, scopedElement); } else { if (_nameMap == null) { _nameMap = new HybridDictionary(); _nameMap[name] = scopedElement; } else { object nameContext = _nameMap[name]; if (nameContext == null) { _nameMap[name] = scopedElement; } else if (scopedElement != nameContext) { throw new ArgumentException(SR.Get(SRID.NameScopeDuplicateNamesNotAllowed, name)); } } } }
/// <summary> /// Registers an instance which was created for a XAML element with its name. /// </summary> /// <param name="name">Name to register the instance. This is the value of a /// <c>x:Name</c> attribute of the XAML element corresponding to the instance.</param> /// <param name="instance">The instance to be registered. This is the instance which was /// instantiated for the XAML element which carries the specified <c>x:Name</c> attriute.</param> protected void RegisterName(string name, object instance) { try { INameScope currentNameScope = _elementContextStack.GetCurrentNameScope(); if (currentNameScope != null) { currentNameScope.RegisterName(name, instance); } } catch (ArgumentException e) { throw new XamlParserException("Duplicate name '{0}'", e, name); } }
protected void RegisterName() { INameScope ns = FindNameScope(); if (ns != null) { try { ns.RegisterName(Name, this); } catch (ArgumentException) { ServiceRegistration.Get <ILogger>().Warn("Name '" + Name + "' was registered twice in namescope '" + ns + "'"); } } }
private void ReadAttributes() { object target = _elementStack.Peek(); for (int index = 0; index < _reader.AttributeCount; index++) { _reader.MoveToAttribute(index); string name = _reader.Name.Trim(); string value = _reader.Value.Trim(); if (name.StartsWith("xmlns")) { continue; } if (string.Compare(name, "Name") == 0 || name.EndsWith(":Name")) { INameScope nameScope = (INameScope)WalkStackForSubclassOf(typeof(INameScope)); if (nameScope != null) { nameScope.RegisterName(value, target); } else { // there is no object in the stack that handles name registration so // we register the name with the Application's resource dictionary MediaPortal.App.Current.Resources.RegisterName(value, target); } } if (string.Compare(name, "Key") == 0 || name.EndsWith(":Key")) { if (value.StartsWith("{")) { MediaPortal.App.Current.Resources.Add(ReadExtension(value), _target); } else { MediaPortal.App.Current.Resources.Add(value, _target); } continue; } MemberInfo memberInfo; Type t; if (name.IndexOf('.') != -1) { string[] tokens = name.Split('.'); t = GetType(tokens[0]); memberInfo = t.GetMethod("Set" + tokens[1], BindingFlags.Public | BindingFlags.Static); name = tokens[1]; } else { t = target.GetType(); memberInfo = t.GetProperty(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance); if (memberInfo == null) { memberInfo = t.GetEvent(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance); } } if (memberInfo == null) { throw new XamlParserException(string.Format("'{0}' does not contain a definition for '{1}'", t, name), _filename, _reader); } if (value.StartsWith("{")) { if (memberInfo is PropertyInfo) { ((PropertyInfo)memberInfo).SetValue(target, ReadExtension(value), null); } else if (memberInfo is MethodInfo) { ((MethodInfo)memberInfo).Invoke(null, new object[] { target, ReadExtension(value) }); } continue; } if (memberInfo is MethodInfo) { MethodInfo methodInfo = (MethodInfo)memberInfo; TypeConverter typeConverter = GetTypeConverter(methodInfo.GetParameters()[1].ParameterType); try { object convertedFromString = typeConverter.ConvertFromString(_reader.Value); methodInfo.Invoke(null, new object[] { target, convertedFromString }); } catch (FormatException) { throw new XamlParserException( string.Format("Cannot convert '{0}' to type '{1}'", _reader.Value, methodInfo.GetParameters()[1].ParameterType), _filename, _reader); } continue; } else if (memberInfo is PropertyInfo) { PropertyInfo propertyInfo = (PropertyInfo)memberInfo; if (propertyInfo.PropertyType == typeof(object)) { propertyInfo.SetValue(target, _reader.Value, null); continue; } TypeConverter typeConverter = GetTypeConverter(propertyInfo.PropertyType); try { object convertedFromString = typeConverter.ConvertFromString(_reader.Value); if (memberInfo is PropertyInfo) { propertyInfo.SetValue(target, convertedFromString, null); } } catch (FormatException) { throw new XamlParserException( string.Format("Cannot convert '{0}' to type '{1}'", _reader.Value, propertyInfo.PropertyType), _filename, _reader); } } else if (memberInfo is EventInfo) { // TODO: Hook up to event Log.Info("Event: {0}", memberInfo.Name); } } }
public override void UpdateProperty(IInstanceBuilderContext context, ViewNode viewNode, IProperty propertyKey, DocumentNode valueNode) { string instance; string str; IPropertyId shadowProperty; ReferenceStep referenceStep = propertyKey as ReferenceStep; ViewNode item = viewNode.Properties[propertyKey]; if (item != null && DocumentNodeUtilities.IsBinding(item.DocumentNode) && referenceStep != null) { ReferenceStep referenceStep1 = referenceStep; if (context.UseShadowProperties) { shadowProperty = DesignTimeProperties.GetShadowProperty(propertyKey, viewNode.DocumentNode.Type); } else { shadowProperty = null; } IPropertyId propertyId = shadowProperty; if (propertyId != null && DesignTimeProperties.UseShadowPropertyForInstanceBuilding(context.DocumentContext.TypeResolver, propertyId)) { referenceStep1 = propertyId as ReferenceStep; } if (referenceStep1 != null) { IInstantiatedElementViewNode instantiatedElementViewNode = viewNode as IInstantiatedElementViewNode; if (instantiatedElementViewNode == null) { referenceStep1.ClearValue(viewNode.Instance); } else { foreach (object instantiatedElement in instantiatedElementViewNode.InstantiatedElements) { referenceStep1.ClearValue(instantiatedElement); } } } } if (propertyKey.DeclaringType.Metadata.IsNameProperty(propertyKey) && InstanceBuilderOperations.GetIsInlinedResourceWithoutNamescope(viewNode)) { InstanceBuilderOperations.UpdatePropertyWithoutApply(context, viewNode, propertyKey, valueNode); return; } INameScope nameScope = context.NameScope; bool flag = (nameScope == null ? false : propertyKey.DeclaringType.Metadata.IsNameProperty(propertyKey)); if (flag) { ViewNode item1 = viewNode.Properties[propertyKey]; if (item1 != null) { str = item1.Instance as string; } else { str = null; } string str1 = str; if (!string.IsNullOrEmpty(str1) && nameScope.FindName(str1) != null) { context.NameScope.UnregisterName(str1); } } if ((!context.IsSerializationScope || !(propertyKey is Event)) && (context.IsSerializationScope || !DesignTimeProperties.IsDocumentOnlyDesignTimeProperty(propertyKey))) { base.UpdateProperty(context, viewNode, propertyKey, valueNode); } else { InstanceBuilderOperations.UpdatePropertyWithoutApply(context, viewNode, propertyKey, valueNode); } if (flag) { ViewNode viewNode1 = viewNode.Properties[propertyKey]; if (viewNode1 != null) { instance = viewNode1.Instance as string; } else { instance = null; } string str2 = instance; if (!string.IsNullOrEmpty(str2)) { try { if (!str2.StartsWith("~", StringComparison.Ordinal) && !str2.Contains(".")) { if (nameScope.FindName(str2) != null) { nameScope.UnregisterName(str2); } nameScope.RegisterName(str2, viewNode.Instance); } } catch (ArgumentException argumentException1) { ArgumentException argumentException = argumentException1; ViewNodeManager viewNodeManager = viewNode1.ViewNodeManager; CultureInfo currentCulture = CultureInfo.CurrentCulture; string instanceBuilderUnableToRegisterName = ExceptionStringTable.InstanceBuilderUnableToRegisterName; object[] objArray = new object[] { str2 }; viewNodeManager.OnException(viewNode1, new InstanceBuilderException(string.Format(currentCulture, instanceBuilderUnableToRegisterName, objArray), argumentException, viewNode1.DocumentNode, viewNode), false); } } } }
public void RegisterName(string name, object element) { _scope.RegisterName(name, element); }