public void FillFromDb(int value, string name, string description = null) { string nameCs = EnumNameConverter.MakeValidIdentifier(name); EnumModelValue modelValue = Values.SingleOrDefault(e => e.Value == value); if (modelValue == null) { /* Was found in DB but has not been discovered in code. Must have been added in Db. */ modelValue = new EnumModelValue(); modelValue.Value = value; modelValue.NameCs = nameCs; modelValue.Description = description; modelValue.IsActive = false; Values.Add(modelValue); } else { /* Was found both in DB and in code.*/ //modelValue.Name = name; modelValue.NameCs = EnumNameConverter.MakeValidIdentifier(name); /* Refresh CS name. */ modelValue.Description = description; } modelValue.IsInDB = true; }
public string ToCsCode(string leadingTrivia) { if (IsInDB == false) { return(""); } string result = string.Format("{0} = {1},", NameCs, Value); if (IsActive == false) { result = @"//" + result; } result = leadingTrivia + result; if (Description != null) { string description = string.Format("[Description(\"{0}\")]", EnumNameConverter.MakeValidDescription(Description)); if (IsActive == false) { description = @"//" + description; } result = leadingTrivia + description + Environment.NewLine + result; } return(result); }