Exemplo n.º 1
0
        /// <summary>
        /// 获取特定属性名称的HashCode和小写的HashCode
        /// </summary>
        /// <param name="member"></param>
        /// <returns></returns>
        private static Expression[] Expr_GetMemberNameHashCodes(MemberInfo member)
        {
            var testCases = new List <Expression>();


            // 计算HashCode的过程放在了代码生成阶段,使用Dictionary的方式时HashCode是执行时计算的。
            StringLowerTable.GetLowerHashCode(member.Name);
            StringLowerTable.GetLowerHashCode(member.Name.ToUpperInvariant());
            int a = member.Name.GetHashCode();
            int b = member.Name.ToLowerInvariant().GetHashCode();

            testCases.Add(Expression.Constant(a));
            testCases.Add(Expression.Constant(b));

            foreach (var attribute in member.GetCustomAttributes(true))
            {
                if (attribute is EntityAttribute)
                {
                    var compatibleName = (attribute as EntityAttribute).Name;

                    StringLowerTable.GetLowerHashCode(compatibleName);
                    StringLowerTable.GetLowerHashCode(compatibleName.ToLowerInvariant());

                    int c = compatibleName.GetHashCode();
                    int d = compatibleName.ToLowerInvariant().GetHashCode();

                    testCases.Add(Expression.Constant(c));
                    testCases.Add(Expression.Constant(d));
                }
            }

            return(testCases.ToArray());
        }
Exemplo n.º 2
0
        public static object GetValue(T obj, string name, bool IgnoreCase)
        {
            if (obj is IDataObject)
            {
                return((obj as IDataObject).GetValue(name, IgnoreCase));
            }

            int HashCode = IgnoreCase ?
                           StringLowerTable.GetLowerHashCode(name.ToLower()) :
                           StringLowerTable.GetLowerHashCode(name);

            return(GetValue_NEW(obj, HashCode));
        }