示例#1
0
        public void ListMembers()
        {
            var xt = new XamlType(typeof(List <int>), sctx);
            var ml = xt.GetAllMembers().ToArray();

            Assert.AreEqual(1, ml.Length, "#1");
            Assert.IsNotNull(xt.GetMember("Capacity"), "#2");
        }
示例#2
0
        public void ContentIncluded()
        {
            var xt = new XamlType(typeof(ContentIncludedClass), sctx);
            var xm = xt.GetMember("Content");

            Assert.AreEqual(xm, xt.ContentProperty, "#1");
            Assert.IsTrue(xt.GetAllMembers().Contains(xm), "#2");
        }
示例#3
0
        public void ReadOnlyPropertyContainer()
        {
            var xt = new XamlType(typeof(ReadOnlyPropertyContainer), sctx);
            var xm = xt.GetMember("Bar");

            Assert.IsNotNull(xm, "#1");
            Assert.IsFalse(xm.IsWritePublic, "#2");
        }
示例#4
0
        private static XamlMember GetColorMember(XamlType xType, string colorType)
        {
            switch (colorType)
            {
            case "textColor":
                return(xType.GetMember("Foreground"));

            case "normalTitleColor":
                return(xType.GetMember("Foreground"));

            case "backgroundColor":
                return(xType.GetMember("Background"));

            case "highlightedTitleColor":
                return(xType.GetMember("Background"));

            case "highlightedColor":
                return(xType.GetMember("Background"));

            case "shadowColor":
                return(xType.GetMember("Background"));

            case "tintColor":
                return(xType.GetMember("Background"));

            default:
                throw new NotImplementedException("Doesn't support color type: " + colorType);
            }
        }
示例#5
0
        public void DependencyPropertyWithNoClrProperty()
        {
            XamlSchemaContext xsc     = System.Windows.Markup.XamlReader.GetWpfSchemaContext();
            XamlType          xType   = xsc.GetXamlType(typeof(XamlTestClasses.BamlTestType));
            XamlMember        xMember = xType.GetMember("DpWithNoClrProperty");

            Assert.IsNotNull(xMember);
            Assert.AreEqual(xMember.Type, xType);
        }
示例#6
0
        public void DependencyPropertyTypeMistmatch()
        {
            XamlSchemaContext xsc     = System.Windows.Markup.XamlReader.GetWpfSchemaContext();
            XamlType          xType   = xsc.GetXamlType(typeof(XamlTestClasses.BamlTestType));
            XamlMember        xMember = xType.GetMember("TypeMismatch");

            Assert.IsNotNull(xMember);
            Assert.AreEqual(xMember.TypeConverter, XamlLanguage.Int32.TypeConverter);
        }
示例#7
0
        private XamlMemberBase GetMember(XamlMemberBase member)
        {
            if (IsLevelOneAndThereIsRootInstance && !member.IsDirective)
            {
                return(rootInstanceXamlType == null ? member : rootInstanceXamlType.GetMember(member.Name));
            }

            return(member);
        }
示例#8
0
        // Only pass rootObjectType if the member is being looked up on the root object
        public XamlMember GetXamlProperty(XamlType xamlType, string propertyName, XamlType rootObjectType)
        {
            if (xamlType.IsUnknown)
            {
                return(null);
            }
            XamlMember member = xamlType.GetMember(propertyName);

            return(IsVisible(member, rootObjectType) ? member : null);
        }
示例#9
0
        public void RoutedEventWithNoRoutedEventProperty()
        {
            XamlSchemaContext xsc     = System.Windows.Markup.XamlReader.GetWpfSchemaContext();
            XamlType          xType   = xsc.GetXamlType(typeof(XamlTestClasses.BamlTestType));
            XamlMember        xMember = xType.GetMember("RoutedEventWithNoClrEvent");

            Assert.IsNotNull(xMember);
            Assert.IsTrue(xMember.IsEvent);
            Assert.AreEqual(xMember.TypeConverter.Name, "EventConverter");
        }
        private static XamlMember GetXamlMember(XamlSchemaContext schemaContext, Type type, string memberName)
        {
            XamlType xamlType = schemaContext.GetXamlType(type);

            if (xamlType == null)
            {
                return(null);
            }
            return(xamlType.GetMember(memberName));
        }
示例#11
0
        public void CustomArrayExtension()
        {
            var xt = new XamlType(typeof(MyArrayExtension), sctx);
            var xm = xt.GetMember("Items");

            Assert.IsNotNull(xt.GetAllMembers().FirstOrDefault(m => m.Name == "Items"), "#0");
            Assert.IsNotNull(xm, "#1");
            Assert.IsFalse(xm.IsReadOnly, "#2");              // Surprisingly it is False. Looks like XAML ReadOnly is true only if it lacks set accessor. Having private member does not make it ReadOnly.
            Assert.IsTrue(xm.Type.IsCollection, "#3");
            Assert.IsFalse(xm.Type.IsConstructible, "#4");
        }
示例#12
0
 private void ValidateUnknown(XamlMember member)
 {
     if (member == XamlLanguage.UnknownContent)
     {
         ValidationError(SR.MemberUnknownContect(GetXamlTypeName(_stack.TopFrame.Type)));
     }
     else if (member.IsUnknown)
     {
         bool     retryAttachable = false;
         XamlType declaringType   = member.DeclaringType;
         if (_stack.Depth == 1 && declaringType.IsUnknown &&
             !string.IsNullOrEmpty(this.rootNamespace) &&
             this.definedType != null && declaringType.Name == this.definedType.Name)
         {
             // Need to handle the case where the namespace of a member on the document root
             // is missing the project root namespace
             string clrNs;
             if (XamlBuildTaskServices.TryExtractClrNs(declaringType.PreferredXamlNamespace, out clrNs))
             {
                 clrNs = string.IsNullOrEmpty(clrNs) ? this.rootNamespace : this.rootNamespace + "." + clrNs;
                 if (clrNs == this.definedType.Namespace)
                 {
                     declaringType   = SchemaContext.GetXamlType(this.definedType);
                     retryAttachable = true;
                 }
             }
         }
         XamlMember typeMember = declaringType.GetMember(member.Name);
         if (typeMember == null && retryAttachable)
         {
             typeMember = declaringType.GetAttachableMember(member.Name);
         }
         if (typeMember == null || typeMember.IsUnknown)
         {
             if (member.IsAttachable)
             {
                 ValidationError(SR.UnresolvedAttachableMember(GetXamlTypeName(member.DeclaringType) + "." + member.Name));
             }
             else if (member.IsDirective)
             {
                 ValidationError(SR.UnresolvedDirective(member.PreferredXamlNamespace + ":" + member.Name));
             }
             else
             {
                 // Skip if declaring type is unknown as the member unknown error messages become redundant.
                 if (declaringType != null && !declaringType.IsUnknown)
                 {
                     ValidationError(SR.UnresolvedMember(member.Name, GetXamlTypeName(declaringType)));
                 }
             }
         }
     }
 }
        public void TestSM_2()
        {
            XamlSchemaContext context   = new XamlSchemaContext();
            XamlObjectWriter  objWriter = new XamlObjectWriter(context);

            XamlType type = context.GetXamlType(typeof(Element10));

            objWriter.WriteStartObject(type);

            XamlMember member = type.GetMember("Element3");

            objWriter.WriteStartMember(member);

            XamlMember member2 = type.GetMember("Element7");

            /* should fail here */
            objWriter.WriteStartMember(member2);

            objWriter.Clear();
            objWriter.Close();
        }
        public void TestV_7()
        {
            XamlObjectWriter objWriter = Setup_SO_SM_V();

            XamlType   type   = objWriter.SchemaContext.GetXamlType(typeof(Element10));
            XamlMember member = type.GetMember("Element0");

            /* should fail here */
            objWriter.WriteStartMember(member);

            objWriter.Clear();
            objWriter.Close();
        }
示例#15
0
        public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext, CultureInfo cultureInfo, object value)
        {
            String s = value as string;

            if (String.IsNullOrEmpty(s))
            {
                throw new ArgumentException("XAML can only convert from Strings");
            }

            int    dashIdx   = s.IndexOf('-');
            string color     = s;
            string colorType = String.Empty;

            if (dashIdx > 1)
            {
                color     = s.Substring(0, dashIdx);
                colorType = s.Substring(dashIdx + 1);
            }

            ColorElement e = null;

            if (colorType == "Duel")
            {
                e           = new ColorElementDuel();
                e.ColorName = color;
                return(e);
            }
            else
            {
                e = new ColorElement();
            }

            IXamlSchemaContextProvider schemaContextProvider = (IXamlSchemaContextProvider)typeDescriptorContext.GetService(typeof(IXamlSchemaContextProvider));
            IAmbientProvider           iAmbient = (IAmbientProvider)typeDescriptorContext.GetService(typeof(IAmbientProvider));

            XamlType             ambientLabel = schemaContextProvider.SchemaContext.GetXamlType(typeof(HasAmbientLabel));
            XamlMember           label        = ambientLabel.GetMember("Label");
            AmbientPropertyValue apVal        = iAmbient.GetFirstAmbientValue(null, label);

            if (apVal == null)
            {
                e.ColorName = color;
            }
            else
            {
                e.ColorName = color + "-" + apVal.Value.ToString();
            }
            return(e);
        }
        private static IEnumerable<XamlInstruction> ParseProperties(IEnumerable<PropertyOption> options, XamlType xamlType)
        {
            foreach (var option in options)
            {
                var member = xamlType.GetMember(option.Property);
                yield return Inject.StartOfMember(member);

                var stringNode = option.Value as StringNode;
                if (stringNode != null)
                {
                    yield return Inject.Value(stringNode.Value);
                }

                yield return Inject.EndOfMember();
            }
        }
        // support method.
        static XamlObjectWriter Setup_SO_SM_V()
        {
            XamlSchemaContext context   = new XamlSchemaContext();
            XamlObjectWriter  objWriter = new XamlObjectWriter(context);

            XamlType type = context.GetXamlType(typeof(Object10));

            objWriter.WriteStartObject(type);

            XamlMember member = type.GetMember("Object0");

            objWriter.WriteStartMember(member);

            objWriter.WriteValue("XYZZY-42");

            return(objWriter);
        }
        // Setters and triggers may have a sourceName which we need to resolve
        // This only works in templates and it works by looking up the mapping between
        // name and type in the template.  We use ambient lookup to find the Template property
        // and then query it for the type.
        private static Type GetTypeFromName(XamlSchemaContext schemaContext,
                                            IAmbientProvider ambientProvider,
                                            string target)
        {
            XamlType   frameworkTemplateXType = schemaContext.GetXamlType(typeof(FrameworkTemplate));
            XamlMember templateProperty       = frameworkTemplateXType.GetMember("Template");

            AmbientPropertyValue ambientValue =
                ambientProvider.GetFirstAmbientValue(new XamlType[] { frameworkTemplateXType }, templateProperty);
            TemplateContent templateHolder =
                ambientValue.Value as System.Windows.TemplateContent;

            if (templateHolder != null)
            {
                return(templateHolder.GetTypeForName(target).UnderlyingType);
            }
            return(null);
        }
