public static PropertyTemplate RenameProperty(PropertyTemplate property)
        {
            string newName;

            if (property.PropName == property.ClassName)
            {
                //issue12, property name is the same as class name
                //error CS0542: '<PropName>': member names cannot be the same as their enclosing type
                newName = property.PropName.ToggleFirstLetter();
                ModelWarning.Add($"Rename the property '{property.ClassName}.{property.PropName}' to '{newName}' for  avoiding the Compiler error CS0542 ");
                property.PropName = newName;

                property.PropComment += "//Renamed";
            }
            //check if property is reserved keyword
            if (!property.PropName.IsCSharpReservedWord())
            {
                return(property);
            }

            newName = property.PropName.ToggleFirstLetter();
            ModelWarning.Add($"Rename the property {property.ClassName}.{property.PropName} to '{newName}' becauuse its name is a reserved keyword");
            property.PropName = newName;
            return(property);
        }
        private static string ModifyPropertyType(PropertyTemplate prop)
        {
            var          type    = prop.PropType;
            const string pattern = @"List<([\w\.]+)>";
            Match        m       = Regex.Match(type, pattern);
            string       newType;

            if (m.Success)
            {
                var name = m.Groups[1].ToString();
                if (!ClassChangedName.ContainsKey(name))
                {
                    return(type);
                }
                newType = $"List<{ClassChangedName[name]}>";
                ModelWarning.Add($"Modify the type of the property: '{prop.ClassName}.{prop.PropName}' from  {type} to {newType}");
                return(newType);
            }

            if (!ClassChangedName.ContainsKey(type))
            {
                return(type);
            }

            newType = ClassChangedName[type];
            ModelWarning.Add($"++ Modify the type of the property: '{prop.ClassName}.{prop.PropName}' from  {type} to {newType}");
            return(newType);
        }
Beispiel #3
0
        private string RenamePropertyType(PropertyTemplate prop)
        {
            var          type    = prop.PropType;
            const string pattern = @"List<([\w\.]+)>";
            var          m       = Regex.Match(type, pattern);

            if (m.Success)
            {
                var name    = m.Groups[1].ToString();
                var newName = GetNewName(name);
                var newType = $"List<{newName}>";
                return(newType);
            }

            return(GetNewName(type));
        }
 /// <summary>
 /// Initialize in cto
 /// </summary>
 /// <param name="propertyTemplate"></param>
 /// <param name="pocoSetting"></param>
 public PropertyGenerator(PropertyTemplate propertyTemplate, PocoSetting pocoSetting)
 {
     _property = propertyTemplate;
     _setting  = pocoSetting ?? new PocoSetting();
 }