Exemple #1
0
        /// <summary>
        /// Define a new field to emit for the current class.
        /// </summary>
        public void emitField(string name, string type, FieldAttr attr)
        {
            string   key      = className + "/F" + name;
            FieldDef fieldDef = (FieldDef)fields[key];

            if (fieldDef == null)
            {
                // only add if not already stubbed out
                fields[key] = classDef.AddField(attr, name, findType(type));
            }
            else
            {
                // is stubbed out, make sure we define field correctly
                fieldDef.SetFieldAttr(attr);
            }
        }
Exemple #2
0
		public FieldDef AddDefinition (FieldAttr field_attr, string name, 
			TypeRef type, Location location) 
		{
			FieldTableItem item = (FieldTableItem) table[name];
			
			if (item == null) {
				FieldDef field = parent_class.AddField (field_attr, name, type.Type);
				AddDefined (name, field, location);
				return field;
			}
			
			item.Field.AddFieldAttr (field_attr);
			item.Defined = true;
			
			return item.Field;
		}
Exemple #3
0
        public ActiveResult Valid(Object obj)
        {
            ActiveResult vret  = null;
            Type         vType = obj.GetType();
            //获取类名
            String className = vType.Name;

            //获取所有公有属性
            PropertyInfo[] info = vType.GetProperties();

            foreach (PropertyInfo var in info)
            {
                //取得属性的特性标签,false表示不获取因为继承而得到的标签
                Object[] arAttr = var.GetCustomAttributes(false);
                if (arAttr.Length > 0)
                {
                    //从注解数组中取第一个注解(一个属性可以包含多个注解)
                    FieldAttr voAttr = arAttr[0] as FieldAttr;
                    if (voAttr.isAuto == true)
                    {
                        continue;
                    }

                    String FieldName   = var.Name;
                    String cFileDesc   = voAttr.FieldDesc;
                    object objValue    = var.GetValue(obj, null);
                    String cFieldValue = StringEx.getString(objValue);
                    if (voAttr.isRequire)
                    {
                        if (String.IsNullOrEmpty(cFieldValue))
                        {
                            return(ActiveResult.Valid(FieldName, cFileDesc + "不能为空!"));
                        }
                    }

                    if (voAttr.DBLength > 0)
                    {
                        if (voAttr.DBLength < cFieldValue.Length)
                        {
                            return(ActiveResult.Valid(FieldName, cFileDesc + "超过" + cFieldValue.Length + "字符!"));
                        }
                    }
                }
            }

            return(vret);
        }
Exemple #4
0
        public FieldDef AddDefinition(FieldAttr field_attr, string name,
                                      TypeRef type, Location location)
        {
            FieldTableItem item = (FieldTableItem)table[name];

            if (item == null)
            {
                FieldDef field = parent_class.AddField(field_attr, name, type.Type);
                AddDefined(name, field, location);
                return(field);
            }

            item.Field.AddFieldAttr(field_attr);
            item.Defined = true;

            return(item.Field);
        }
Exemple #5
0
        //////////////////////////////////////////////////////////////////////////
        // Emit
        //////////////////////////////////////////////////////////////////////////

        public static void emit(Emitter emitter, FPod pod)
        {
            //FPodEmit emit = new FPodEmit(pod);

            TypeAttr  tattr = TypeAttr.Public | TypeAttr.Sealed;
            FieldAttr fattr = FieldAttr.Public | FieldAttr.Static;

            emitter.emitClass("System.Object", FanUtil.toDotnetTypeName(pod.m_podName, "$Pod", false),
                              new string[0], tattr);

            pod.readLiterals();

            // generate constant fields other types will reference, we don't
            // initialize them, rather we do that later via reflection
            for (int i = 0; i < pod.m_literals.m_ints.size(); i++)
            {
                emitter.emitField("I" + i, "System.Int64", fattr);
            }
            for (int i = 0; i < pod.m_literals.m_floats.size(); i++)
            {
                emitter.emitField("F" + i, "System.Double", fattr);
            }
            for (int i = 0; i < pod.m_literals.m_decimals.size(); i++)
            {
                emitter.emitField("D" + i, "Fan.Sys.BigDecimal", fattr);
            }
            for (int i = 0; i < pod.m_literals.m_strs.size(); i++)
            {
                emitter.emitField("S" + i, "System.String", fattr);
            }
            for (int i = 0; i < pod.m_literals.m_durations.size(); i++)
            {
                emitter.emitField("Dur" + i, "Fan.Sys.Duration", fattr);
            }
            for (int i = 0; i < pod.m_literals.m_uris.size(); i++)
            {
                emitter.emitField("U" + i, "Fan.Sys.Uri", fattr);
            }
        }