示例#19
0
        static LocalClass BuildSomething()
        {
            XamlSchemaContext schema       = new XamlSchemaContext();
            XamlObjectWriter  xow          = new XamlObjectWriter(schema);
            XamlType          xamlType     = schema.GetXamlType(typeof(LocalClass));
            XamlMember        xamlProperty = xamlType.GetMember("Title");

            xow.WriteStartObject(xamlType);
            xow.WriteStartMember(xamlProperty);
            xow.WriteValue("This is a string");
            xow.WriteEndMember();
            xow.WriteEndObject();

            object o = xow.Result;

            LocalClass local = (LocalClass)o;

            return(local);
        }
        // Token: 0x0600210D RID: 8461 RVA: 0x00098390 File Offset: 0x00096590
        private static Type GetTypeFromName(XamlSchemaContext schemaContext, IAmbientProvider ambientProvider, string target)
        {
            XamlType             xamlType          = schemaContext.GetXamlType(typeof(FrameworkTemplate));
            XamlMember           member            = xamlType.GetMember("Template");
            AmbientPropertyValue firstAmbientValue = ambientProvider.GetFirstAmbientValue(new XamlType[]
            {
                xamlType
            }, new XamlMember[]
            {
                member
            });
            TemplateContent templateContent = firstAmbientValue.Value as TemplateContent;

            if (templateContent != null)
            {
                return(templateContent.GetTypeForName(target).UnderlyingType);
            }
            return(null);
        }
        public void WriteStringValueForPropertyOfTypeString()
        {
            XamlSchemaContext xsc = new XamlSchemaContext();
            XamlObjectWriter  ow  = new XamlObjectWriter(xsc);

            XamlType simpleElementXT = xsc.GetXamlType(typeof(ElementWithSimpleProperties));

            ow.WriteStartObject(simpleElementXT);
            ow.WriteStartMember(simpleElementXT.GetMember("String"));
            ow.WriteValue("23.5");
            ow.WriteEndMember();
            ow.WriteEndObject();

            ElementWithSimpleProperties simpleElement = (ElementWithSimpleProperties)(ow.Result);

            if ("23.5" != simpleElement.String)
            {
                throw new Exception("simpleElement.String==\"" + simpleElement.String + "\" ; expected \"23.5\"");
            }
        }
        public void WriteIntegerValueForPropertyOfTypeDouble()
        {
            XamlSchemaContext xsc = new XamlSchemaContext();
            XamlObjectWriter  ow  = new XamlObjectWriter(xsc);

            XamlType simpleElementXT = xsc.GetXamlType(typeof(ElementWithSimpleProperties));

            ow.WriteStartObject(simpleElementXT);
            ow.WriteStartMember(simpleElementXT.GetMember("Double"));
            ow.WriteValue(23);
            ow.WriteEndMember();
            ow.WriteEndObject();

            ElementWithSimpleProperties simpleElement = (ElementWithSimpleProperties)(ow.Result);

            if (23 != simpleElement.Double)
            {
                throw new Exception("simpleElement.Double==" + simpleElement.Double + " ; expected 23.  Int32 didn't work.");
            }
        }
示例#23
0
        private ProtoXamlNode ConvertAttributeToNode(XamlType containingType, UnprocessedAttribute rawAttribute)
        {
            XamlMember member;

            if (rawAttribute.Locator.IsDotted)
            {
                var ownerName = rawAttribute.Locator.Owner.PropertyName;
                var ownerPrefix = rawAttribute.Locator.Owner.Prefix;

                var owner = wiringContext.TypeContext.GetByPrefix(ownerPrefix, ownerName);

                member = owner.GetAttachableMember(rawAttribute.Locator.PropertyName);
            }
            else
            {
                member = containingType.GetMember(rawAttribute.Locator.PropertyName);
            }

            return nodeBuilder.Attribute(member, rawAttribute.Value, rawAttribute.Locator.Prefix);
        }
        // TODO: Refactor this shit.
        private ProtoXamlInstruction ConvertAttributeToNode(XamlType containingType, AttributeAssignment rawAttributeAssignment)
        {
            MutableXamlMember member;

            if (rawAttributeAssignment.Locator.IsDotted)
            {
                member = GetMemberForDottedLocator(rawAttributeAssignment.Locator);
            }
            else
            {
                if (IsNameDirective(rawAttributeAssignment.Locator, containingType))
                {
                    return instructionBuilder.Directive(CoreTypes.Name, rawAttributeAssignment.Value);
                }

                member = containingType.GetMember(rawAttributeAssignment.Locator.PropertyName);
            }

            var namespaceDeclaration = new NamespaceDeclaration(rawAttributeAssignment.Locator.Namespace, rawAttributeAssignment.Locator.Prefix);
            return instructionBuilder.Attribute(member, rawAttributeAssignment.Value, namespaceDeclaration.Prefix);
        }
        private ProtoXamlInstruction ConvertAttributeToNode(XamlType containingType, AttributeAssignment rawAttributeAssignment)
        {
            MutableXamlMember member;

            if (rawAttributeAssignment.Locator.IsDotted)
            {
                var ownerName = rawAttributeAssignment.Locator.Owner.PropertyName;
                var ownerPrefix = rawAttributeAssignment.Locator.Owner.Prefix;

                var owner = wiringContext.TypeContext.GetByPrefix(ownerPrefix, ownerName);

                member = owner.GetAttachableMember(rawAttributeAssignment.Locator.PropertyName);
            }
            else
            {
                member = containingType.GetMember(rawAttributeAssignment.Locator.PropertyName);
            }

            var namespaceDeclaration = new NamespaceDeclaration(rawAttributeAssignment.Locator.Namespace, rawAttributeAssignment.Locator.Prefix);
            return instructionBuilder.Attribute(member, rawAttributeAssignment.Value, namespaceDeclaration.Prefix);
        }
        internal static XamlMember LookupNameScopeProperty(XamlType xamlType)
        {
            if (xamlType.UnderlyingType == null)
            {
                return(null);
            }
            NameScopePropertyAttribute customAttribute = GetCustomAttribute(typeof(NameScopePropertyAttribute), xamlType.UnderlyingType) as NameScopePropertyAttribute;

            if (customAttribute == null)
            {
                return(null);
            }
            Type   type = customAttribute.Type;
            string name = customAttribute.Name;

            if (type != null)
            {
                return(xamlType.SchemaContext.GetXamlType(type).GetAttachableMember(name));
            }
            return(xamlType.GetMember(name));
        }
示例#27
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            IXamlSchemaContextProvider schemaContextProvider =
                (IXamlSchemaContextProvider)context.GetService(typeof(IXamlSchemaContextProvider));
            IAmbientProvider ambientValueProvider =
                (IAmbientProvider)context.GetService(typeof(IAmbientProvider));
            IXamlNamespaceResolver namespaceResolver =
                (IXamlNamespaceResolver)context.GetService(typeof(IXamlNamespaceResolver));

            XamlTypeName typeName        = XamlTypeName.Parse("TemplateClass2", namespaceResolver);
            XamlType     xamlType        = schemaContextProvider.SchemaContext.GetXamlType(typeName);
            XamlMember   ambientProperty = xamlType.GetMember("Suffix");
            IEnumerable <AmbientPropertyValue> propVals = ambientValueProvider.GetAllAmbientValues(null, ambientProperty);
            string s = (string)value;

            foreach (AmbientPropertyValue val in propVals)
            {
                s += (string)val.Value;
            }
            return(s);
        }
        // TODO: Refactor this shit.
        private ProtoInstruction ConvertAttributeToNode(XamlType containingType, AttributeAssignment rawAttributeAssignment)
        {
            MutableMember member;

            if (rawAttributeAssignment.Locator.IsDotted)
            {
                member = GetMemberForDottedLocator(rawAttributeAssignment.Locator);
            }
            else
            {
                if (IsNameDirective(rawAttributeAssignment.Locator, containingType))
                {
                    return(instructionBuilder.Directive(CoreTypes.Name, rawAttributeAssignment.Value));
                }

                member = containingType.GetMember(rawAttributeAssignment.Locator.PropertyName);
            }

            var namespaceDeclaration = new NamespaceDeclaration(rawAttributeAssignment.Locator.Namespace, rawAttributeAssignment.Locator.Prefix);

            return(instructionBuilder.Attribute(member, rawAttributeAssignment.Value, namespaceDeclaration.Prefix));
        }
