public static InstructionSave SetPropertyValue(this NamedObjectSave instance, string propertyName, object valueToSet) { InstructionSave instruction = instance.GetInstructionFromMember(propertyName); if (instruction == null) { TypedMemberBase tmb = instance.TypedMembers.FirstOrDefault(member => member.MemberName == propertyName); if (tmb != null) { instruction = instance.AddNewGenericInstructionFor(propertyName, tmb.MemberType); } else { instruction = instance.AddNewGenericInstructionFor(propertyName, valueToSet.GetType()); } if (tmb.CustomTypeName != null) { instruction.Type = tmb.CustomTypeName; } } instruction.Value = valueToSet; return(instruction); }