コード例 #1
0
 /// <summary>
 /// check that the class has [primarykey] attribute or not
 /// if yes true
 /// else false
 /// </summary>
 /// <param name="mytype">datatype [ex employee class or student class etc]</param>
 /// <returns></returns>
 private bool ContainsPrimaryKey(MyType myType)
 {
     foreach (PropertyInfo property in myType.GetType().GetProperties())
     {
         if (AttributeHeler.IsPrimaryKeyAttribute(property))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #2
0
        /// <summary>
        /// create comma separated list of property values
        /// if includeprimary is true then primary key value also consider in list
        /// else primary key value is remove from list
        /// </summary>
        /// <param name="mytype">type of class [ex person class or student etc]</param>
        /// <param name="includeprimary">weather primary key property should consider in list or not if yes : consider , if false : removed from list</param>
        private void SetPropertiesValues(MyType myType, bool includePrimary = true)
        {
            string CompleteVal = string.Empty;

            foreach (PropertyInfo property in myType.GetType().GetProperties())
            {
                if (!AttributeHeler.CheckIgnoreColumn(property) && includePrimary == AttributeHeler.IsPrimaryKeyAttribute(property))
                {
                    TypeCode typeCode = Type.GetTypeCode(property.PropertyType);
                    string   Name     = property.Name;
                    Object   value    = property.GetValue(myType, null);
                    var      val      = ClassHelper <MyType> .SetValue(Name, value, myType);

                    CompleteVal += (ClassHelper <MyType> .CreateSqlString(val) + ",");
                }
            }
            CompleteVal      = CompleteVal.Remove(CompleteVal.Length - 1);
            PropertiesValues = CompleteVal;
        }
コード例 #3
0
 /// <summary>
 /// create comma separated propertyname list
 /// if includeprimary is true then primary key propery also consider in list
 /// else primary key property is remove from list
 /// </summary>
 /// <param name="mytype">type of class [ex person class or student etc]</param>
 /// <param name="includeprimary">weather primary key property should consider in list or not if yes : consider , if false : removed from list</param>
 private void SetPropertiesNames(MyType myType, bool includePrimary = true)
 {
     foreach (var property in myType.GetType().GetProperties())
     {
         if (!AttributeHeler.CheckIgnoreColumn(property))
         {
             if (includePrimary)
             {
                 string Name = AttributeHeler.GetColumnName(property);
                 PropertiesNames += (Name + ",");
             }
             else if (!AttributeHeler.IsPrimaryKeyAttribute(property))
             {
                 string Name = AttributeHeler.GetColumnName(property);
                 PropertiesNames += (Name + ",");
             }
         }
     }
     PropertiesNames = PropertiesNames.Remove(PropertiesNames.Length - 1);
 }
コード例 #4
0
        /// <summary>
        /// return primary key name
        /// </summary>
        /// <param name="mytype"></param>
        /// <returns></returns>
        private string SetPimaryKeyName(MyType myType)
        {
            var isContainsPrimarKey = ContainsPrimaryKey(myType);

            if (isContainsPrimarKey)
            {
                //foreach loop can be optimised
                foreach (PropertyInfo property in myType.GetType().GetProperties())
                {
                    if (AttributeHeler.IsPrimaryKeyAttribute(property))
                    {
                        PrimaryKeyNameInSourceCode = property.Name;
                        string primaryKeyName = AttributeHeler.GetColumnName(property);
                        PrimaryKeyNameInDB = primaryKeyName;
                        return(primaryKeyName);
                    }
                }
            }
            else
            {
                throw new Exception(ExceptionMessage.PK_NOT_EXIST);
            }
            throw new Exception("Error occured in SetPkName function");
        }