示例#29
0
        private MemberBase GetActualMemberFromMemberSpecifiedInInstruction(MemberBase specifiedMember)
        {
            if (IsLevelOneAndThereIsRootInstance && !specifiedMember.IsDirective && rootInstanceXamlType != null)
            {
                var attachable = specifiedMember as AttachableMember;

                MemberBase actualMember;

                if (attachable != null)
                {
                    actualMember = attachable.DeclaringType.GetAttachableMember(specifiedMember.Name);
                }
                else
                {
                    actualMember = rootInstanceXamlType.GetMember(specifiedMember.Name);
                }

                return(actualMember);
            }

            return(specifiedMember);
        }
        private ProtoXamlInstruction ConvertAttributeToNode(XamlType containingType, AttributeAssignment rawAttributeAssignment)
        {
            MutableXamlMember member;

            if (rawAttributeAssignment.Locator.IsDotted)
            {
                var ownerName   = rawAttributeAssignment.Locator.Owner.PropertyName;
                var ownerPrefix = rawAttributeAssignment.Locator.Owner.Prefix;

                var owner = wiringContext.TypeContext.GetByPrefix(ownerPrefix, ownerName);

                member = owner.GetAttachableMember(rawAttributeAssignment.Locator.PropertyName);
            }
            else
            {
                member = containingType.GetMember(rawAttributeAssignment.Locator.PropertyName);
            }

            var namespaceDeclaration = new NamespaceDeclaration(rawAttributeAssignment.Locator.Namespace, rawAttributeAssignment.Locator.Prefix);

            return(instructionBuilder.Attribute(member, rawAttributeAssignment.Value, namespaceDeclaration.Prefix));
        }
        public void WriteValueOfEventAsDelegate()
        {
            XamlSchemaContext xsc = new XamlSchemaContext();
            XamlObjectWriter  ow  = new XamlObjectWriter(xsc);

            XamlType eventElementXT = xsc.GetXamlType(typeof(EventElement));

            ow.WriteStartObject(eventElementXT);
            ow.WriteStartMember(eventElementXT.GetMember("Tap"));
            EventElement.TapDelegate tapDelegate = new EventElement.TapDelegate(methodToCall);
            ow.WriteValue(tapDelegate);
            ow.WriteEndMember();
            ow.WriteEndObject();

            EventElement eventElement = ((EventElement)ow.Result);

            tapEventFired = false;
            eventElement.RaiseTapEvent();
            if (!tapEventFired)
            {
                throw new Exception("Tap event did not fire");
            }
        }
        private IEnumerable<Instruction> ParseProperties(IEnumerable<PropertyOption> options, XamlType xamlType)
        {
            foreach (var option in options)
            {
                var member = xamlType.GetMember(option.Property);
                yield return Inject.StartOfMember(member);


                var stringNode = option.Value as StringNode;
                if (stringNode != null)
                {
                    yield return Inject.Value(stringNode.Value);
                }

                var markupExtensionNode = option.Value as MarkupExtensionNode;
                if (markupExtensionNode != null)
                {
                    foreach (var xamlInstruction in ParseMarkupExtensionNode(markupExtensionNode)) { yield return xamlInstruction; }
                }

                yield return Inject.EndOfMember();
            }
        }
示例#33
0
        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();
        }
        public void WriteEventWithAMarkupExtensionReturingADelegate()
        {
            XamlSchemaContext xsc = new XamlSchemaContext();
            XamlObjectWriter  ow  = new XamlObjectWriter(xsc);

            XamlType eventElementXT       = xsc.GetXamlType(typeof(EventElement));
            XamlType delegateCreatingMeXT = xsc.GetXamlType(typeof(DelegateCreatingME));

            ow.WriteStartObject(eventElementXT);
            ow.WriteStartMember(eventElementXT.GetMember("Tap"));
            ow.WriteStartObject(delegateCreatingMeXT);
            ow.WriteEndObject();
            ow.WriteEndMember();
            ow.WriteEndObject();

            EventElement eventElement = ((EventElement)ow.Result);
            int          fireCount    = eventElement.TapEventCount;

            eventElement.RaiseTapEvent();
            if (eventElement.TapEventCount != fireCount + 1)
            {
                throw new Exception("Tap event did not fire");
            }
        }
示例#35
0
        private void TestSetup()
        {
            _mainReader        = null;
            _mainWriter        = null;
            _removeProperty    = null;
            _removeType        = null;
            _xamlSchemaContext = null;

            _xamlSchemaContext = new XamlSchemaContext();
            string   elementXns = "clr-namespace:Test.Elements;assembly=XamlTestClasses";
            XamlType element3   = _xamlSchemaContext.GetXamlType(elementXns, "Element10");

            // Remove the Property "Element2"
            _removeProperty = element3.GetMember("Element2");

            // Remove all instances of "HoldsOneElement"
            _removeType = _xamlSchemaContext.GetXamlType(elementXns, "HoldsOneElement");

            StringReader stringReader = new StringReader(SubtreeXAML);
            XmlReader    xmlReader    = XmlReader.Create(stringReader);

            _mainReader = new XamlXmlReader(xmlReader, _xamlSchemaContext);
            _mainWriter = new XamlObjectWriter(_xamlSchemaContext);
        }
示例#36
0
		// It gives Type member, not PositionalParameters... and no Items member here.
		protected void Read_ArrayExtension2 (XamlReader r)
		{
			Assert.IsTrue (r.Read (), "#11");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#12");
			Assert.IsNotNull (r.Namespace, "#13");
			Assert.AreEqual ("x", r.Namespace.Prefix, "#13-2");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, r.Namespace.Namespace, "#13-3");
//			Assert.IsNull (r.Instance, "#14");

			Assert.IsTrue (r.Read (), "#21");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#22");
			var xt = new XamlType (typeof (ArrayExtension), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "#23-2");
//			Assert.IsTrue (r.Instance is ArrayExtension, "#26");

			if (r is XamlXmlReader)
				ReadBase (r);

			Assert.IsTrue (r.Read (), "#31");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#32");
			Assert.AreEqual (xt.GetMember ("Type"), r.Member, "#33-2");

			Assert.IsTrue (r.Read (), "#41");
			Assert.AreEqual (XamlNodeType.Value, r.NodeType, "#42");
			Assert.AreEqual ("x:Int32", r.Value, "#43-2");

			Assert.IsTrue (r.Read (), "#51");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#52");

			Assert.IsTrue (r.Read (), "#61");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#62");

			Assert.IsFalse (r.Read (), "#71");
			Assert.IsTrue (r.IsEof, "#72");
		}
示例#37
0
		protected void WriteNullMemberAsObject (XamlReader r, Action validateNullInstance)
		{
			Assert.AreEqual (XamlNodeType.None, r.NodeType, "#1");
			Assert.IsTrue (r.Read (), "#6");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#7");
			Assert.AreEqual (String.Empty, r.Namespace.Prefix, "#7-2");
			Assert.AreEqual ("clr-namespace:MonoTests.System.Xaml;assembly=" + GetType ().Assembly.GetName ().Name, r.Namespace.Namespace, "#7-3");

			Assert.IsTrue (r.Read (), "#11");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#12");
			Assert.AreEqual ("x", r.Namespace.Prefix, "#12-2");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, r.Namespace.Namespace, "#12-3");

			Assert.IsTrue (r.Read (), "#16");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#17");
			var xt = new XamlType (typeof (TestClass4), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "#17-2");
//			Assert.IsTrue (r.Instance is TestClass4, "#17-3");
			Assert.AreEqual (2, xt.GetAllMembers ().Count, "#17-4");

			if (r is XamlXmlReader)
				ReadBase (r);

			Assert.IsTrue (r.Read (), "#21");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#22");
			Assert.AreEqual (xt.GetMember ("Bar"), r.Member, "#22-2");

			Assert.IsTrue (r.Read (), "#26");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#27");
			Assert.AreEqual (XamlLanguage.Null, r.Type, "#27-2");
			if (validateNullInstance != null)
				validateNullInstance ();

			Assert.IsTrue (r.Read (), "#31");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#32");

			Assert.IsTrue (r.Read (), "#36");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#37");

			Assert.IsTrue (r.Read (), "#41");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#42");
			Assert.AreEqual (xt.GetMember ("Foo"), r.Member, "#42-2");

			Assert.IsTrue (r.Read (), "#43");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#43-2");
			Assert.AreEqual (XamlLanguage.Null, r.Type, "#43-3");
			if (validateNullInstance != null)
				validateNullInstance ();

			Assert.IsTrue (r.Read (), "#44");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#44-2");

			Assert.IsTrue (r.Read (), "#46");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#47");

			Assert.IsTrue (r.Read (), "#51");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#52");

			Assert.IsFalse (r.Read (), "#56");
			Assert.IsTrue (r.IsEof, "#57");
		}
示例#38
0
		protected void Read_ArrayList (XamlReader r)
		{
			Assert.IsTrue (r.Read (), "ns#1-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#1-2");

			var defns = "clr-namespace:System.Collections;assembly=mscorlib";

			Assert.AreEqual (String.Empty, r.Namespace.Prefix, "ns#1-3");
			Assert.AreEqual (defns, r.Namespace.Namespace, "ns#1-4");

			Assert.IsTrue (r.Read (), "#11");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#12");
			Assert.IsNotNull (r.Namespace, "#13");
			Assert.AreEqual ("x", r.Namespace.Prefix, "#13-2");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, r.Namespace.Namespace, "#13-3");

			Assert.IsTrue (r.Read (), "#21");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#22");
			var xt = new XamlType (typeof (ArrayList), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "#23");
