Example #1
0
        public Name GetCodeIdentifier(Field field)
        {
            if (_fieldNameMap.TryGetValue(field, out var name))
            {
                return(name);
            }

            var def = field.DeclaringType;

            if (def == null)
            {
                // Method parameters are internally represented with the same class "Field".
                // They do not have a declaring type. Anyway, they don't suffer from the field-name-equals-nested-type-name problem.
                return(new Name(SyntaxHelpers.MakeCamel(field.Name)));
            }

            var typeNames = new HashSet <Name>(def.NestedTypes.Select(t => MakeTypeName(t)));

            typeNames.Add(MakeTypeName(def));

            foreach (var member in def.Fields)
            {
                var memberName = new Name(SyntaxHelpers.MakeCamel(member.Name));

                while (typeNames.Contains(memberName))
                {
                    memberName = new Name(string.Format(PropertyNamedLikeTypeRenameFormat, memberName.ToString()));
                }

                _fieldNameMap.Add(member, memberName);
            }

            return(_fieldNameMap[field]);
        }
Example #2
0
        public static NameSyntax NamespaceName(string[] @namespace)
        {
            NameSyntax ident = null;

            if (@namespace != null)
            {
                ident = IdentifierName(SyntaxHelpers.MakeCamel(@namespace[0]));
                foreach (string name in @namespace.Skip(1))
                {
                    var temp = IdentifierName(SyntaxHelpers.MakeCamel(name));
                    ident = QualifiedName(ident, temp);
                }
            }
            return(ident);
        }
Example #3
0
 public Name GetCodeIdentifier(Method method)
 {
     return(new Name(SyntaxHelpers.MakeCamel(method.Name)));
 }