System.Xml.Serialization.XmlSerializationReaderInterpreter.AddListValue C# (CSharp) Method

AddListValue() private method

private AddListValue ( TypeData listType, object &list, int index, object value, bool canCreateInstance ) : void
listType TypeData
list object
index int
value object
canCreateInstance bool
return void
		void AddListValue (TypeData listType, ref object list, int index, object value, bool canCreateInstance)
		{
			Type type = listType.Type;
			if (type.IsArray)
			{
				list = EnsureArrayIndex ((Array)list, index, type.GetElementType());
				((Array)list).SetValue (value, index);
			}
			else	// Must be IEnumerable
			{
				if (list == null) {
					if (canCreateInstance) list = Activator.CreateInstance (type, true);
					else throw CreateReadOnlyCollectionException (type.FullName);
				}

				MethodInfo mi = type.GetMethod ("Add", new Type[] {listType.ListItemType} );
				mi.Invoke (list, new object[] { value });
			}
		}