Exemple #6
0
 /// <summary>
 /// Add a field to this class
 /// </summary>
 /// <param name="fAtts">attributes for this field</param>
 /// <param name="name">field name</param>
 /// <param name="fType">field type</param>
 /// <returns>a descriptor for this new field</returns>
 public FieldDef AddField(FieldAttr fAtts, string name, Type fType)
 {
     FieldDef field = AddField(name, fType);
     field.SetFieldAttr(fAtts);
     return field;
 }
Exemple #7
0
 internal FieldDef(FieldAttr attrSet, string name, Type fType, Class paren)
     : base(name, fType, paren)
 {
     flags = (ushort)attrSet;
     tabIx = MDTable.Field;
 }
Exemple #8
0
 /// <summary>
 /// Add a "global" field to this module
 /// </summary>
 /// <param name="attrSet">attributes of this field</param>
 /// <param name="name">field name</param>
 /// <param name="fType">field type</param>
 /// <returns>a descriptor for this new "global" field</returns>
 public FieldDef AddField(FieldAttr attrSet, string name, Type fType)
 {
     FieldDef newField = defaultClass.AddField(attrSet, name, fType);
     return newField;
 }
Exemple #9
0
        public static Object readFromRequest(HttpRequest request, Object obj)
        {
            Type vType = obj.GetType();
            //获取类名
            String className = vType.Name;

            //获取所有公有属性
            PropertyInfo[] info = vType.GetProperties();

            foreach (PropertyInfo var in info)
            {
                //取得属性的特性标签,false表示不获取因为继承而得到的标签
                Object[] attr = var.GetCustomAttributes(false);
                if (attr.Length > 0)
                {
                    FieldAttr vAttr = attr[0] as FieldAttr;

                    String cFieldName  = var.Name;
                    String cFieldValue = StringEx.getString(request[cFieldName]);

                    if (vAttr.DBType == ActionField.ftBoolean)
                    {
                        if (cFieldValue.Length > 0)
                        {
                            if ((cFieldValue != "1") && (cFieldValue != "0"))
                            {
                                if (cFieldValue.Equals("on"))
                                {
                                    cFieldValue = "1";
                                }
                                else
                                {
                                    cFieldValue = "0";
                                }
                            }
                        }
                        else
                        {
                            cFieldValue = "0";
                        }
                    }
                    if (cFieldValue.Length > 0)
                    {
                        String cFieldType = var.PropertyType.ToString();
                        if (cFieldType.IndexOf("String") > -1)
                        {
                            var.SetValue(obj, cFieldValue, null);
                        }
                        else if (cFieldType.IndexOf("Int32") > -1)
                        {
                            Int32 iFieldValue = StringEx.getInt32(cFieldValue);
                            var.SetValue(obj, iFieldValue, null);
                        }
                        else if (cFieldType.IndexOf("Int64") > -1)
                        {
                            Int64 iFieldValue = StringEx.getInt64(cFieldValue);
                            var.SetValue(obj, iFieldValue, null);
                        }
                        else if (cFieldType.IndexOf("Single") > -1)
                        {
                            try
                            {
                                Single iFieldValue = Single.Parse(cFieldValue);
                                var.SetValue(obj, iFieldValue, null);
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                        else if (cFieldType.IndexOf("Double") > -1)
                        {
                            try
                            {
                                Double iFieldValue = Double.Parse(cFieldValue);
                                var.SetValue(obj, iFieldValue, null);
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                        else if (cFieldType.IndexOf("DateTime") > -1)
                        {
                            try
                            {
                                DateTime iFieldValue = DateTime.Parse(cFieldValue);
                                var.SetValue(obj, iFieldValue, null);
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                }
            }
            return(obj);
        }
Exemple #10
0
 internal FieldDef(FieldAttr attrSet, string name, Type fType, ClassSpec paren)
     : base(name, fType,paren)
 {
     flags = (ushort)attrSet;
     tabIx = MDTable.Field;
 }
Exemple #11
0
 public void SetFieldAttr(FieldAttr fa)
 {
     flags = (ushort)fa;
 }
Exemple #12
0
 /// <summary>
 /// Define a new field to emit for the current class.
 /// </summary>
 public void emitField(string name, string type, FieldAttr attr)
 {
     string key = className + "/F" + name;
       FieldDef fieldDef = (FieldDef)fields[key];
       if (fieldDef == null)
       {
     // only add if not already stubbed out
     fields[key] = classDef.AddField(attr, name, findType(type));
       }
       else
       {
     // is stubbed out, make sure we define field correctly
     fieldDef.SetFieldAttr(attr);
       }
 }
Exemple #13
0
 public void SetFieldAttr(FieldAttr fa)
 {
     flags = (ushort)fa;
 }
 /// <summary>
 /// Add a "global" field to this module
 /// </summary>
 /// <param name="attrSet">attributes of this field</param>
 /// <param name="name">field name</param>
 /// <param name="fType">field type</param>
 /// <returns>a descriptor for this new "global" field</returns>
 public FieldDef AddField(FieldAttr attrSet, string name, Type fType) {
   return moduleClass.AddField(attrSet,name,fType);
 }
		internal FieldDef(FieldAttr attrSet, string name, Type fType) : base(name, fType) 
		{
			flags = (ushort)attrSet;
			tabIx = MDTable.Field;
		}
        /// <summary>
        /// Add a "global" field to this module
        /// </summary>
        /// <param name="attrSet">attributes of this field</param>
        /// <param name="name">field name</param>
        /// <param name="fType">field type</param>
        /// <returns>a descriptor for this new "global" field</returns>
        public FieldDef AddField(FieldAttr attrSet, string name, Type fType)
        {
            FieldDef newField = defaultClass.AddField(attrSet, name, fType);

            return(newField);
        }
Exemple #17
0
        public String Insert(T obj)
        {
            List <String> FieldList = new List <string>();
            List <Object> ValueList = new List <Object>();

            Type vType = obj.GetType();
            //获取类名
            String className = vType.Name;

            //获取所有公有属性
            PropertyInfo[] info = vType.GetProperties();

            foreach (PropertyInfo var in info)
            {
                //取得属性的特性标签,false表示不获取因为继承而得到的标签
                Object[] attr = var.GetCustomAttributes(false);
                if (attr.Length > 0)
                {
                    //从注解数组中取第一个注解(一个属性可以包含多个注解)
                    FieldAttr myattr = attr[0] as FieldAttr;
                    if (myattr.isAuto == true)
                    {
                        continue;
                    }
                }
                FieldList.Add(var.Name);
                object objValue = var.GetValue(obj, null);
                ValueList.Add(objValue);
            }
            StringBuilder sql = new StringBuilder();

            sql.Append("INSERT INTO " + className);
            sql.Append(" ( ");
            for (int i = 0; i < FieldList.Count; i++)
            {
                String cFieldName = FieldList[i];
                if (i == 0)
                {
                    sql.Append(cFieldName);
                }
                else
                {
                    sql.Append("," + cFieldName);
                }
            }
            sql.Append(" )");


            sql.Append(" VALUES ( ");

            for (int i = 0; i < ValueList.Count; i++)
            {
                Object objValue    = ValueList[i];
                String cFieldValue = (objValue == null) ? "null" : "'" + objValue.ToString() + "'";
                if (i == 0)
                {
                    sql.Append(cFieldValue);
                }
                else
                {
                    sql.Append("," + cFieldValue);
                }
            }
            sql.Append(" )");
            return(sql.ToString());
        }
Exemple #18
0
        public object ReadDB(Object obj, DataRow dr)
        {
            ActiveResult vret  = null;
            Type         vType = obj.GetType();

            //获取所有公有属性
            PropertyInfo[] info = vType.GetProperties();
            foreach (PropertyInfo var in info)
            {
                //取得属性的特性标签,false表示不获取因为继承而得到的标签
                Object[] attrList = var.GetCustomAttributes(false);
                if (attrList.Length > 0)
                {
                    //从注解数组中取第一个注解(一个属性可以包含多个注解)
                    FieldAttr vAttr      = attrList[0] as FieldAttr;
                    String    cFieldDesc = vAttr.FieldDesc;
                    String    cFieldName = vAttr.FieldName;
                    if (cFieldName == null)
                    {
                        cFieldName = var.Name;
                    }

                    String cFieldValue = StringEx.getString(dr[cFieldName]);
                    String cFieldType  = var.PropertyType.ToString();
                    if (cFieldType.IndexOf("String") > -1)
                    {
                        var.SetValue(obj, cFieldValue, null);
                    }
                    else if (cFieldType.IndexOf("Int32") > -1)
                    {
                        int iFieldValue = StringEx.getInt(cFieldValue);
                        var.SetValue(obj, iFieldValue, null);
                    }
                    else if (cFieldType.IndexOf("DateTime") > -1)
                    {
                        try
                        {
                            DateTime vDate = DateTime.Parse(cFieldValue);
                            var.SetValue(obj, vDate, null);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    else if (cFieldType.IndexOf("Single") > -1)
                    {
                        try
                        {
                            Single vDate = Single.Parse(cFieldValue);
                            var.SetValue(obj, vDate, null);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    else if (cFieldType.IndexOf("Double") > -1)
                    {
                        try
                        {
                            Double vDate = Double.Parse(cFieldValue);
                            var.SetValue(obj, vDate, null);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    else if (cFieldType.IndexOf("Int64") > -1)
                    {
                        int iFieldValue = StringEx.getInt(cFieldValue);
                        var.SetValue(obj, iFieldValue, null);
                    }
                }
            }

            return(obj);
        }
Exemple #19
0
        public ActiveResult CheckData(T obj)
        {
            ActiveResult vret  = null;
            Type         vType = obj.GetType();

            //获取所有公有属性
            PropertyInfo[] info = vType.GetProperties();
            foreach (PropertyInfo var in info)
            {
                //取得属性的特性标签,false表示不获取因为继承而得到的标签
                Object[] attrList = var.GetCustomAttributes(false);
                if (attrList.Length > 0)
                {
                    //从注解数组中取第一个注解(一个属性可以包含多个注解)
                    FieldAttr vAttr      = attrList[0] as FieldAttr;
                    String    cFieldDesc = vAttr.FieldDesc;
                    String    cFieldName = vAttr.FieldName;
                    if (cFieldName == null)
                    {
                        cFieldName = var.Name;
                    }
                    Object objValue = var.GetValue(obj, null);

                    if (vAttr.isKey && (!vAttr.isAuto))
                    {
                        if (objValue == null)
                        {
                            vret = ActiveResult.Valid(cFieldName, cFieldDesc + "不能为空!");
                            break;
                        }
                    }

                    if ((vAttr.DBType == ActionField.ftString) && (objValue != null))
                    {
                        if (StringEx.getString(objValue).Length > vAttr.DBLength)
                        {
                            vret = ActiveResult.Valid(cFieldName, cFieldDesc + "长度不能超过" + vAttr.DBLength + "!");
                            break;
                        }
                    }
                    if ((vAttr.DBType == ActionField.ftBoolean) && (objValue != null))
                    {
                        String cValue = StringEx.getString(objValue).ToUpper();
                        if ((cValue.Equals("0") || cValue.Equals("1") || cValue.Equals("Y") || cValue.Equals("N")))
                        {
                            objValue = "1";
                        }
                        else
                        {
                            vret = ActiveResult.Valid(cFieldName, cFieldDesc + "必须是布尔类型!");
                            break;
                        }
                    }
                    if ((vAttr.DBType == ActionField.ftInteger) && (objValue != null))
                    {
                        try
                        {
                            int.Parse(objValue.ToString());
                        }
                        catch (Exception ex)
                        {
                            vret = ActiveResult.Valid(cFieldName, cFieldDesc + "必须是整数!");
                            break;
                        }
                    }
                    if ((vAttr.DBType == ActionField.ftLong) && (objValue != null))
                    {
                        try
                        {
                            Int64.Parse(objValue.ToString());
                        }
                        catch (Exception ex)
                        {
                            vret = ActiveResult.Valid(cFieldName, cFieldDesc + "必须是长整型!");
                            break;
                        }
                    }

                    if ((vAttr.DBType == ActionField.ftFloat) && (objValue != null))
                    {
                        try
                        {
                            float.Parse(objValue.ToString());
                        }
                        catch (Exception ex)
                        {
                            vret = ActiveResult.Valid(cFieldName, cFieldDesc + "必须是浮点数!");
                            break;
                        }
                    }
                    if ((vAttr.DBType == ActionField.ftDouble) && (objValue != null))
                    {
                        try
                        {
                            double.Parse(objValue.ToString());
                        }
                        catch (Exception ex)
                        {
                            vret = ActiveResult.Valid(cFieldName, cFieldDesc + "必须是双精度浮点数!");
                            break;
                        }
                    }
                }
            }
            return(vret);
        }
Exemple #20
0
        public String Update(T obj, String cWhereParm)
        {
            List <String> FieldList = new List <string>();
            List <Object> ValueList = new List <Object>();

            Type vType = obj.GetType();
            //获取类名
            String className = vType.Name;

            //获取所有公有属性
            PropertyInfo[] info = vType.GetProperties();

            foreach (PropertyInfo var in info)
            {
                //取得属性的特性标签,false表示不获取因为继承而得到的标签
                Object[] attr = var.GetCustomAttributes(false);

                if (attr.Length > 0)
                {
                    //从注解数组中取第一个注解(一个属性可以包含多个注解)
                    FieldAttr myattr = attr[0] as FieldAttr;

                    if (myattr.isAuto == true)
                    {
                        continue;
                    }
                }
                FieldList.Add(var.Name);
                Object cFieldValue = var.GetValue(obj, null);
                ValueList.Add(cFieldValue);
            }

            StringBuilder sql = new StringBuilder();

            sql.Append("UPDATE " + className);
            sql.Append(" SET ");
            for (int i = 0; i < FieldList.Count; i++)
            {
                String cFieldName  = FieldList[i];
                Object cFieldValue = ValueList[i];
                if (cFieldValue == null)
                {
                    cFieldValue = "null";
                }
                else
                {
                    cFieldValue = "'" + cFieldValue + "'";
                }
                if (i == 0)
                {
                    sql.Append(" " + cFieldName + "=" + cFieldValue + "");
                }
                else
                {
                    sql.Append("," + cFieldName + "=" + cFieldValue + "");
                }
            }

            sql.Append(" WHERE " + cWhereParm);
            return(sql.ToString());

            Console.WriteLine(sql);
        }
		/// <summary>
		/// Add a field to this class
		/// </summary>
		/// <param name="fAtts">attributes for this field</param>
		/// <param name="name">field name</param>
		/// <param name="fType">field type</param>
		/// <returns>a descriptor for this new field</returns>
		public FieldDef AddField(FieldAttr fAtts, string name, Type fType) 
		{
			FieldDef field = new FieldDef(fAtts,name,fType);
			fields.Add(field);
			return field;
		}
Exemple #22
0
        /*------------------------- public set and get methods --------------------------*/

        /// <summary>
        /// Add an attribute(s) to this field
        /// </summary>
        /// <param name="fa">the attribute(s) to be added</param>
        public void AddFieldAttr(FieldAttr fa)
        {
            flags |= (ushort)fa;
        }
		/// <summary>
		/// Add an attribute(s) to this field
		/// </summary>
		/// <param name="fa">the attribute(s) to be added</param>
		public void AddFieldAttr(FieldAttr fa) 
		{
			flags |= (ushort)fa;
		}
 internal static FieldDef AddField(ClassDef ParentClass, FieldAttr attr, string fieldName, PERWAPI.Type fieldType) {
     return ParentClass.AddField(attr, fieldName, fieldType);
 }