Example #1
0
        public string GetNameForIdentifier(Type type)
        {
            var rawName = m_InnerHandler.GetNameForIdentifier(type);

            // don't allow identifiers to match c# keywords.
            if (s_Keywords.Contains(rawName))
            {
                var prefix = type.IsInterface ? "stub" : "dummy";
                return($"{prefix}{rawName}");
            }

            // don't allow identifiers to exactly match type names
            if (rawName != type.Name)
            {
                return(rawName);
            }

            if (type == typeof(string))
            {
                return("str");
            }
            if (type == typeof(int))
            {
                return("number");
            }

            return(rawName + "Value");
        }
        public string GetNameForIdentifier(Type type)
        {
            if (!m_NameForIdentifierCache.ContainsKey(type))
            {
                m_NameForIdentifierCache[type] = m_InnerTypeHandler.GetNameForIdentifier(type);
            }

            return(m_NameForIdentifierCache[type]);
        }
        public string GetNameForIdentifier(Type type)
        {
            var name = m_InnerHandler.GetNameForIdentifier(type);

            if (type.IsInterface && name.StartsWith("I"))
            {
                name = new string(name.Skip(1).ToArray());
            }
            return(name);
        }
        public string[] GetMethodArguments(MethodBase methodBase, bool useVariables, bool nonDefault)
        {
            var parameters = methodBase.GetParameters();

            var paramterTypesClean = parameters
                                     .Select(p => p.ParameterType.IsByRef
                            ? p.ParameterType.GetElementType()
                            : p.ParameterType);

            var arguments = useVariables
                ? paramterTypesClean.Select(t => StringUtils.ToLowerInitial(m_TypeHandler.GetNameForIdentifier(t))).ToArray()
                : paramterTypesClean.Select(t => m_TypeHandler.GetInstantiation(t, nonDefault)).ToArray();

            // at this point 'arguments' is an array of variable names that are assumed
            // to be in scope. This loop modifies them.
            for (var i = 0; i < parameters.Length; i++)
            {
                var pInfo = parameters[i];
                var pType = pInfo.ParameterType;
                // If we need 'out' or 'ref' prefix
                if (HasParamKeyword(pInfo))
                {
                    var argument = arguments[i];
                    arguments[i] = $"{ParamKeyword(pInfo)} {argument}";
                }
                // For strings, use the parameter name as the value for ease of reading.
                else if (pType == typeof(string))
                {
                    arguments[i] = $"\"{pInfo.Name.ToLower()}\"";
                }
                // For types which don't really need a variable to hold the value 'cos they
                // have short instantiations, then we just in-line instantiate.
                // The cost elsewhere that makes the variables should be kept in sync, so we don't
                // have unused variable declarations lying around.
                else if (IsInstantiationTerse(pType))
                {
                    arguments[i] = GetInstantiation(pType, nonDefault);
                }
            }

            return(arguments);
        }
Example #5
0
        public string GetNameForIdentifier(Type type)
        {
            var typeDisplayName = type.Name;
            var genArgs         = type.GetGenericArguments();
            int index           = typeDisplayName.IndexOf('`');

            typeDisplayName = index == -1 ? typeDisplayName : typeDisplayName.Substring(0, index);
            typeDisplayName = typeDisplayName
                              + string.Join("", genArgs.Select(p => m_RootHandler.GetNameForIdentifier(p)));
            return(typeDisplayName);
        }
Example #6
0
        public string GetInstantiation(Type type, bool interestingValue)
        {
            if (type.IsClass &&
                !type.IsAbstract &&
                type.GetConstructors().Any(ctor => ctor.GetParameters().Length == 0))
            {
                return($"new {m_RootHandler.GetNameForCSharp(type)}()");
            }

            // Assume a helper method exists
            return($"Create{m_RootHandler.GetNameForIdentifier(type)}()");
        }
        public string GetNameForIdentifier(Type type)
        {
            var dictionaryType = GetDictionaryTypeForAssignment(type);

            return(m_RootHandler.GetNameForIdentifier(dictionaryType));
        }
Example #8
0
        public string GetNameForIdentifier(Type type)
        {
            var identifier = m_RootHandler.GetNameForIdentifier(GetArrayElementType(type));

            return(StringUtils.Pluralise($"{identifier}"));
        }
Example #9
0
        public string GetNameForIdentifier(Type type)
        {
            var name = m_InnerHandler.GetNameForIdentifier(type);

            return(StringUtils.ToLowerInitial(name));
        }