コード例 #1
0
        private TbField getPrimaryField <T>(T t)
        {
            PropertyInfo[] properties = t.GetType().GetProperties();
            if (properties == null)
            {
                return(null);
            }

            foreach (PropertyInfo property in properties)
            {
                object[] propertyAttrs = property.GetCustomAttributes(false);
                for (int i = 0; i < propertyAttrs.Length; i++)
                {
                    object propertyAttr = propertyAttrs[i];
                    if (propertyAttr is IdAttribute)
                    {
                        TbField tf = new TbField();
                        tf.Name  = property.Name;
                        tf.Value = property.GetValue(t, null);
                        return(tf);
                    }
                }
            }

            return(null);
        }
コード例 #2
0
        private string getPrimaryKey <T>(T t)
        {
            TbField tf = getPrimaryField <T>(t);

            if (tf == null)
            {
                return("");
            }

            if (tf.Value == null)
            {
                return(string.Format("{0}", t.GetType().Name));
            }
            else
            {
                return(string.Format("{0}:{1}", t.GetType().Name, tf.Value));
            }
        }