Exemple #1
0
        private static CodeTypeReference GetPropertyType(Model model, Property prop)
        {
            CodeTypeReference result = null;
            string            type   = Util.GetType(prop.Type);

            bool isString = false;

            if (type.Contains('.'))
            {
                result = new CodeTypeReference(type);
            }
            else if (model.Generics != null && model.Generics.Contains(type))
            {
                result = new CodeTypeReference(type, CodeTypeReferenceOptions.GenericTypeParameter);
            }
            else
            {
                switch (type)
                {
                case "phoneNumber":
                case "string":
                    result   = new CodeTypeReference(typeof(string));
                    isString = true;
                    break;

                case "long":
                    result = new CodeTypeReference(typeof(long));
                    break;

                case "int":
                    result = new CodeTypeReference(typeof(int));
                    break;

                case "DateTime":
                    result = new CodeTypeReference(typeof(DateTime));
                    break;

                case "bool":
                    result = new CodeTypeReference(typeof(bool));
                    break;

                case "double":
                    result = new CodeTypeReference(typeof(double));
                    break;

                case "string[]":
                    result = new CodeTypeReference(typeof(string[]));
                    break;

                case "long[]":
                    result = new CodeTypeReference(typeof(long[]));
                    break;

                default:
                    result   = new CodeTypeReference(typeof(string));
                    isString = true;
                    break;
                }
            }

            if (prop.CanBeNull && !isString && !type.EndsWith("[]") && !type.Contains("."))
            {
                CodeTypeReference tmp = new CodeTypeReference(typeof(Nullable <>));
                tmp.TypeArguments.Add(result);
                result = tmp;
            }

            return(result);
        }