//			Assert.AreEqual (obj, r.Instance, "#26");
			Assert.IsTrue (xt.IsCollection, "#27");

			if (r is XamlXmlReader)
				ReadBase (r);

			// This assumption on member ordering ("Type" then "Items") is somewhat wrong, and we might have to adjust it in the future.

			Assert.IsTrue (r.Read (), "#31");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#32");
			Assert.AreEqual (xt.GetMember ("Capacity"), r.Member, "#33");

			Assert.IsTrue (r.Read (), "#41");
			Assert.AreEqual (XamlNodeType.Value, r.NodeType, "#42");
			// The value is implementation details, not testable.
			//Assert.AreEqual ("3", r.Value, "#43");

			Assert.IsTrue (r.Read (), "#51");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#52");

			Assert.IsTrue (r.Read (), "#72");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#72-2");
			Assert.AreEqual (XamlLanguage.Items, r.Member, "#72-3");

			string [] values = {"5", "-3", "0"};
			for (int i = 0; i < 3; i++) {
				Assert.IsTrue (r.Read (), i + "#73");
				Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, i + "#73-2");
				Assert.IsTrue (r.Read (), i + "#74");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, i + "#74-2");
				Assert.AreEqual (XamlLanguage.Initialization, r.Member, i + "#74-3");
				Assert.IsTrue (r.Read (), i + "#75");
				Assert.IsNotNull (r.Value, i + "#75-2");
				Assert.AreEqual (values [i], r.Value, i + "#73-3");
				Assert.IsTrue (r.Read (), i + "#74");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, i + "#74-2");
				Assert.IsTrue (r.Read (), i + "#75");
				Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, i + "#75-2");
			}

			Assert.IsTrue (r.Read (), "#81");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#82"); // XamlLanguage.Items

			Assert.IsTrue (r.Read (), "#87");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#88");

			Assert.IsFalse (r.Read (), "#89");
		}
示例#39
0
		protected void Read_ArrayOrArrayExtensionOrMyArrayExtension (XamlReader r, Action validateInstance, Type extType)
		{
			if (extType == typeof (MyArrayExtension)) {
				Assert.IsTrue (r.Read (), "#1");
				Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#2");
				Assert.IsNotNull (r.Namespace, "#3");
				Assert.AreEqual (String.Empty, r.Namespace.Prefix, "#3-2");
			}
			Assert.IsTrue (r.Read (), "#11");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#12");
			Assert.IsNotNull (r.Namespace, "#13");
			Assert.AreEqual ("x", r.Namespace.Prefix, "#13-2");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, r.Namespace.Namespace, "#13-3");

			Assert.IsTrue (r.Read (), "#21");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#22");
			var xt = new XamlType (extType, r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "#23");
			if (validateInstance != null)
				validateInstance ();

			if (r is XamlXmlReader)
				ReadBase (r);

			// This assumption on member ordering ("Type" then "Items") is somewhat wrong, and we might have to adjust it in the future.

			Assert.IsTrue (r.Read (), "#31");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#32");
			Assert.AreEqual (xt.GetMember ("Type"), r.Member, "#33");

			Assert.IsTrue (r.Read (), "#41");
			Assert.AreEqual (XamlNodeType.Value, r.NodeType, "#42");
			Assert.AreEqual ("x:Int32", r.Value, "#43");

			Assert.IsTrue (r.Read (), "#51");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#52");

			Assert.IsTrue (r.Read (), "#61");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#62");
			Assert.AreEqual (xt.GetMember ("Items"), r.Member, "#63");

			Assert.IsTrue (r.Read (), "#71");
			Assert.AreEqual (XamlNodeType.GetObject, r.NodeType, "#71-2");
			Assert.IsNull (r.Type, "#71-3");
			Assert.IsNull (r.Member, "#71-4");
			Assert.IsNull (r.Value, "#71-5");

			Assert.IsTrue (r.Read (), "#72");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#72-2");
			Assert.AreEqual (XamlLanguage.Items, r.Member, "#72-3");

			string [] values = {"5", "-3", "0"};
			for (int i = 0; i < 3; i++) {
				Assert.IsTrue (r.Read (), i + "#73");
				Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, i + "#73-2");
				Assert.IsTrue (r.Read (), i + "#74");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, i + "#74-2");
				Assert.AreEqual (XamlLanguage.Initialization, r.Member, i + "#74-3");
				Assert.IsTrue (r.Read (), i + "#75");
				Assert.IsNotNull (r.Value, i + "#75-2");
				Assert.AreEqual (values [i], r.Value, i + "#73-3");
				Assert.IsTrue (r.Read (), i + "#74");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, i + "#74-2");
				Assert.IsTrue (r.Read (), i + "#75");
				Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, i + "#75-2");
			}

			Assert.IsTrue (r.Read (), "#81");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#82"); // XamlLanguage.Items

			Assert.IsTrue (r.Read (), "#83");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#84"); // GetObject

			Assert.IsTrue (r.Read (), "#85");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#86"); // ArrayExtension.Items

			Assert.IsTrue (r.Read (), "#87");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#88"); // ArrayExtension

			Assert.IsFalse (r.Read (), "#89");
		}
示例#40
0
		protected void Read_ListType (XamlReader r, bool isObjectReader)
		{
			Assert.IsTrue (r.Read (), "ns#1-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#1-2");

			var defns = "clr-namespace:System.Collections.Generic;assembly=mscorlib";
			var defns2 = "clr-namespace:System;assembly=mscorlib";
			var defns3 = "clr-namespace:System.Xaml;assembly=System.Xaml";

			Assert.AreEqual (String.Empty, r.Namespace.Prefix, "ns#1-3");
			Assert.AreEqual (defns, r.Namespace.Namespace, "ns#1-4");

			Assert.IsTrue (r.Read (), "ns#2-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#2-2");
			Assert.IsNotNull (r.Namespace, "ns#2-3");
			Assert.AreEqual ("s", r.Namespace.Prefix, "ns#2-3-2");
			Assert.AreEqual (defns2, r.Namespace.Namespace, "ns#2-3-3");

			Assert.IsTrue (r.Read (), "ns#3-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#3-2");
			Assert.IsNotNull (r.Namespace, "ns#3-3");
			Assert.AreEqual ("sx", r.Namespace.Prefix, "ns#3-3-2");
			Assert.AreEqual (defns3, r.Namespace.Namespace, "ns#3-3-3");

			Assert.IsTrue (r.Read (), "#11");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#12");
			Assert.IsNotNull (r.Namespace, "#13");
			Assert.AreEqual ("x", r.Namespace.Prefix, "#13-2");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, r.Namespace.Namespace, "#13-3");

			Assert.IsTrue (r.Read (), "#21");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#22");
			var xt = new XamlType (typeof (List<Type>), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "#23");
			Assert.IsTrue (xt.IsCollection, "#27");

			if (r is XamlXmlReader)
				ReadBase (r);

			Assert.IsTrue (r.Read (), "#31");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#32");
			Assert.AreEqual (xt.GetMember ("Capacity"), r.Member, "#33");

			Assert.IsTrue (r.Read (), "#41");
			Assert.AreEqual (XamlNodeType.Value, r.NodeType, "#42");
			Assert.AreEqual ("2", r.Value, "#43");

			Assert.IsTrue (r.Read (), "#51");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#52");

			Assert.IsTrue (r.Read (), "#72");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#72-2");
			Assert.AreEqual (XamlLanguage.Items, r.Member, "#72-3");

			string [] values = {"x:Int32", "Dictionary(s:Type, sx:XamlType)"};
			for (int i = 0; i < 2; i++) {
				Assert.IsTrue (r.Read (), i + "#73");
				Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, i + "#73-2");
				Assert.IsTrue (r.Read (), i + "#74");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, i + "#74-2");
				// Here XamlObjectReader and XamlXmlReader significantly differs. (Lucky we can make this test conditional so simply)
				if (isObjectReader)
					Assert.AreEqual (XamlLanguage.PositionalParameters, r.Member, i + "#74-3");
				else
					Assert.AreEqual (XamlLanguage.Type.GetMember ("Type"), r.Member, i + "#74-3");
				Assert.IsTrue (r.Read (), i + "#75");
				Assert.IsNotNull (r.Value, i + "#75-2");
				Assert.AreEqual (values [i], r.Value, i + "#73-3");
				Assert.IsTrue (r.Read (), i + "#74");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, i + "#74-2");
				Assert.IsTrue (r.Read (), i + "#75");
				Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, i + "#75-2");
			}

			Assert.IsTrue (r.Read (), "#81");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#82"); // XamlLanguage.Items
			
			Assert.IsTrue (r.Read (), "#87");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#88");

			Assert.IsFalse (r.Read (), "#89");
		}
