public override void WriteStartMember(XamlMember property)
 {
     this.ThrowIfDisposed();
     if (property == null)
     {
         throw new ArgumentNullException("property");
     }
     this._deferringWriter.WriteStartMember(property);
     if (!this._deferringWriter.Handled)
     {
         string message = null;
         if (this._nextNodeMustBeEndMember)
         {
             message = System.Xaml.SR.Get("ValueMustBeFollowedByEndMember");
         }
         else if (property == XamlLanguage.UnknownContent)
         {
             message = System.Xaml.SR.Get("TypeHasNoContentProperty", new object[] { this._context.CurrentType });
         }
         else if (property.IsUnknown)
         {
             message = System.Xaml.SR.Get("CantSetUnknownProperty", new object[] { property.ToString() });
         }
         else if (this._context.CurrentProperty != null)
         {
             message = System.Xaml.SR.Get("OpenPropertyInCurrentFrame_SM", new object[] { this._context.CurrentType.ToString(), this._context.CurrentProperty.ToString(), property.ToString() });
         }
         else if (this._context.CurrentType == null)
         {
             message = System.Xaml.SR.Get("NoTypeInCurrentFrame_SM", new object[] { property.ToString() });
         }
         if (message != null)
         {
             throw this.WithLineInfo(new XamlObjectWriterException(message));
         }
         this._context.CurrentProperty = property;
         this.Logic_DuplicatePropertyCheck(this._context, property, false);
         if (this._context.CurrentInstance == null)
         {
             if (!this.IsConstructionDirective(this._context.CurrentProperty) && !this.IsDirectiveAllowedOnNullInstance(this._context.CurrentProperty, this._context.CurrentType))
             {
                 this.Logic_CreateAndAssignToParentStart(this._context);
             }
             if (property == XamlLanguage.PositionalParameters)
             {
                 this._context.CurrentCollection = new List<PositionalParameterDescriptor>();
             }
         }
         else
         {
             if (this.IsTextConstructionDirective(property))
             {
                 throw this.WithLineInfo(new XamlObjectWriterException(System.Xaml.SR.Get("LateConstructionDirective", new object[] { property.Name })));
             }
             if (this._context.CurrentIsTypeConvertedObject)
             {
                 if (!property.IsDirective && !property.IsAttachable)
                 {
                     throw this.WithLineInfo(new XamlObjectWriterException(System.Xaml.SR.Get("SettingPropertiesIsNotAllowed", new object[] { property.Name })));
                 }
                 if (property.IsAttachable && (this._context.CurrentInstance is NameFixupToken))
                 {
                     NameFixupToken currentInstance = (NameFixupToken) this._context.CurrentInstance;
                     throw this.WithLineInfo(new XamlObjectWriterException(System.Xaml.SR.Get("AttachedPropOnFwdRefTC", new object[] { property, this._context.CurrentType, string.Join(", ", currentInstance.NeededNames.ToArray()) })));
                 }
             }
         }
         if ((property.IsDirective && (property != XamlLanguage.Items)) && (property != XamlLanguage.PositionalParameters))
         {
             XamlType type = property.Type;
             if (type.IsCollection || type.IsDictionary)
             {
                 this._context.CurrentCollection = this.Runtime.CreateInstance(property.Type, null);
             }
         }
     }
 }
Пример #2
0
		public void EqualsTest ()
		{
			XamlMember m;
			var xt = XamlLanguage.Type;
			m = new XamlMember ("Type", xt, false);
			var type_type = xt.GetMember ("Type");
			Assert.AreNotEqual (m, xt.GetMember ("Type"), "#1"); // whoa!
			Assert.AreNotEqual (type_type, m, "#2"); // whoa!
			Assert.AreEqual (type_type, xt.GetMember ("Type"), "#3");
			Assert.AreEqual (type_type.ToString (), m.ToString (), "#4");

			Assert.AreEqual (xt.GetAllMembers ().FirstOrDefault (mm => mm.Name == "Type"), xt.GetAllMembers ().FirstOrDefault (mm => mm.Name == "Type"), "#5");
			Assert.AreEqual (xt.GetAllMembers ().FirstOrDefault (mm => mm.Name == "Type"), xt.GetMember ("Type"), "#6");

			// different XamlSchemaContext
			Assert.AreNotEqual (m, XamlLanguage.Type.GetMember ("Type"), "#7");
			Assert.AreNotEqual (XamlLanguage.Type.GetMember ("Type"), new XamlSchemaContext ().GetXamlType (typeof (Type)).GetMember ("Type"), "#7");
			Assert.AreEqual (XamlLanguage.Type.GetMember ("Type"), new XamlSchemaContext ().GetXamlType (typeof (TypeExtension)).GetMember ("Type"), "#8");
		}