System.Xaml.XamlObjectWriterInternal.OnWriteEndObject C# (CSharp) Method

OnWriteEndObject() protected method

protected OnWriteEndObject ( ) : void
return void
		protected override void OnWriteEndObject ()
		{
			InitializeObjectIfRequired (false); // this is required for such case that there was no StartMember call.

			var state = object_states.Pop ();
			var obj = state.Value;
			
			if (obj is MarkupExtension) {
				try {
					obj = ((MarkupExtension) obj).ProvideValue (service_provider);
				} catch (XamlObjectWriterException) {
					throw;
				} catch (Exception ex) {
					throw new XamlObjectWriterException ("An error occured on getting provided value", ex);
				}
			}
			var nfr = obj as NameFixupRequired;
			if (nfr != null && object_states.Count > 0) { // IF the root object to be written is x:Reference, then the Result property will become the NameFixupRequired. That's what .NET also does.
				// actually .NET seems to seek "parent" object in its own IXamlNameResolver implementation.
				var pstate = object_states.Peek ();
				nfr.ParentType = pstate.Type;
				nfr.ParentMember = CurrentMember; // Note that it is a member of the pstate.
				nfr.ParentValue = pstate.Value;
				pending_name_references.Add ((NameFixupRequired) obj);
			}
			else
				StoreAppropriatelyTypedValue (obj, state.KeyValue);
			object_states.Push (state);
			if (object_states.Count == 1) {
				Result = obj;
				ResolvePendingReferences ();
			}
		}