示例#41
0
		protected void Read_ListArray (XamlReader r)
		{
			Assert.IsTrue (r.Read (), "ns#1-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#1-2");

			var defns = "clr-namespace:System.Collections.Generic;assembly=mscorlib";
			var defns2 = "clr-namespace:System;assembly=mscorlib";
			var defns3 = "clr-namespace:System.Xaml;assembly=System.Xaml";

			Assert.AreEqual (String.Empty, r.Namespace.Prefix, "ns#1-3");
			Assert.AreEqual (defns, r.Namespace.Namespace, "ns#1-4");

			Assert.IsTrue (r.Read (), "ns#2-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#2-2");
			Assert.IsNotNull (r.Namespace, "ns#2-3");
			Assert.AreEqual ("s", r.Namespace.Prefix, "ns#2-3-2");
			Assert.AreEqual (defns2, r.Namespace.Namespace, "ns#2-3-3");

			Assert.IsTrue (r.Read (), "#11");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#12");
			Assert.IsNotNull (r.Namespace, "#13");
			Assert.AreEqual ("x", r.Namespace.Prefix, "#13-2");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, r.Namespace.Namespace, "#13-3");

			Assert.IsTrue (r.Read (), "#21");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#22");
			var xt = new XamlType (typeof (List<Array>), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "#23");
			Assert.IsTrue (xt.IsCollection, "#27");

			if (r is XamlXmlReader)
				ReadBase (r);

			Assert.IsTrue (r.Read (), "#31");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#32");
			Assert.AreEqual (xt.GetMember ("Capacity"), r.Member, "#33");

			Assert.IsTrue (r.Read (), "#41");
			Assert.AreEqual (XamlNodeType.Value, r.NodeType, "#42");
			Assert.AreEqual ("2", r.Value, "#43");

			Assert.IsTrue (r.Read (), "#51");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#52");

			Assert.IsTrue (r.Read (), "#72");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#72-2");
			Assert.AreEqual (XamlLanguage.Items, r.Member, "#72-3");

			string [] values = {"x:Int32", "x:String"};
			for (int i = 0; i < 2; i++) {
				Assert.IsTrue (r.Read (), i + "#73");
				Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, i + "#73-2");
				Assert.AreEqual (XamlLanguage.Array, r.Type, i + "#73-3");
				Assert.IsTrue (r.Read (), i + "#74");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, i + "#74-2");
				Assert.AreEqual (XamlLanguage.Array.GetMember ("Type"), r.Member, i + "#74-3");
				Assert.IsTrue (r.Read (), i + "#75");
				Assert.IsNotNull (r.Value, i + "#75-2");
				Assert.AreEqual (values [i], r.Value, i + "#73-3");
				Assert.IsTrue (r.Read (), i + "#74");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, i + "#74-2");

				Assert.IsTrue (r.Read (), i + "#75");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, i + "#75-2");
				Assert.AreEqual (XamlLanguage.Array.GetMember ("Items"), r.Member, i + "#75-3");
				Assert.IsTrue (r.Read (), i + "#75-4");
				Assert.AreEqual (XamlNodeType.GetObject, r.NodeType, i + "#75-5");
				Assert.IsTrue (r.Read (), i + "#75-7");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, i + "#75-8");
				Assert.AreEqual (XamlLanguage.Items, r.Member, i + "#75-9");

				for (int j = 0; j < 3; j++) {
					Assert.IsTrue (r.Read (), i + "#76-" + j);
					Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, i + "#76-2"+ "-" + j);
					Assert.IsTrue (r.Read (), i + "#76-3"+ "-" + j);
					Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, i + "#76-4"+ "-" + j);
					Assert.IsTrue (r.Read (), i + "#76-5"+ "-" + j);
					Assert.AreEqual (XamlNodeType.Value, r.NodeType, i + "#76-6"+ "-" + j);
					Assert.IsTrue (r.Read (), i + "#76-7"+ "-" + j);
					Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, i + "#76-8"+ "-" + j);
					Assert.IsTrue (r.Read (), i + "#76-9"+ "-" + j);
					Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, i + "#76-10"+ "-" + j);
				}

				Assert.IsTrue (r.Read (), i + "#77");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, i + "#77-2");

				Assert.IsTrue (r.Read (), i + "#78");
				Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, i + "#78-2");

				Assert.IsTrue (r.Read (), i + "#79");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, i + "#79-2");

				Assert.IsTrue (r.Read (), i + "#80");
				Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, i + "#80-2");
			}

			Assert.IsTrue (r.Read (), "#81");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#82"); // XamlLanguage.Items
			
			Assert.IsTrue (r.Read (), "#87");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#88");

			Assert.IsFalse (r.Read (), "#89");
		}
		// member element, implicit member, children via content property, or value
		IEnumerable<XamlXmlNodeInfo> ReadMemberElement (XamlType parentType, XamlType xt)
		{
			XamlMember xm = null;
			var name = r.LocalName;
			int idx = name.IndexOf ('.');
			// FIXME: it skips strict type name check, as it could result in MarkupExtension mismatch (could be still checked, though)
			if (idx >= 0/* && name.Substring (0, idx) == xt.Name*/) {
				name = name.Substring (idx + 1);
				xm = xt.GetMember (name);
			} else {
				xm = (XamlMember) FindStandardDirective (name, AllowedMemberLocations.MemberElement) ??
					// not a standard directive? then try attachable
					xt.GetAttachableMember (name) ??
					// still not? then try ordinal member
					xt.GetMember (name);
				if (xm == null) {
					// still not? could it be omitted as content property or items ?
					if ((xm = GetExtraMember (xt)) != null) {
						// Note that this does not involve r.Read()
						foreach (var ni in ReadMember (xt, xm))
							yield return ni;
						yield break;
					}
				}
			}
			if (xm == null) {
				// Current element could be for another member in the parent type (if exists)
				if (parentType != null && parentType.GetMember (name) != null) {
					// stop the iteration and signal the caller to not read current element as an object. (It resolves conflicts between "start object for current collection's item" and "start member for the next member in the parent object".
					yield return Node (XamlNodeType.None, null);
					yield break;
				}

				// ok, then create unknown member.
				xm = new XamlMember (name, xt, false); // FIXME: not sure if isAttachable is always false.
			}

			if (!r.IsEmptyElement) {
				r.Read ();
				foreach (var ni in ReadMember (xt, xm))
					yield return ni;
				r.MoveToContent ();
				r.ReadEndElement ();
			}
			else
				r.Read ();
		}
示例#43
0
		protected void Read_CollectionContentPropertyX (XamlReader r, bool contentPropertyIsUsed)
		{
			Assert.IsTrue (r.Read (), "ns#1-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#1-2");
			Assert.IsNotNull (r.Namespace, "ns#1-3");
			Assert.AreEqual ("", r.Namespace.Prefix, "ns#1-4");
			var assns = "clr-namespace:MonoTests.System.Xaml;assembly=" + GetType ().Assembly.GetName ().Name;
			Assert.AreEqual (assns, r.Namespace.Namespace, "ns#1-5");

			Assert.IsTrue (r.Read (), "ns#2-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#2-2");
			Assert.IsNotNull (r.Namespace, "ns#2-3");
			Assert.AreEqual ("sc", r.Namespace.Prefix, "ns#2-4");
			assns = "clr-namespace:System.Collections;assembly=" + typeof (IList<>).Assembly.GetName ().Name;
			Assert.AreEqual (assns, r.Namespace.Namespace, "ns#2-5");

			Assert.IsTrue (r.Read (), "ns#x-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#x-2");
			Assert.IsNotNull (r.Namespace, "ns#x-3");
			Assert.AreEqual ("scg", r.Namespace.Prefix, "ns#x-4");
			assns = "clr-namespace:System.Collections.Generic;assembly=" + typeof (IList<>).Assembly.GetName ().Name;
			Assert.AreEqual (assns, r.Namespace.Namespace, "ns#x-5");

			Assert.IsTrue (r.Read (), "ns#3-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#3-2");
			Assert.IsNotNull (r.Namespace, "ns#3-3");
			Assert.AreEqual ("x", r.Namespace.Prefix, "ns#3-4");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, r.Namespace.Namespace, "ns#3-5");

			// t:CollectionContentProperty
			Assert.IsTrue (r.Read (), "so#1-1");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#1-2");
			var xt = new XamlType (typeof (CollectionContentPropertyX), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "so#1-3");

			if (r is XamlXmlReader)
				ReadBase (r);

			// m:ListOfItems
			Assert.IsTrue (r.Read (), "sm1#1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm1#2");
			Assert.AreEqual (xt.GetMember ("ListOfItems"), r.Member, "sm1#3");

			// t:List<IEnumerable>
			xt = new XamlType (typeof (List<IEnumerable>), r.SchemaContext);
			Assert.IsTrue (r.Read (), "so#2-1");

			if (false/*contentPropertyIsUsed*/)
				Assert.AreEqual (XamlNodeType.GetObject, r.NodeType, "so#2-2.1");
			else {
				Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#2-2.2");
				Assert.AreEqual (xt, r.Type, "so#2-3");

				// m:Capacity
				Assert.IsTrue (r.Read (), "sm#2-1");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm#2-2");
				Assert.AreEqual (xt.GetMember ("Capacity"), r.Member, "sm#2-3");

				// r.Skip (); // LAMESPEC: .NET then skips to *post* Items node (i.e. at the first TestClass item)

				Assert.IsTrue (r.Read (), "v#1-1");

				// /m:Capacity
				Assert.IsTrue (r.Read (), "em#2-1");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#2-2");
			}

			Assert.IsTrue (r.Read (), "sm#3-1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm#3-2");
			Assert.AreEqual (XamlLanguage.Items, r.Member, "sm#3-3");

			if (!contentPropertyIsUsed) {

				Assert.IsTrue (r.Read (), "so#x-1");
				Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#x-2.2");
				xt = new XamlType (typeof (List<object>), r.SchemaContext);
				Assert.AreEqual (xt, r.Type, "so#x-3");

				// m:Capacity
				Assert.IsTrue (r.Read (), "sm#xx-1");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm#xx-2");
				Assert.AreEqual (xt.GetMember ("Capacity"), r.Member, "sm#xx-3");

				Assert.IsTrue (r.Read (), "v#x-1");

				// /m:Capacity
				Assert.IsTrue (r.Read (), "em#xx-1");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#xx-2");

				Assert.IsTrue (r.Read (), "sm#x-1");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm#x-2");
				Assert.AreEqual (XamlLanguage.Items, r.Member, "sm#x-3");
			}

			for (int i = 0; i < 4; i++) {
				// t:SimpleClass
				Assert.IsTrue (r.Read (), "so#3-1." + i);
				Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#3-2." + i);
				xt = new XamlType (typeof (SimpleClass), r.SchemaContext);
				Assert.AreEqual (xt, r.Type, "so#3-3." + i);

				// /t:SimpleClass
				Assert.IsTrue (r.Read (), "eo#3-1");
				Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#3-2");
			}

			if (!contentPropertyIsUsed) {
				// /m:Items
				Assert.IsTrue (r.Read (), "em#x-1");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#x-2");

				// /t:List<IEnumerable>
				Assert.IsTrue (r.Read (), "eo#x-1");
				Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#x-2");
			}

			// /m:Items
			Assert.IsTrue (r.Read (), "em#3-1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#3-2");

			// /t:CollectionContentProperty
			Assert.IsTrue (r.Read (), "eo#2-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#2-2");

			// /m:ListOfItems
			Assert.IsTrue (r.Read (), "em#1-1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#1-2");

			// /t:CollectionContentProperty
			Assert.IsTrue (r.Read (), "eo#1-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#1-2");

			Assert.IsFalse (r.Read (), "end");
		}
