Пример #1
0
        public static void ToString(StringBuilder sb, Object[] array)
        {
            if (array == null)
            {
                sb.Append("null");
                return;
            }
            int iMax = array.Length - 1;

            if (iMax == -1)
            {
                sb.Append("[]");
                return;
            }
            sb.Append('[');
            for (int i = 0; ; i++)
            {
                Object item = array[i];
                StringBuilderUtil.AppendPrintable(sb, item);
                if (i == iMax)
                {
                    sb.Append(']');
                    return;
                }
                sb.Append(", ");
            }
        }
Пример #2
0
        public static String ToString(Object[] array)
        {
            if (array == null)
            {
                return("null");
            }
            int iMax = array.Length - 1;

            if (iMax == -1)
            {
                return("[]");
            }
            StringBuilder sb = new StringBuilder();

            sb.Append('[');
            for (int i = 0; ; i++)
            {
                Object item = array[i];
                StringBuilderUtil.AppendPrintable(sb, item);
                if (i == iMax)
                {
                    return(sb.Append(']').ToString());
                }
                sb.Append(", ");
            }
        }
Пример #3
0
        public static String LowerCaseFirst(String s)
        {
            if (s == null || s.Length == 0)
            {
                return("");
            }
            char firstChar = s[0];

            if (Char.IsLower(firstChar))
            {
                return(s);
            }
            return(StringBuilderUtil.Concat(delegate(StringBuilder sb)
            {
                sb.Append(Char.ToLowerInvariant(firstChar));
                sb.Append(s.Substring(1));
            }));
        }
Пример #4
0
        public static MethodInfo GetDeclaredMethod(bool tryOnly, Type type, NewType returnType, String methodName, NewType[] parameters)
        {
            foreach (MethodInfo method in GetDeclaredMethodsInHierarchy(type))
            {
                if (!method.Name.Equals(methodName))
                {
                    continue;
                }
                if (returnType != null && !NewType.GetType(method.ReturnType).Equals(returnType))
                {
                    continue;
                }
                if (parameters == null)
                {
                    return(method);
                }
                ParameterInfo[] currentParameters = method.GetParameters();
                if (currentParameters.Length != parameters.Length)
                {
                    continue;
                }
                bool sameParameters = true;
                for (int a = currentParameters.Length; a-- > 0;)
                {
                    if (parameters[a] != null && !NewType.GetType(currentParameters[a].ParameterType).Equals(parameters[a]))
                    {
                        sameParameters = false;
                        break;
                    }
                }
                if (sameParameters)
                {
                    return(method);
                }
            }
            if (tryOnly)
            {
                return(null);
            }
            String propertyName = methodName;

            if (methodName.ToLowerInvariant().StartsWith("set") ||
                methodName.ToLowerInvariant().StartsWith("get"))
            {
                propertyName = StringBuilderUtil.UpperCaseFirst(methodName.Substring(3));
            }
            PropertyInfo propertyInfo;
            BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy;

            if (returnType != null)
            {
                try
                {
                    propertyInfo = type.GetProperty(propertyName, flags, null, returnType.Type, Type.EmptyTypes, new ParameterModifier[0]);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                propertyInfo = type.GetProperty(propertyName, flags);
            }
            if (propertyInfo != null)
            {
                if (methodName.ToLowerInvariant().StartsWith("set") && propertyInfo.GetSetMethod() != null)
                {
                    return(propertyInfo.GetSetMethod());
                }
                else if (propertyInfo.GetGetMethod() != null)
                {
                    return(propertyInfo.GetGetMethod());
                }
            }
            throw new ArgumentException("No matching method found: " + methodName);
        }