Mono.Xaml.ManagedXamlLoader.AddChildToItem C# (CSharp) Метод

AddChildToItem() приватный Метод

private AddChildToItem ( XamlCallbackData data, Value parent_parent_ptr, object parent, IntPtr parent_data, Value child_ptr, object child, IntPtr child_data ) : bool
data XamlCallbackData
parent_parent_ptr Mono.Value
parent object
parent_data System.IntPtr
child_ptr Mono.Value
child object
child_data System.IntPtr
Результат bool
		private unsafe bool AddChildToItem (XamlCallbackData *data, Value *parent_parent_ptr, object parent, IntPtr parent_data, Value *child_ptr, object child, IntPtr child_data)
		{
			ResourceDictionary the_dict = parent as ResourceDictionary;
			if (the_dict != null) {
				string key_name = NativeMethods.xaml_get_element_key (data->parser, child_data);

				if (key_name == null) {
					Console.Error.WriteLine ("Attempting to add item to a resource dictionary without an x:Key or x:Name");
					throw new XamlParseException (-1, -1, "You must specify an x:Key or x:Name for elements in a ResourceDictionary");
				}

				try {
					the_dict.Add (key_name, child);
					return true;
				} catch (Exception e) {
					// Fall through to string
					Console.Error.WriteLine (e);
					return false;
				}
			}

			IList the_list = parent as IList;
			if (the_list != null) {

				try {
					the_list.Add (child);
					return true;
				}
				catch {
					return false;
				}
			}

			Type parent_type = parent.GetType ();
			PropertyInfo pi = GetContentProperty (parent_type);

			if (pi == null) {
				Console.Error.WriteLine ("Unable to find content property on type {0}", parent_type);
				return false;
			}

			//
			// Is the content property a collection
			//
			if (typeof (IList).IsAssignableFrom (pi.PropertyType) && !(child is IList)) {
				the_list = (IList) pi.GetValue (parent, null);

				if (the_list == null) {
					the_list = (IList) Activator.CreateInstance (pi.PropertyType);
					if (the_list == null) {
						Console.Error.WriteLine ("Unable to create instance of list: " + pi.PropertyType);
						return false;
					}
					pi.SetValue (parent, the_list, null);
				}

				try {
					the_list.Add (child);
					return true;
				}
				catch {
					return false;
				}
 			}

			string error;

			try {
				return SetPropertyFromValue (data, parent, parent_data, parent_parent_ptr, pi, child_ptr, child_data, out error);
			} catch {
				throw new XamlParseException (2010, String.Format ("{0} does not support {1} as content.", parent, child));
			}
		}