示例#44
0
		public void NamedItem ()
		{
			var xt = new XamlType (typeof (NamedItem), sctx);
			var e = xt.GetAllMembers ().GetEnumerator ();
			Assert.IsTrue (e.MoveNext (), "#1");
			Assert.AreEqual (xt.GetMember ("ItemName"), e.Current, "#2");
			Assert.IsTrue (e.MoveNext (), "#3");
			Assert.AreEqual (xt.GetMember ("References"), e.Current, "#4");
			Assert.IsFalse (e.MoveNext (), "#5");
		}
		// Note that it could return invalid (None) node to tell the caller that it is not really an object element.
		IEnumerable<XamlXmlNodeInfo> ReadObjectElement (XamlType parentType, XamlMember currentMember)
		{
			if (r.NodeType != XmlNodeType.Element) {
				//throw new XamlParseException (String.Format ("Element is expected, but got {0}", r.NodeType));
				yield return Node (XamlNodeType.Value, r.Value);
				yield break;
			}

			if (r.MoveToFirstAttribute ()) {
				do {
					if (r.NamespaceURI == XamlLanguage.Xmlns2000Namespace)
						yield return Node (XamlNodeType.NamespaceDeclaration, new NamespaceDeclaration (r.Value, r.Prefix == "xmlns" ? r.LocalName : String.Empty));
				} while (r.MoveToNextAttribute ());
				r.MoveToElement ();
			}

			var sti = GetStartTagInfo ();

			var xt = sctx.GetXamlType (sti.TypeName);
			if (xt == null) {
				// Current element could be for another member in the parent type (if exists)
				if (parentType != null && (r.LocalName.IndexOf ('.') > 0 || parentType.GetMember (r.LocalName) != null)) {
					// stop the iteration and signal the caller to not read current element as an object. (It resolves conflicts between "start object for current collection's item" and "start member for the next member in the parent object".
					yield return Node (XamlNodeType.None, null);
					yield break;
				}

				// creates name-only XamlType. Also, it does not seem that it does not store this XamlType to XamlSchemaContext (Try GetXamlType(xtn) after reading such xaml node, it will return null).
				xt = new XamlType (sti.Namespace, sti.Name, sti.TypeName.TypeArguments == null ? null : sti.TypeName.TypeArguments.Select<XamlTypeName,XamlType> (xxtn => sctx.GetXamlType (xxtn)).ToArray (), sctx);
			}
			
			bool isGetObject = false;
			if (currentMember != null && !xt.CanAssignTo (currentMember.Type)) {
				if (currentMember.DeclaringType != null && currentMember.DeclaringType.ContentProperty == currentMember)
					isGetObject = true;

				// It could still be GetObject if current_member
				// is not a directive and current type is not
				// a markup extension.
				// (I'm not very sure about the condition;
				// it could be more complex.)
				// seealso: bug #682131
				else if (!(currentMember is XamlDirective) &&
				    !xt.IsMarkupExtension)
					isGetObject = true;
			}

			if (isGetObject) {
				yield return Node (XamlNodeType.GetObject, currentMember.Type);
				foreach (var ni in ReadMembers (parentType, currentMember.Type))
					yield return ni;
				yield return Node (XamlNodeType.EndObject, currentMember.Type);
				yield break;
			}
			// else

			yield return Node (XamlNodeType.StartObject, xt);

			// process attribute members (including MarkupExtensions)
			ProcessAttributesToMember (sctx, sti, xt);

			foreach (var pair in sti.Members) {
				yield return Node (XamlNodeType.StartMember, pair.Key);

				// Try markup extension
				// FIXME: is this rule correct?
				var v = pair.Value;
				if (!String.IsNullOrEmpty (v) && v [0] == '{') {
					var pai = ParsedMarkupExtensionInfo.Parse (v, xaml_namespace_resolver, sctx);
					yield return Node (XamlNodeType.StartObject, pai.Type);
					foreach (var xepair in pai.Arguments) {
						yield return Node (XamlNodeType.StartMember, xepair.Key);
						if (xepair.Value is List<string>)
							foreach (var s in (List<string>) xepair.Value)
								yield return Node (XamlNodeType.Value, s);
						else
							yield return Node (XamlNodeType.Value, xepair.Value);
						yield return Node (XamlNodeType.EndMember, xepair.Key);
					}
					yield return Node (XamlNodeType.EndObject, pai.Type);
				}
				else
					yield return Node (XamlNodeType.Value, pair.Value);

				yield return Node (XamlNodeType.EndMember, pair.Key);
			}

			// process content members
			if (!r.IsEmptyElement) {
				r.Read ();
				foreach (var ni in ReadMembers (parentType, xt))
					yield return ni;
				r.ReadEndElement ();
			}
			else
				r.Read (); // consume empty element.

			yield return Node (XamlNodeType.EndObject, xt);
		}
示例#46
0
		public void CustomArrayExtension ()
		{
			var xt = new XamlType (typeof (MyArrayExtension), sctx);
			var xm = xt.GetMember ("Items");
			Assert.IsNotNull (xt.GetAllMembers ().FirstOrDefault (m => m.Name == "Items"), "#0");
			Assert.IsNotNull (xm, "#1");
			Assert.IsFalse (xm.IsReadOnly, "#2"); // Surprisingly it is False. Looks like XAML ReadOnly is true only if it lacks set accessor. Having private member does not make it ReadOnly.
			Assert.IsTrue (xm.Type.IsCollection, "#3");
			Assert.IsFalse (xm.Type.IsConstructible, "#4");
		}
示例#47
0
		void ReadTestProperty_AmbientPropertyContainer (XamlReader r, int i, bool extensionBased)
		{
			var xt = new XamlType (typeof (SecondTest.TestObject), r.SchemaContext);

			// m:TestProperty
			Assert.IsTrue (r.Read (), "sm#2-1." + i);
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm#2-2." + i);
			Assert.AreEqual (xt.GetMember ("TestProperty"), r.Member, "sm#2-3." + i);

			if (i == 0) {
				// t:TestObject={x:Null}
				Assert.IsTrue (r.Read (), "so#3-1." + i);
				Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#3-2." + i);
				Assert.AreEqual (XamlLanguage.Null, r.Type, "so#3-3." + i);
				Assert.IsTrue (r.Read (), "eo#3-1." + i);
				Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#3-2." + i);
			} else if (extensionBased) {
				ReadReasourceExtension_AmbientPropertyContainer (r, i, extensionBased);
			} else {
				ReadReference_AmbientPropertyContainer (r, i, extensionBased);
			}

			// /m:TestProperty
			Assert.IsTrue (r.Read (), "em#2-1." + i);
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#2-2." + i);
		}
示例#48
0
		protected void Read_NonPrimitive (XamlReader r)
		{
			Assert.AreEqual (XamlNodeType.None, r.NodeType, "#1");
			Assert.IsTrue (r.Read (), "#6");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#7");
			Assert.AreEqual (String.Empty, r.Namespace.Prefix, "#7-2");
			Assert.AreEqual ("clr-namespace:MonoTests.System.Xaml;assembly=" + GetType ().Assembly.GetName ().Name, r.Namespace.Namespace, "#7-3");

			Assert.IsTrue (r.Read (), "#11");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#12");
			Assert.AreEqual ("x", r.Namespace.Prefix, "#12-2");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, r.Namespace.Namespace, "#12-3");

			Assert.IsTrue (r.Read (), "#16");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#17");
			var xt = new XamlType (typeof (TestClass3), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "#17-2");
//			Assert.IsTrue (r.Instance is TestClass3, "#17-3");

			if (r is XamlXmlReader)
				ReadBase (r);

			Assert.IsTrue (r.Read (), "#21");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#22");
			Assert.AreEqual (xt.GetMember ("Nested"), r.Member, "#22-2");

			Assert.IsTrue (r.Read (), "#26");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#27");
			Assert.AreEqual (XamlLanguage.Null, r.Type, "#27-2");
//			Assert.IsNull (r.Instance, "#27-3");

			Assert.IsTrue (r.Read (), "#31");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#32");

			Assert.IsTrue (r.Read (), "#36");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#37");

			Assert.IsTrue (r.Read (), "#41");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#42");

			Assert.IsFalse (r.Read (), "#46");
			Assert.IsTrue (r.IsEof, "#47");
		}
