コード例 #1
0
        public TranslateResult TranslateToClr(string type)
        {
            TranslateResult toReturn = new TranslateResult();

            type = type.ToLower();
            if (type.StartsWith("varchar") ||
                type.StartsWith("nvarchar") ||
                type.Equals("uniqueidentifier") ||
                type.StartsWith("char") ||
                type.Contains("text") ||
                type.Contains("memo"))
            {
                toReturn.Type = "string";
            }
            else if (type.StartsWith("varbinary") || type.Contains("blob"))
            {
                toReturn.Type = "byte[]";
            }
            else if (type.Equals("bit", StringComparison.InvariantCultureIgnoreCase) ||
                     type.StartsWith("logical"))
            {
                toReturn.Type = "bool";
            }
            else if (type.StartsWith("date") || type.StartsWith("smalldate"))
            {
                toReturn.Type = "DateTime";
            }
            else if (type.StartsWith("time"))
            {
                toReturn.Type = "TimeSpan";
            }
            else if (type.StartsWith("real") || type.StartsWith("numeric") || type.StartsWith("decimal") || type.StartsWith("float"))
            {
                toReturn.Type = "double";
            }
            else if (type.StartsWith("bigint"))
            {
                toReturn.Type = "long";
            }
            else if (type.Contains("int") || type.Equals("smallint"))
            {
                toReturn.Type = "int";
            }
            else //I give up, give an object
            {
                toReturn.Success = false;
                toReturn.Type    = "object";
            }

            return(toReturn);
        }
コード例 #2
0
        private bool AddPropertyToClass(DBObjectWithType obj, CodeClass newClass, Column v)
        {
            bool failure = false;

            SauceClassGenerationPackage.OutputWindow.OutputStringThreadSafe(string.Format("Processing Column: {0}.{1}..{2}", obj.Object.Name, v.Name, Environment.NewLine));
            TranslateResult result = TranslateToClr(v.DataType);
            string          name   = MakeLegalName(v.Name);

            CodeProperty2 newProp = (CodeProperty2)newClass.AddProperty(name, name, result.Type, Type.Missing, vsCMAccess.vsCMAccessPublic);

            MakeAutoProperty(newProp);
            AddDataFieldAttribute(newProp, obj.Object, v);

            if (!result.Success)
            {
                failure = true;
                SauceClassGenerationPackage.OutputWindow.OutputStringThreadSafe(string.Format("Unable to translate {0} to a CLR type for {1}.{2}", v.DataType, obj.Object.Name, v.Name));
                this.InvokeOnMe(() =>
                {
                    SauceClassGenerationPackage.OutputWindow.Activate();
                });
            }
            return(failure);
        }