private void ValidateMemberOnType(XamlMember member, XamlType type) { if (member.IsUnknown || type.IsUnknown) { return; } if (member.IsDirective) { if (member == XamlLanguage.Items) { if (!type.IsCollection && !type.IsDictionary) { ValidationError(SR.UnexpectedXamlDictionary(member.Name, GetXamlTypeName(_stack.TopFrame.Type))); } } if (member == XamlLanguage.Class && _stack.Depth > 1) { ValidationError(SR.UnexpectedXamlClass); } } else if (member.IsAttachable) { if (!type.CanAssignTo(member.TargetType)) { ValidationError(SR.UnexpectedXamlAttachableMember(member.Name, GetXamlTypeName(member.TargetType))); } } else if (!member.IsDirective && !type.CanAssignTo(member.DeclaringType)) { ValidationError(SR.UnexpectedXamlMemberNotAssignable(member.Name, GetXamlTypeName(type))); } }
/// <SecurityNote> /// Because this is a public virtual method, idempotence cannot be guaranteed. /// S.X doesn't use this method at all; but any externals consumers who are doing security checks /// based on the returned method should make sure that they are resillient to changing results. /// </SecurityNote> public virtual MethodInfo GetAddMethod(XamlType contentType) { if (contentType == null) { throw new ArgumentNullException(nameof(contentType)); } if (IsUnknown || _xamlType.ItemType == null) { return(null); } // Common case is that we match the item type. Short-circuit any additional lookup. if (contentType == _xamlType.ItemType || (_xamlType.AllowedContentTypes.Count == 1 && contentType.CanAssignTo(_xamlType.ItemType))) { return(_xamlType.AddMethod); } // Only collections can have additional content types if (!_xamlType.IsCollection) { return(null); } // Populate the dictionary of all available Add methods MethodInfo addMethod; if (_addMethods == null) { Dictionary <XamlType, MethodInfo> addMethods = new Dictionary <XamlType, MethodInfo>(); addMethods.Add(_xamlType.ItemType, _xamlType.AddMethod); foreach (XamlType type in _xamlType.AllowedContentTypes) { addMethod = CollectionReflector.GetAddMethod( _xamlType.UnderlyingType, type.UnderlyingType); if (addMethod != null) { addMethods.Add(type, addMethod); } } _addMethods = addMethods; } // First try the fast path. Look for an exact match. if (_addMethods.TryGetValue(contentType, out addMethod)) { return(addMethod); } // Next the slow path. Check each one for is assignable from. foreach (KeyValuePair <XamlType, MethodInfo> pair in _addMethods) { if (contentType.CanAssignTo(pair.Key)) { return(pair.Value); } } return(null); }
private void ValidateTypeToMemberOnStack(XamlType type) { if (type.IsUnknown) { return; } if (type == this.xNull) { ValidateValueToMemberOnStack(null); } XamlMember member = _stack.TopFrame.Member; if (member == XamlLanguage.PositionalParameters || type.IsMarkupExtension || member.IsUnknown) { return; } if (member == XamlLanguage.Items) { XamlType collectionType = GetCollectionTypeOnStack(); if (collectionType == null || collectionType.IsUnknown || collectionType.AllowedContentTypes == null) { return; } if (!collectionType.AllowedContentTypes.Any(contentType => type.CanAssignTo(contentType))) { ValidationError(SR.UnassignableCollection(GetXamlTypeName(type), GetXamlTypeName(collectionType.ItemType), GetXamlTypeName(collectionType))); } } else if (member.IsDirective && (member.Type.IsCollection || member.Type.IsDictionary)) { XamlType collectionType = member.Type; if (collectionType == null || collectionType.IsUnknown || collectionType.AllowedContentTypes == null) { return; } if (!collectionType.AllowedContentTypes.Any(contentType => type.CanAssignTo(contentType))) { ValidationError(SR.UnassignableCollection(GetXamlTypeName(type), GetXamlTypeName(collectionType.ItemType), GetXamlTypeName(collectionType))); } } else if (!type.CanAssignTo(member.Type)) { if (member.DeferringLoader != null) { return; } if (NodeType == XamlNodeType.Value) { ValidationError(SR.UnassignableTypes(GetXamlTypeName(type), GetXamlTypeName(member.Type), member.Name)); } else { ValidationError(SR.UnassignableTypesObject(GetXamlTypeName(type), GetXamlTypeName(member.Type), member.Name)); } } }
public XamlMember GetDottedProperty(XamlType tagType, string tagNamespace, XamlPropertyName propName, bool tagIsRoot) { if (tagType == null) { throw new XamlInternalException(System.Xaml.SR.Get("ParentlessPropertyElement", new object[] { propName.ScopedName })); } XamlMember xamlAttachableProperty = null; XamlType xamlType = null; string propNs = this.ResolveXamlNameNS(propName); if (propNs == null) { throw new XamlParseException(System.Xaml.SR.Get("PrefixNotFound", new object[] { propName.Prefix })); } XamlType rootTagType = tagIsRoot ? tagType : null; bool flag = false; if (tagType.IsGeneric) { flag = this.PropertyTypeMatchesGenericTagType(tagType, tagNamespace, propNs, propName.OwnerName); if (flag) { xamlAttachableProperty = this.GetInstanceOrAttachableProperty(tagType, propName.Name, rootTagType); if (xamlAttachableProperty != null) { return(xamlAttachableProperty); } } } XamlTypeName typeName = new XamlTypeName(propNs, propName.Owner.Name); xamlType = this.GetXamlType(typeName, true); bool flag2 = tagType.CanAssignTo(xamlType); if (flag2) { xamlAttachableProperty = this.GetInstanceOrAttachableProperty(xamlType, propName.Name, rootTagType); } else { xamlAttachableProperty = this.GetXamlAttachableProperty(xamlType, propName.Name); } if (xamlAttachableProperty != null) { return(xamlAttachableProperty); } XamlType declaringType = flag ? tagType : xamlType; if (flag || flag2) { return(this.CreateUnknownMember(declaringType, propName.Name)); } return(this.CreateUnknownAttachableMember(declaringType, propName.Name)); }
bool IsAssignableTo(XamlType type, Type assignableTo) { XamlType liveXamlType = this.schemaContext.GetXamlType(assignableTo); XamlType rolXamlType = this.schemaContext.GetXamlType(new XamlTypeName(liveXamlType)); if (rolXamlType == null) { // assignableTo is not in the project references, so project must not be deriving from it return(false); } return(type.CanAssignTo(rolXamlType)); }
public XamlMember GetDottedProperty(XamlType tagType, string tagNamespace, XamlPropertyName propName, bool tagIsRoot) { if (tagType == null) { throw new XamlInternalException(System.Xaml.SR.Get("ParentlessPropertyElement", new object[] { propName.ScopedName })); } XamlMember xamlAttachableProperty = null; XamlType xamlType = null; string propNs = this.ResolveXamlNameNS(propName); if (propNs == null) { throw new XamlParseException(System.Xaml.SR.Get("PrefixNotFound", new object[] { propName.Prefix })); } XamlType rootTagType = tagIsRoot ? tagType : null; bool flag = false; if (tagType.IsGeneric) { flag = this.PropertyTypeMatchesGenericTagType(tagType, tagNamespace, propNs, propName.OwnerName); if (flag) { xamlAttachableProperty = this.GetInstanceOrAttachableProperty(tagType, propName.Name, rootTagType); if (xamlAttachableProperty != null) { return xamlAttachableProperty; } } } XamlTypeName typeName = new XamlTypeName(propNs, propName.Owner.Name); xamlType = this.GetXamlType(typeName, true); bool flag2 = tagType.CanAssignTo(xamlType); if (flag2) { xamlAttachableProperty = this.GetInstanceOrAttachableProperty(xamlType, propName.Name, rootTagType); } else { xamlAttachableProperty = this.GetXamlAttachableProperty(xamlType, propName.Name); } if (xamlAttachableProperty != null) { return xamlAttachableProperty; } XamlType declaringType = flag ? tagType : xamlType; if (flag || flag2) { return this.CreateUnknownMember(declaringType, propName.Name); } return this.CreateUnknownAttachableMember(declaringType, propName.Name); }
public virtual MethodInfo GetAddMethod(XamlType contentType) { if (contentType == null) { throw new ArgumentNullException("contentType"); } if (!this.IsUnknown && (this._xamlType.ItemType != null)) { MethodInfo addMethod; if ((contentType == this._xamlType.ItemType) || ((this._xamlType.AllowedContentTypes.Count == 1) && contentType.CanAssignTo(this._xamlType.ItemType))) { return(this._xamlType.AddMethod); } if (!this._xamlType.IsCollection) { return(null); } if (this._addMethods == null) { Dictionary <XamlType, MethodInfo> dictionary = new Dictionary <XamlType, MethodInfo>(); dictionary.Add(this._xamlType.ItemType, this._xamlType.AddMethod); foreach (XamlType type in this._xamlType.AllowedContentTypes) { addMethod = CollectionReflector.GetAddMethod(this._xamlType.UnderlyingType, type.UnderlyingType); if (addMethod != null) { dictionary.Add(type, addMethod); } } this._addMethods = dictionary; } if (this._addMethods.TryGetValue(contentType, out addMethod)) { return(addMethod); } foreach (KeyValuePair <XamlType, MethodInfo> pair in this._addMethods) { if (contentType.CanAssignTo(pair.Key)) { return(pair.Value); } } } return(null); }
internal XamlMember GetProperty(Int16 propertyId, XamlType parentType) { BamlProperty bamlProperty; XamlMember xamlMember; if (TryGetBamlProperty(propertyId, out bamlProperty, out xamlMember)) { if (xamlMember != null) { return(xamlMember); } XamlType declaringType = GetXamlType(bamlProperty.DeclaringTypeId); // If the parent type & declaring type are assignable, then it could // be either a regular property or attachable. if (parentType.CanAssignTo(declaringType)) { xamlMember = declaringType.GetMember(bamlProperty.Name); if (xamlMember == null) { xamlMember = declaringType.GetAttachableMember(bamlProperty.Name); } } else { //If not assignable, it has to be an attachable member xamlMember = declaringType.GetAttachableMember(bamlProperty.Name); } lock (_syncObject) { _bamlProperty[propertyId] = xamlMember; } return(xamlMember); } throw new KeyNotFoundException(); }
// Token: 0x0600226B RID: 8811 RVA: 0x000AAF38 File Offset: 0x000A9138 internal static void TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, bool onlyLoadOneNode, bool skipJournaledProperties, bool shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack <WpfXamlFrame> stack, IStyleConnector styleConnector) { while (xamlReader.Read()) { if (shouldPassLineNumberInfo && xamlLineInfo.LineNumber != 0) { xamlLineInfoConsumer.SetLineInfo(xamlLineInfo.LineNumber, xamlLineInfo.LinePosition); } switch (xamlReader.NodeType) { case XamlNodeType.StartObject: WpfXamlLoader.WriteStartObject(xamlReader, xamlWriter, stack); break; case XamlNodeType.GetObject: xamlWriter.WriteNode(xamlReader); if (stack.CurrentFrame.Type != null) { stack.PushScope(); } stack.CurrentFrame.Type = stack.PreviousFrame.Property.Type; break; case XamlNodeType.EndObject: { xamlWriter.WriteNode(xamlReader); if (stack.CurrentFrame.FreezeFreezable) { Freezable freezable = xamlWriter.Result as Freezable; if (freezable != null && freezable.CanFreeze) { freezable.Freeze(); } } DependencyObject dependencyObject = xamlWriter.Result as DependencyObject; if (dependencyObject != null && stack.CurrentFrame.XmlSpace != null) { XmlAttributeProperties.SetXmlSpace(dependencyObject, stack.CurrentFrame.XmlSpace.Value ? "default" : "preserve"); } stack.PopScope(); break; } case XamlNodeType.StartMember: if ((!xamlReader.Member.IsDirective || !(xamlReader.Member == XamlReaderHelper.Freeze)) && xamlReader.Member != WpfXamlLoader.XmlSpace.Value && xamlReader.Member != XamlLanguage.Space) { xamlWriter.WriteNode(xamlReader); } stack.CurrentFrame.Property = xamlReader.Member; if (skipJournaledProperties && !stack.CurrentFrame.Property.IsDirective) { WpfXamlMember wpfXamlMember = stack.CurrentFrame.Property as WpfXamlMember; if (wpfXamlMember != null) { DependencyProperty dependencyProperty = wpfXamlMember.DependencyProperty; if (dependencyProperty != null) { FrameworkPropertyMetadata frameworkPropertyMetadata = dependencyProperty.GetMetadata(stack.CurrentFrame.Type.UnderlyingType) as FrameworkPropertyMetadata; if (frameworkPropertyMetadata != null && frameworkPropertyMetadata.Journal) { int num = 1; while (xamlReader.Read()) { switch (xamlReader.NodeType) { case XamlNodeType.StartObject: { XamlType type = xamlReader.Type; XamlType xamlType = type.SchemaContext.GetXamlType(typeof(BindingBase)); XamlType xamlType2 = type.SchemaContext.GetXamlType(typeof(DynamicResourceExtension)); if (num == 1 && (type.CanAssignTo(xamlType) || type.CanAssignTo(xamlType2))) { num = 0; WpfXamlLoader.WriteStartObject(xamlReader, xamlWriter, stack); } break; } case XamlNodeType.StartMember: num++; break; case XamlNodeType.EndMember: num--; if (num == 0) { xamlWriter.WriteNode(xamlReader); stack.CurrentFrame.Property = null; } break; case XamlNodeType.Value: { DynamicResourceExtension dynamicResourceExtension = xamlReader.Value as DynamicResourceExtension; if (dynamicResourceExtension != null) { WpfXamlLoader.WriteValue(xamlReader, xamlWriter, stack, styleConnector); } break; } } if (num == 0) { break; } } } } } } break; case XamlNodeType.EndMember: { WpfXamlFrame currentFrame = stack.CurrentFrame; XamlMember property = currentFrame.Property; if ((!property.IsDirective || !(property == XamlReaderHelper.Freeze)) && property != WpfXamlLoader.XmlSpace.Value && property != XamlLanguage.Space) { xamlWriter.WriteNode(xamlReader); } currentFrame.Property = null; break; } case XamlNodeType.Value: WpfXamlLoader.WriteValue(xamlReader, xamlWriter, stack, styleConnector); break; case XamlNodeType.NamespaceDeclaration: xamlWriter.WriteNode(xamlReader); if (stack.Depth == 0 || stack.CurrentFrame.Type != null) { stack.PushScope(); for (WpfXamlFrame wpfXamlFrame = stack.CurrentFrame; wpfXamlFrame != null; wpfXamlFrame = (WpfXamlFrame)wpfXamlFrame.Previous) { if (wpfXamlFrame.XmlnsDictionary != null) { stack.CurrentFrame.XmlnsDictionary = new XmlnsDictionary(wpfXamlFrame.XmlnsDictionary); break; } } if (stack.CurrentFrame.XmlnsDictionary == null) { stack.CurrentFrame.XmlnsDictionary = new XmlnsDictionary(); } } stack.CurrentFrame.XmlnsDictionary.Add(xamlReader.Namespace.Prefix, xamlReader.Namespace.Namespace); break; default: xamlWriter.WriteNode(xamlReader); break; } if (onlyLoadOneNode) { return; } } }
internal XamlMember GetProperty(Int16 propertyId, XamlType parentType) { BamlProperty bamlProperty; XamlMember xamlMember; if (TryGetBamlProperty(propertyId, out bamlProperty, out xamlMember)) { if (xamlMember != null) { return xamlMember; } XamlType declaringType = GetXamlType(bamlProperty.DeclaringTypeId); // If the parent type & declaring type are assignable, then it could // be either a regular property or attachable. if (parentType.CanAssignTo(declaringType)) { xamlMember = declaringType.GetMember(bamlProperty.Name); if (xamlMember == null) { xamlMember = declaringType.GetAttachableMember(bamlProperty.Name); } } else { //If not assignable, it has to be an attachable member xamlMember = declaringType.GetAttachableMember(bamlProperty.Name); } lock (_syncObject) { _bamlProperty[propertyId] = xamlMember; } return xamlMember; } throw new KeyNotFoundException(); }
internal static void TransformNodes(System.Xaml.XamlReader xamlReader, System.Xaml.XamlObjectWriter xamlWriter, bool onlyLoadOneNode, bool skipJournaledProperties, bool shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack <WpfXamlFrame> stack, IStyleConnector styleConnector) { while (xamlReader.Read()) { if (shouldPassLineNumberInfo) { if (xamlLineInfo.LineNumber != 0) { xamlLineInfoConsumer.SetLineInfo(xamlLineInfo.LineNumber, xamlLineInfo.LinePosition); } } switch (xamlReader.NodeType) { case System.Xaml.XamlNodeType.NamespaceDeclaration: xamlWriter.WriteNode(xamlReader); if (stack.Depth == 0 || stack.CurrentFrame.Type != null) { stack.PushScope(); // Need to create an XmlnsDictionary. // Look up stack to see if we have one earlier // If so, use that. Otherwise new a xmlnsDictionary WpfXamlFrame iteratorFrame = stack.CurrentFrame; while (iteratorFrame != null) { if (iteratorFrame.XmlnsDictionary != null) { stack.CurrentFrame.XmlnsDictionary = new XmlnsDictionary(iteratorFrame.XmlnsDictionary); break; } iteratorFrame = (WpfXamlFrame)iteratorFrame.Previous; } if (stack.CurrentFrame.XmlnsDictionary == null) { stack.CurrentFrame.XmlnsDictionary = new XmlnsDictionary(); } } stack.CurrentFrame.XmlnsDictionary.Add(xamlReader.Namespace.Prefix, xamlReader.Namespace.Namespace); break; case System.Xaml.XamlNodeType.StartObject: WriteStartObject(xamlReader, xamlWriter, stack); break; case System.Xaml.XamlNodeType.GetObject: xamlWriter.WriteNode(xamlReader); // If there wasn't a namespace node before this get object, need to pushScope. if (stack.CurrentFrame.Type != null) { stack.PushScope(); } stack.CurrentFrame.Type = stack.PreviousFrame.Property.Type; break; case System.Xaml.XamlNodeType.EndObject: xamlWriter.WriteNode(xamlReader); // Freeze if required if (stack.CurrentFrame.FreezeFreezable) { Freezable freezable = xamlWriter.Result as Freezable; if (freezable != null && freezable.CanFreeze) { freezable.Freeze(); } } DependencyObject dependencyObject = xamlWriter.Result as DependencyObject; if (dependencyObject != null && stack.CurrentFrame.XmlSpace.HasValue) { XmlAttributeProperties.SetXmlSpace(dependencyObject, stack.CurrentFrame.XmlSpace.Value ? "default" : "preserve"); } stack.PopScope(); break; case System.Xaml.XamlNodeType.StartMember: // ObjectWriter should NOT process PresentationOptions:Freeze directive since it is Unknown // The space directive node stream should not be written because it induces object instantiation, // and the Baml2006Reader can produce space directives prematurely. if (!(xamlReader.Member.IsDirective && xamlReader.Member == XamlReaderHelper.Freeze) && xamlReader.Member != XmlSpace.Value && xamlReader.Member != XamlLanguage.Space) { xamlWriter.WriteNode(xamlReader); } stack.CurrentFrame.Property = xamlReader.Member; if (skipJournaledProperties) { if (!stack.CurrentFrame.Property.IsDirective) { System.Windows.Baml2006.WpfXamlMember wpfMember = stack.CurrentFrame.Property as System.Windows.Baml2006.WpfXamlMember; if (wpfMember != null) { DependencyProperty prop = wpfMember.DependencyProperty; if (prop != null) { FrameworkPropertyMetadata metadata = prop.GetMetadata(stack.CurrentFrame.Type.UnderlyingType) as FrameworkPropertyMetadata; if (metadata != null && metadata.Journal == true) { // Ignore the BAML for this member, unless it declares a value that wasn't journaled - namely a binding or a dynamic resource int count = 1; while (xamlReader.Read()) { switch (xamlReader.NodeType) { case System.Xaml.XamlNodeType.StartMember: count++; break; case System.Xaml.XamlNodeType.StartObject: XamlType xamlType = xamlReader.Type; XamlType bindingBaseType = xamlType.SchemaContext.GetXamlType(typeof(BindingBase)); XamlType dynamicResourceType = xamlType.SchemaContext.GetXamlType(typeof(DynamicResourceExtension)); if (count == 1 && (xamlType.CanAssignTo(bindingBaseType) || xamlType.CanAssignTo(dynamicResourceType))) { count = 0; WriteStartObject(xamlReader, xamlWriter, stack); } break; case System.Xaml.XamlNodeType.EndMember: count--; if (count == 0) { xamlWriter.WriteNode(xamlReader); stack.CurrentFrame.Property = null; } break; case System.Xaml.XamlNodeType.Value: DynamicResourceExtension value = xamlReader.Value as DynamicResourceExtension; if (value != null) { WriteValue(xamlReader, xamlWriter, stack, styleConnector); } break; } if (count == 0) { break; } } System.Diagnostics.Debug.Assert(count == 0, "Mismatch StartMember/EndMember"); } } } } } break; case System.Xaml.XamlNodeType.EndMember: WpfXamlFrame currentFrame = stack.CurrentFrame; XamlMember currentProperty = currentFrame.Property; // ObjectWriter should not process PresentationOptions:Freeze directive nodes since it is unknown // The space directive node stream should not be written because it induces object instantiation, // and the Baml2006Reader can produce space directives prematurely. if (!(currentProperty.IsDirective && currentProperty == XamlReaderHelper.Freeze) && currentProperty != XmlSpace.Value && currentProperty != XamlLanguage.Space) { xamlWriter.WriteNode(xamlReader); } currentFrame.Property = null; break; case System.Xaml.XamlNodeType.Value: WriteValue(xamlReader, xamlWriter, stack, styleConnector); break; default: xamlWriter.WriteNode(xamlReader); break; } //Only do this loop for one node if loadAsync if (onlyLoadOneNode) { return; } } }
public virtual MethodInfo GetAddMethod(XamlType contentType) { if (contentType == null) { throw new ArgumentNullException("contentType"); } if (!this.IsUnknown && (this._xamlType.ItemType != null)) { MethodInfo addMethod; if ((contentType == this._xamlType.ItemType) || ((this._xamlType.AllowedContentTypes.Count == 1) && contentType.CanAssignTo(this._xamlType.ItemType))) { return this._xamlType.AddMethod; } if (!this._xamlType.IsCollection) { return null; } if (this._addMethods == null) { Dictionary<XamlType, MethodInfo> dictionary = new Dictionary<XamlType, MethodInfo>(); dictionary.Add(this._xamlType.ItemType, this._xamlType.AddMethod); foreach (XamlType type in this._xamlType.AllowedContentTypes) { addMethod = CollectionReflector.GetAddMethod(this._xamlType.UnderlyingType, type.UnderlyingType); if (addMethod != null) { dictionary.Add(type, addMethod); } } this._addMethods = dictionary; } if (this._addMethods.TryGetValue(contentType, out addMethod)) { return addMethod; } foreach (KeyValuePair<XamlType, MethodInfo> pair in this._addMethods) { if (contentType.CanAssignTo(pair.Key)) { return pair.Value; } } } return null; }
private IEnumerable <XamlNode> LogicStream_CheckForStartGetCollectionFromMember() { XamlType type1 = this._context.CurrentType; XamlMember currentMember = this._context.CurrentMember; XamlType type = currentMember.Type; XamlType iteratorVariable2 = (this._xamlScanner.NodeType == ScannerNodeType.TEXT) ? XamlLanguage.String : this._xamlScanner.Type; if (type.IsArray && (this._xamlScanner.Type != this.ArrayExtensionType)) { IEnumerable <NamespaceDeclaration> newNamespaces = null; XamlTypeName iteratorVariable4 = new XamlTypeName(type.ItemType); INamespacePrefixLookup prefixLookup = new NamespacePrefixLookup(out newNamespaces, new Func <string, string>(this._context.FindNamespaceByPrefix)); string data = iteratorVariable4.ToString(prefixLookup); foreach (NamespaceDeclaration iteratorVariable7 in newNamespaces) { yield return(new XamlNode(XamlNodeType.NamespaceDeclaration, iteratorVariable7)); } yield return(this.Logic_StartObject(this.ArrayExtensionType, null)); this._context.CurrentInImplicitArray = true; yield return(this.Logic_StartMember(this.ArrayTypeMember)); yield return(new XamlNode(XamlNodeType.Value, data)); yield return(this.Logic_EndMember()); yield return(this.Logic_EndOfAttributes()); yield return(this.Logic_StartMember(this.ItemsTypeMember)); XamlType currentType = this._context.CurrentType; currentMember = this._context.CurrentMember; type = currentMember.Type; } if (!currentMember.IsDirective && (type.IsCollection || type.IsDictionary)) { bool iteratorVariable8 = false; if (currentMember.IsReadOnly || !this._context.CurrentMemberIsWriteVisible()) { iteratorVariable8 = true; } else if (((type.TypeConverter != null) && !currentMember.IsReadOnly) && (this._xamlScanner.NodeType == ScannerNodeType.TEXT)) { iteratorVariable8 = false; } else if (((iteratorVariable2 == null) || !iteratorVariable2.CanAssignTo(type)) && (iteratorVariable2 != null)) { if (!iteratorVariable2.IsMarkupExtension || this._xamlScanner.HasKeyAttribute) { iteratorVariable8 = true; } else if (iteratorVariable2 == XamlLanguage.Array) { iteratorVariable8 = true; } } if (iteratorVariable8) { yield return(this.Logic_StartGetObjectFromMember(type)); yield return(this.Logic_StartItemsProperty(type)); } } }
/// <summary> /// Resolves a property of the form 'Foo.Bar' or 'a:Foo.Bar', in /// in the context of a parent tag. The parent tagType may or may not /// be covariant with the ownerType. In the case of dotted attribute /// syntax, the namespace my be passed in. /// </summary> /// <param name="tagType">The xamlType of the enclosing Tag</param> /// <param name="tagNamespace">The namespace of the enclosing Tag</param> /// <param name="propName">The dotted name of the property</param> /// <param name="tagIsRoot">Whether the tag is the root of the document</param> /// <returns></returns> public XamlMember GetDottedProperty(XamlType tagType, string tagNamespace, XamlPropertyName propName, bool tagIsRoot) { if (tagType == null) { throw new XamlInternalException(SR.Get(SRID.ParentlessPropertyElement, propName.ScopedName)); } XamlMember property = null; XamlType ownerType = null; string ns = ResolveXamlNameNS(propName); if (ns == null) { throw new XamlParseException(SR.Get(SRID.PrefixNotFound, propName.Prefix)); } XamlType rootTagType = tagIsRoot ? tagType : null; // If we have <foo x:TA="" foo.bar=""/> we want foo in foo.bar to match the tag // type since there is no way to specify generic syntax in dotted property notation // If that fails, then we fall back to the non-generic case below. bool ownerTypeMatchesGenericTagType = false; if (tagType.IsGeneric) { ownerTypeMatchesGenericTagType = PropertyTypeMatchesGenericTagType(tagType, tagNamespace, ns, propName.OwnerName); if (ownerTypeMatchesGenericTagType) { property = GetInstanceOrAttachableProperty(tagType, propName.Name, rootTagType); if (property != null) { return(property); } } } // Non-generic case, just resolve using the namespace and name XamlTypeName ownerTypeName = new XamlTypeName(ns, propName.Owner.Name); ownerType = GetXamlType(ownerTypeName, true); bool canAssignTagTypeToOwnerType = tagType.CanAssignTo(ownerType); if (canAssignTagTypeToOwnerType) { property = GetInstanceOrAttachableProperty(ownerType, propName.Name, rootTagType); } else { property = GetXamlAttachableProperty(ownerType, propName.Name); } if (property == null) { // This is an unknown property. // We don't know for sure whether or not it's attachable, so we go with our best guess. // If the owner type is same as the generic tag type, or is assignable to the tag type, // it's probably not attachable. XamlType declaringType = ownerTypeMatchesGenericTagType ? tagType : ownerType; if (ownerTypeMatchesGenericTagType || canAssignTagTypeToOwnerType) { property = CreateUnknownMember(declaringType, propName.Name); } else { property = CreateUnknownAttachableMember(declaringType, propName.Name); } } return(property); }
private void InjectPropertyAndFrameIfNeeded(XamlType elementType, SByte flags) { // If we saved the Node stream for the first ME element of a dictionary to // check if it had a key then process that now. if (_lookingForAKeyOnAMarkupExtensionInADictionaryDepth == _context.CurrentFrame.Depth) { RestoreSavedFirstItemInDictionary(); } XamlType parentType = _context.CurrentFrame.XamlType; XamlMember parentProperty = _context.CurrentFrame.Member; if (parentType != null) { if (parentProperty == null) { // We have got two consecutive ElementStart records // We must insert an implicit content property between them if (_context.CurrentFrame.ContentProperty != null) { _context.CurrentFrame.Member = parentProperty = _context.CurrentFrame.ContentProperty; } else if (parentType.ContentProperty != null) { _context.CurrentFrame.Member = parentProperty = parentType.ContentProperty; } else { if (parentType.IsCollection || parentType.IsDictionary) { _context.CurrentFrame.Member = parentProperty = XamlLanguage.Items; } else if (parentType.TypeConverter != null) { _context.CurrentFrame.Member = parentProperty = XamlLanguage.Initialization; } else { throw new XamlParseException(SR.Get(SRID.RecordOutOfOrder, parentType.Name)); } } _context.CurrentFrame.Flags = Baml2006ReaderFrameFlags.HasImplicitProperty; _xamlNodesWriter.WriteStartMember(parentProperty); // if we are NOT already spooling a template if (_context.TemplateStartDepth < 0 && _isBinaryProvider) { if (parentProperty == BamlSchemaContext.FrameworkTemplateTemplateProperty) { // If this is a template then spool the template into a Node List. _context.TemplateStartDepth = _context.CurrentFrame.Depth; _xamlTemplateNodeList = new XamlNodeList(_xamlNodesWriter.SchemaContext); _xamlWriterStack.Push(_xamlNodesWriter); _xamlNodesWriter = _xamlTemplateNodeList.Writer; } } } XamlType parentPropertyType = parentProperty.Type; // Normally an error except for collections if (parentPropertyType != null && (parentPropertyType.IsCollection || parentPropertyType.IsDictionary) && !parentProperty.IsDirective && (flags & ReaderFlags_AddedToTree) == 0) { bool emitPreamble = false; // If the collection property is Readonly then "retrieve" the collection. if (parentProperty.IsReadOnly) { emitPreamble = true; } // OR if the Value isn't assignable to the Collection emit the preable. else if (!elementType.CanAssignTo(parentPropertyType)) { // UNLESS: the Value is a Markup extension, then it is assumed that // the ProvidValue type will be AssignableFrom. if (!elementType.IsMarkupExtension) { emitPreamble = true; } // EXCEPT: if the BAML said it was Retrived else if (_context.CurrentFrame.Flags == Baml2006ReaderFrameFlags.HasImplicitProperty) { emitPreamble = true; } // OR: the ME is Array else if (elementType == XamlLanguage.Array) { emitPreamble = true; } } if (emitPreamble) { EmitGoItemsPreamble(parentPropertyType); } // We may need to look for an x:Key on the ME in a dictionary. // so save up the node stream for the whole element definition and check it // for an x:Key later. if (!emitPreamble && parentPropertyType.IsDictionary && elementType.IsMarkupExtension) { StartSavingFirstItemInDictionary(); } } } }
private IEnumerable <XamlNode> LogicStream_CheckForStartGetCollectionFromMember() { XamlType currentType = _context.CurrentType; XamlMember currentProperty = _context.CurrentMember; XamlType propertyType = currentProperty.Type; XamlType valueElementType = (_xamlScanner.NodeType == ScannerNodeType.TEXT) ? XamlLanguage.String : _xamlScanner.Type; if (propertyType.IsArray && _xamlScanner.Type != ArrayExtensionType) { IEnumerable <NamespaceDeclaration> newNamespaces = null; XamlTypeName typeName = new XamlTypeName(propertyType.ItemType); INamespacePrefixLookup prefixResolver = new NamespacePrefixLookup(out newNamespaces, _context.FindNamespaceByPrefix); string typeNameString = typeName.ToString(prefixResolver); // SideEffects!!! prefixResolver will populate newNamespaces foreach (NamespaceDeclaration nsDecl in newNamespaces) { yield return(new XamlNode(XamlNodeType.NamespaceDeclaration, nsDecl)); } yield return(Logic_StartObject(ArrayExtensionType, null)); _context.CurrentInImplicitArray = true; yield return(Logic_StartMember(ArrayTypeMember)); yield return(new XamlNode(XamlNodeType.Value, typeNameString)); yield return(Logic_EndMember()); yield return(Logic_EndOfAttributes()); yield return(Logic_StartMember(ItemsTypeMember)); currentType = _context.CurrentType; currentProperty = _context.CurrentMember; propertyType = currentProperty.Type; } // Now Consider inserting special preamble to "Get" the collection: // . GO // . . SM _items if (!currentProperty.IsDirective && (propertyType.IsCollection || propertyType.IsDictionary)) { bool emitPreamble = false; // If the collection property is Readonly then "Get" the collection. if (currentProperty.IsReadOnly || !_context.CurrentMemberIsWriteVisible()) { emitPreamble = true; } // If the collection is R/W and there is a type converter and we have Text // use the type converter rather than the GO; SM _items; else if (propertyType.TypeConverter != null && !currentProperty.IsReadOnly && _xamlScanner.NodeType == ScannerNodeType.TEXT) { emitPreamble = false; } // Or if the Value (this is the first value in the collection) // isn't assignable to the Collection then "Get" the collection. else if (valueElementType == null || !valueElementType.CanAssignTo(propertyType)) { if (valueElementType != null) { // Unless: the Value is a Markup extension, in which case it is // assumed that the ProvideValue() type will be AssignableFrom // or If the next object has an x:Key in which case it must be // a dictionary entry. // so Don't "Get" the collection. if (!valueElementType.IsMarkupExtension || _xamlScanner.HasKeyAttribute) { emitPreamble = true; } // Except: the Array Extension can never return a dictionary // so for Array Extension do "Get" the collection. // Note Array Extension would be suitable for List Collections // Note: a fully validating parser should look at MarkupExtensionReturnType // for this choice, there might be other MarkupExtensions that fit this. else if (valueElementType == XamlLanguage.Array) { emitPreamble = true; } } } if (emitPreamble) { yield return(Logic_StartGetObjectFromMember(propertyType)); yield return(Logic_StartItemsProperty(propertyType)); } } }