示例#49
0
		public void Dictionary ()
		{
			var t = new XamlType (typeof (int), sctx);
			Assert.IsFalse (t.IsDictionary, "#1.1");
			Assert.IsFalse (t.IsCollection, "#1.1-2");
			Assert.IsNull (t.KeyType, "#1.2");
			t = new XamlType (typeof (Hashtable), sctx);
			Assert.IsTrue (t.IsDictionary, "#2.1");
			Assert.IsFalse (t.IsCollection, "#2.1-2");
			Assert.IsNotNull (t.KeyType, "#2.2");
			Assert.IsNotNull (t.ItemType, "#2.2-2");
			Assert.AreEqual ("Object", t.KeyType.Name, "#2.3");
			Assert.AreEqual ("Object", t.ItemType.Name, "#2.3-2");
			t = new XamlType (typeof (Dictionary<int,string>), sctx);
			Assert.IsTrue (t.IsDictionary, "#3.1");
			Assert.IsFalse (t.IsCollection, "#3.1-2");
			Assert.IsNotNull (t.KeyType, "#3.2");
			Assert.IsNotNull (t.ItemType, "#3.2-2");
			Assert.AreEqual ("Int32", t.KeyType.Name, "#3.3");
			Assert.AreEqual ("String", t.ItemType.Name, "#3.3-2");

			var ml = t.GetAllMembers ();
			Assert.AreEqual (2, ml.Count, "#3.4");
			Assert.IsTrue (ml.Any (mi => mi.Name == "Keys"), "#3.4-2");
			Assert.IsTrue (ml.Any (mi => mi.Name == "Values"), "#3.4-3");
			Assert.IsNotNull (t.GetMember ("Keys"), "#3.4-4");
			Assert.IsNotNull (t.GetMember ("Values"), "#3.4-5");
		}
示例#50
0
		protected void Read_XmlSerializableWrapper (XamlReader r, bool isObjectReader)
		{
			Assert.IsTrue (r.Read (), "ns#1-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#1-2");
			Assert.IsNotNull (r.Namespace, "ns#1-3");
			Assert.AreEqual ("", r.Namespace.Prefix, "ns#1-4");
			var assns = "clr-namespace:MonoTests.System.Xaml;assembly=" + GetType ().Assembly.GetName ().Name;
			Assert.AreEqual (assns, r.Namespace.Namespace, "ns#1-5");

			Assert.IsTrue (r.Read (), "ns#2-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#2-2");
			Assert.IsNotNull (r.Namespace, "ns#2-3");
			Assert.AreEqual ("x", r.Namespace.Prefix, "ns#2-4");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, r.Namespace.Namespace, "ns#2-5");

			// t:XmlSerializableWrapper
			Assert.IsTrue (r.Read (), "so#1-1");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#1-2");
			var xt = new XamlType (typeof (XmlSerializableWrapper), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "so#1-3");

			if (r is XamlXmlReader)
				ReadBase (r);

			// m:Value
			Assert.IsTrue (r.Read (), "sm1#1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm1#2");
			Assert.AreEqual (xt.GetMember ("Value"), r.Member, "sm1#3");

			// x:XData
			Assert.IsTrue (r.Read (), "so#2-1");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#2-2");
			Assert.AreEqual (XamlLanguage.XData, r.Type, "so#2-3");
			if (r is XamlObjectReader)
				Assert.IsNull (((XamlObjectReader) r).Instance, "xdata-instance");

			Assert.IsTrue (r.Read (), "sm2#1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm2#2");
			Assert.AreEqual (XamlLanguage.XData.GetMember ("Text"), r.Member, "sm2#3");

			Assert.IsTrue (r.Read (), "v1#1");
			Assert.AreEqual (XamlNodeType.Value, r.NodeType, "v1#2");
			var val = isObjectReader ? "<root />" : "<root xmlns=\"" + assns + "\" />";
			Assert.AreEqual (val, r.Value, "v1#3");

			Assert.IsTrue (r.Read (), "em2#1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em2#2");

			Assert.IsTrue (r.Read (), "eo#2-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#2-2");

			Assert.IsTrue (r.Read (), "em1#1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em1#2");

			// /t:XmlSerializableWrapper
			Assert.IsTrue (r.Read (), "eo#1-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#1-2");

			Assert.IsFalse (r.Read (), "end");
		}
示例#51
0
		public void ListMembers ()
		{
			var xt = new XamlType (typeof (List<int>), sctx);
			var ml = xt.GetAllMembers ().ToArray ();
			Assert.AreEqual (1, ml.Length, "#1");
			Assert.IsNotNull (xt.GetMember ("Capacity"), "#2");
		}
示例#52
0
		protected void Read_TypeConverterOnListMember (XamlReader r)
		{
			Assert.IsTrue (r.Read (), "ns#1-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#1-2");
			Assert.IsNotNull (r.Namespace, "ns#1-3");
			Assert.AreEqual ("", r.Namespace.Prefix, "ns#1-4");
			Assert.AreEqual ("http://www.domain.com/path", r.Namespace.Namespace, "ns#1-5");

			// t:TypeOtherAssembly
			Assert.IsTrue (r.Read (), "so#1-1");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#1-2");
			var xt = new XamlType (typeof (SecondTest.TypeOtherAssembly), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "so#1-3");

			if (r is XamlXmlReader)
				ReadBase (r);

			// m:Values
			Assert.IsTrue (r.Read (), "sm1#1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm1#2");
			Assert.AreEqual (xt.GetMember ("Values"), r.Member, "sm1#3");

			// x:Value
			Assert.IsTrue (r.Read (), "v#1-1");
			Assert.AreEqual (XamlNodeType.Value, r.NodeType, "v#1-2");
			Assert.AreEqual ("1, 2, 3", r.Value, "v#1-3");

			// /m:Values
			Assert.IsTrue (r.Read (), "em#1-1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#1-2");

			// /t:TypeOtherAssembly
			Assert.IsTrue (r.Read (), "eo#1-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#1-2");

			Assert.IsFalse (r.Read (), "end");
		}
示例#53
0
		public void ContentIncluded ()
		{
			var xt = new XamlType (typeof (ContentIncludedClass), sctx);
			var xm = xt.GetMember ("Content");
			Assert.AreEqual (xm, xt.ContentProperty, "#1");
			Assert.IsTrue (xt.GetAllMembers ().Contains (xm), "#2");
		}
