System.Xml.Serialization.SerializationCodeGenerator.GenerateAddListValue C# (CSharp) Method

GenerateAddListValue() private method

private GenerateAddListValue ( TypeData listType, string list, string index, string value, bool canCreateInstance ) : void
listType TypeData
list string
index string
value string
canCreateInstance bool
return void
		void GenerateAddListValue (TypeData listType, string list, string index, string value, bool canCreateInstance)
		{
			Type type = listType.Type;
			if (type.IsArray)
			{
				WriteLine (list + " = (" + ToCSharpFullName (type) + ") EnsureArrayIndex (" + list + ", " + index + ", " + GetTypeOf(type.GetElementType()) + ");");
				WriteLine (list + "[" + index + "] = " + value + ";");
			}
			else	// Must be IEnumerable
			{
				WriteLine ("if (((object)" + list + ") == null)");
				if (canCreateInstance) 
					WriteLine ("\t" + list + String.Format (" = ({0}) Activator.CreateInstance(typeof({0}), true);", listType.CSharpFullName));
				else 
					WriteLine ("\tthrow CreateReadOnlyCollectionException (" + GetLiteral (listType.CSharpFullName) + ");");
				
				WriteLine (list + ".Add (" + value + ");");
			}
		}
SerializationCodeGenerator