/// <summary> /// Generates the code for assigning all fields of a component from data from a dictionary. /// </summary> /// <param name="componentName">Name of the component to generate the code for.</param> /// <param name="infos">Data about all fields to assign.</param> /// <returns>Code for assigning all fields of a component from data from a dictionary.</returns> private static string FieldAssignments(string componentName, ComponentFieldInfo[] infos) { const string Format = " component.{0} = ({1})properties[\"{2}.{0}\"];"; var assignments = infos.Select(info => { return string.Format(Format, info.name, info.type, componentName); }).ToArray(); return string.Join("\n", assignments); }
static string fieldNames(ComponentFieldInfo[] fieldInfos) { var args = fieldInfos.Select(info => "new" + info.name.UppercaseFirst()).ToArray(); return string.Join(", ", args); }
static string fieldNamesWithType(ComponentFieldInfo[] fieldInfos) { var typedArgs = fieldInfos .Select(info => info.type + " new" + info.name.UppercaseFirst()) .ToArray(); return string.Join(", ", typedArgs); }
static string fieldAssignments(ComponentFieldInfo[] fieldInfos) { const string format = " component.{0} = {1};"; var assignments = fieldInfos.Select(info => { var newArg = "new" + info.name.UppercaseFirst(); return string.Format(format, info.name, newArg); }).ToArray(); return string.Join("\n", assignments); }