示例#54
0
		protected void Read_DirectListContainer (XamlReader r)
		{
			var assns1 = "clr-namespace:MonoTests.System.Xaml;assembly=" + GetType ().Assembly.GetName ().Name;
			var assns2 = "clr-namespace:System.Collections.Generic;assembly=" + typeof (IList<>).Assembly.GetName ().Name;
			ReadNamespace (r, String.Empty, assns1, "ns#1");
			ReadNamespace (r, "scg", assns2, "ns#2");
			ReadNamespace (r, "x", XamlLanguage.Xaml2006Namespace, "ns#3");

			// t:DirectListContainer
			Assert.IsTrue (r.Read (), "so#1-1");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#1-2");
			var xt = new XamlType (typeof (DirectListContainer), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "so#1-3");

			if (r is XamlXmlReader)
				ReadBase (r);

			// m:Items
			Assert.IsTrue (r.Read (), "sm1#1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm1#2");
			Assert.AreEqual (xt.GetMember ("Items"), r.Member, "sm1#3");

			// GetObject
			Assert.IsTrue (r.Read (), "go#1");
			Assert.AreEqual (XamlNodeType.GetObject, r.NodeType, "go#2");

			// m:Items(GetObject)
			Assert.IsTrue (r.Read (), "sm2#1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm2#2");
			Assert.AreEqual (XamlLanguage.Items, r.Member, "sm2#3");

			xt = r.SchemaContext.GetXamlType (typeof (DirectListContent));
			for (int i = 0; i < 3; i++) {
				// t:DirectListContent
				Assert.IsTrue (r.Read (), "so#x-1." + i);
				Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#x-2." + i);
				Assert.AreEqual (xt, r.Type, "so#x-3." + i);

				// m:Value
				Assert.IsTrue (r.Read (), "sm#x1");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm#x2");
				Assert.AreEqual (xt.GetMember ("Value"), r.Member, "sm#x3");

				// x:Value
				Assert.IsTrue (r.Read (), "v#x-1");
				Assert.AreEqual (XamlNodeType.Value, r.NodeType, "v#x-2");
				Assert.AreEqual ("Hello" + (i + 1), r.Value, "v#x-3");

				// /m:Value
				Assert.IsTrue (r.Read (), "em#x-1");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#x-2");

				// /t:DirectListContent
				Assert.IsTrue (r.Read (), "eo#x-1");
				Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#x-2");
			}

			// /m:Items(GetObject)
			Assert.IsTrue (r.Read (), "em#2-1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#2-2");

			// /GetObject
			Assert.IsTrue (r.Read (), "ego#2-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "ego#2-2");

			// /m:Items
			Assert.IsTrue (r.Read (), "em#1-1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#1-2");

			// /t:DirectListContainer
			Assert.IsTrue (r.Read (), "eo#1-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#1-2");

			Assert.IsFalse (r.Read (), "end");
		}
示例#55
0
		public void ReadOnlyPropertyContainer ()
		{
			var xt = new XamlType (typeof (ReadOnlyPropertyContainer), sctx);
			var xm = xt.GetMember ("Bar");
			Assert.IsNotNull (xm, "#1");
			Assert.IsFalse (xm.IsWritePublic, "#2");
		}
示例#56
0
		protected void Read_DirectDictionaryContainer (XamlReader r)
		{
			var assns1 = "clr-namespace:MonoTests.System.Xaml;assembly=" + GetType ().Assembly.GetName ().Name;
			ReadNamespace (r, String.Empty, assns1, "ns#1");
			ReadNamespace (r, "x", XamlLanguage.Xaml2006Namespace, "ns#2");

			// t:DirectDictionaryContainer
			Assert.IsTrue (r.Read (), "so#1-1");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#1-2");
			var xt = new XamlType (typeof (DirectDictionaryContainer), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "so#1-3");

			if (r is XamlXmlReader)
				ReadBase (r);

			// m:Items
			Assert.IsTrue (r.Read (), "sm1#1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm1#2");
			Assert.AreEqual (xt.GetMember ("Items"), r.Member, "sm1#3");

			// GetObject
			Assert.IsTrue (r.Read (), "go#1");
			Assert.AreEqual (XamlNodeType.GetObject, r.NodeType, "go#2");

			// m:Items(GetObject)
			Assert.IsTrue (r.Read (), "sm2#1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm2#2");
			Assert.AreEqual (XamlLanguage.Items, r.Member, "sm2#3");

			xt = r.SchemaContext.GetXamlType (typeof (int));
			for (int i = 0; i < 3; i++) {
				// t:DirectDictionaryContent
				Assert.IsTrue (r.Read (), "so#x-1." + i);
				Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#x-2." + i);
				Assert.AreEqual (xt, r.Type, "so#x-3." + i);

				// m:Key
				Assert.IsTrue (r.Read (), "sm#y1");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm#y2");
				Assert.AreEqual (XamlLanguage.Key, r.Member, "sm#y3");

				// x:Value
				Assert.IsTrue (r.Read (), "v#y-1");
				Assert.AreEqual (XamlNodeType.Value, r.NodeType, "v#y-2");
				Assert.AreEqual (((EnumValueType) i).ToString ().ToLower (), r.Value, "v#y-3");

				// /m:Key
				Assert.IsTrue (r.Read (), "em#y-1");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#y-2");

				// m:Value
				Assert.IsTrue (r.Read (), "sm#x1");
				Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm#x2");
				Assert.AreEqual (XamlLanguage.Initialization, r.Member, "sm#x3");

				// x:Value
				Assert.IsTrue (r.Read (), "v#x-1");
				Assert.AreEqual (XamlNodeType.Value, r.NodeType, "v#x-2");
				Assert.AreEqual ("" + (i + 2) * 10, r.Value, "v#x-3");

				// /m:Value
				Assert.IsTrue (r.Read (), "em#x-1");
				Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#x-2");

				// /t:DirectDictionaryContent
				Assert.IsTrue (r.Read (), "eo#x-1");
				Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#x-2");
			}

			// /m:Items(GetObject)
			Assert.IsTrue (r.Read (), "em#2-1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#2-2");

			// /GetObject
			Assert.IsTrue (r.Read (), "ego#2-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "ego#2-2");

			// /m:Items
			Assert.IsTrue (r.Read (), "em#1-1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#1-2");

			// /t:DirectDictionaryContainer
			Assert.IsTrue (r.Read (), "eo#1-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#1-2");

			Assert.IsFalse (r.Read (), "end");
		}
		void ProcessAttributesToMember (XamlSchemaContext sctx, StartTagInfo sti, XamlType xt)
		{
			foreach (var p in sti.Attributes) {
				int idx = p.Key.IndexOf (':');
				string prefix = idx > 0 ? p.Key.Substring (0, idx) : String.Empty;
				string aname = idx > 0 ? p.Key.Substring (idx + 1) : p.Key;
				idx = aname.IndexOf ('.');
				if (idx > 0) {
					string apns = prefix.Length > 0 ? r.LookupNamespace (prefix) : r.NamespaceURI;
					var apname = aname.Substring (0, idx);
					var axtn = new XamlTypeName (apns, apname, null);
					var at = sctx.GetXamlType (axtn);
					var am = at.GetAttachableMember (aname.Substring (idx + 1));
					if (am != null)
						sti.Members.Add (new Pair (am, p.Value));
					// ignore unknown attribute
				}
				var xm = xt.GetMember (aname);
				if (xm != null)
					sti.Members.Add (new Pair (xm, p.Value));
				// ignore unknown attribute
			}
		}
示例#58
0
		protected void Read_AttachedProperty (XamlReader r)
		{
			var at = new XamlType (typeof (Attachable), r.SchemaContext);

			Assert.IsTrue (r.Read (), "ns#1-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#1-2");
			Assert.IsNotNull (r.Namespace, "ns#1-3");
			Assert.AreEqual ("", r.Namespace.Prefix, "ns#1-4");
			var assns = "clr-namespace:MonoTests.System.Xaml;assembly=" + GetType ().Assembly.GetName ().Name;
			Assert.AreEqual (assns, r.Namespace.Namespace, "ns#1-5");

			// t:AttachedWrapper
			Assert.IsTrue (r.Read (), "so#1-1");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#1-2");
			var xt = new XamlType (typeof (AttachedWrapper), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "so#1-3");

			if (r is XamlXmlReader)
				ReadBase (r);

			ReadAttachedProperty (r, at.GetAttachableMember ("Foo"), "x", "x");

			// m:Value
			Assert.IsTrue (r.Read (), "sm#2-1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#sm#2-2");
			Assert.AreEqual (xt.GetMember ("Value"), r.Member, "sm#2-3");

			// t:Attached
			Assert.IsTrue (r.Read (), "so#2-1");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#so#2-2");
			Assert.AreEqual (r.SchemaContext.GetXamlType (typeof (Attached)), r.Type, "so#2-3");

			ReadAttachedProperty (r, at.GetAttachableMember ("Foo"), "y", "y");

			Assert.IsTrue (r.Read (), "eo#2-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#eo#2-2");

			// /m:Value
			Assert.IsTrue (r.Read (), "em#2-1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#em#2-2");

			// /t:AttachedWrapper
			Assert.IsTrue (r.Read (), "eo#1-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#1-2");

			Assert.IsFalse (r.Read (), "end");
		}
示例#59
0
		protected void Read_NullableContainer (XamlReader r)
		{
			Assert.IsTrue (r.Read (), "ns#1-1");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "ns#1-2");
			Assert.IsNotNull (r.Namespace, "ns#1-3");
			Assert.AreEqual ("", r.Namespace.Prefix, "ns#1-4");
			var assns = "clr-namespace:MonoTests.System.Xaml;assembly=" + GetType ().Assembly.GetName ().Name;
			Assert.AreEqual (assns, r.Namespace.Namespace, "ns#1-5");

			// t:NullableContainer
			Assert.IsTrue (r.Read (), "so#1-1");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "so#1-2");
			var xt = new XamlType (typeof (NullableContainer), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "so#1-3");

			if (r is XamlXmlReader)
				ReadBase (r);

			// m:TestProp
			Assert.IsTrue (r.Read (), "sm1#1");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "sm1#2");
			Assert.AreEqual (xt.GetMember ("TestProp"), r.Member, "sm1#3");

			// x:Value
			Assert.IsTrue (r.Read (), "v#1-1");
			Assert.AreEqual (XamlNodeType.Value, r.NodeType, "v#1-2");
			Assert.AreEqual ("5", r.Value, "v#1-3");

			// /m:TestProp
			Assert.IsTrue (r.Read (), "em#1-1");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "em#1-2");

			// /t:NullableContainer
			Assert.IsTrue (r.Read (), "eo#1-1");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "eo#1-2");

			Assert.IsFalse (r.Read (), "end");
		}
示例#60
0
		protected void Read_Reference (XamlReader r)
		{
			Assert.IsTrue (r.Read (), "#11");
			Assert.AreEqual (XamlNodeType.NamespaceDeclaration, r.NodeType, "#12");
			Assert.AreEqual ("x", r.Namespace.Prefix, "#13-2");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, r.Namespace.Namespace, "#13-3");

			Assert.IsTrue (r.Read (), "#21");
			Assert.AreEqual (XamlNodeType.StartObject, r.NodeType, "#22");
			var xt = new XamlType (typeof (Reference), r.SchemaContext);
			Assert.AreEqual (xt, r.Type, "#23-2");
//			Assert.IsTrue (r.Instance is Reference, "#26");
			Assert.IsNotNull (XamlLanguage.Type.SchemaContext, "#23-3");
			Assert.IsNotNull (r.SchemaContext, "#23-4");
			Assert.AreNotEqual (XamlLanguage.Type.SchemaContext, r.SchemaContext, "#23-5");
			Assert.AreNotEqual (XamlLanguage.Reference.SchemaContext, xt.SchemaContext, "#23-6");
			Assert.AreEqual (XamlLanguage.Reference, xt, "#23-7");

			if (r is XamlXmlReader)
				ReadBase (r);

			Assert.IsTrue (r.Read (), "#31");
			Assert.AreEqual (XamlNodeType.StartMember, r.NodeType, "#32");
			// unlike TypeExtension there is no PositionalParameters.
			Assert.AreEqual (xt.GetMember ("Name"), r.Member, "#33-2");

			// It is a ContentProperty (besides [ConstructorArgument])
			Assert.IsTrue (r.Read (), "#41");
			Assert.AreEqual (XamlNodeType.Value, r.NodeType, "#42");
			Assert.AreEqual ("FooBar", r.Value, "#43-2");

			Assert.IsTrue (r.Read (), "#51");
			Assert.AreEqual (XamlNodeType.EndMember, r.NodeType, "#52");

			Assert.IsTrue (r.Read (), "#61");
			Assert.AreEqual (XamlNodeType.EndObject, r.NodeType, "#62");

			Assert.IsFalse (r.Read (), "#71");
			Assert.IsTrue (r.IsEof, "#72");
		}