Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Util
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv9486/Util
Modified Files:
ReflectionUtils.cs
Log Message:
added xml doc comments
Index: ReflectionUtils.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Util/ReflectionUtils.cs,v
retrieving revision 1.48
retrieving revision 1.49
diff -C2 -d -r1.48 -r1.49
*** ReflectionUtils.cs 22 Aug 2007 08:49:46 -0000 1.48
--- ReflectionUtils.cs 27 Aug 2007 13:57:18 -0000 1.49
***************
*** 48,53 ****
/// </summary>
public const BindingFlags AllMembersCaseInsensitiveFlags = BindingFlags.Public |
! BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static
! | BindingFlags.IgnoreCase;
/// <summary>
--- 48,54 ----
/// </summary>
public const BindingFlags AllMembersCaseInsensitiveFlags = BindingFlags.Public |
! BindingFlags.NonPublic | BindingFlags.Instance
! | BindingFlags.Static
! | BindingFlags.IgnoreCase;
/// <summary>
***************
*** 97,102 ****
method,
ReflectionUtils.AllMembersCaseInsensitiveFlags,
! null, argumentTypes == null ?
! Type.EmptyTypes : argumentTypes , null);
if (retMethod == null)
{
--- 98,105 ----
method,
ReflectionUtils.AllMembersCaseInsensitiveFlags,
! null,
! argumentTypes == null ? Type.EmptyTypes : argumentTypes,
! null);
!
if (retMethod == null)
{
***************
*** 149,187 ****
#if NET_2_0
! /// <summary>
! /// Returns an array of <see langword="string"/>s that represent
! /// the names of the generic type parameter.
! /// </summary>
! /// <param name="method">The method.</param>
! /// <returns>An array containing the parameter names.</returns>
! /// <exception cref="System.ArgumentNullException">
! /// If <paramref name="method"/> is <see langword="null"/>.
! /// </exception>
! public static string[] GetGenericParameterNames(MethodInfo method)
! {
! AssertUtils.ArgumentNotNull(method, "method");
! return GetGenericParameterNames(method.GetGenericArguments());
! }
! /// <summary>
! /// Returns an array of <see langword="string"/>s that represent
! /// the names of the generic type parameter.
! /// </summary>
! /// <param name="args">The parameter info array.</param>
! /// <returns>An array containing parameter names.</returns>
! /// <exception cref="System.ArgumentNullException">
! /// If <paramref name="args"/> is <see langword="null"/> or any of the
! /// elements <paramref name="args"/> is <see langword="null"/>.
! /// </exception>
! public static string[] GetGenericParameterNames(Type[] args)
! {
! AssertUtils.ArgumentNotNull(args, "args");
! string[] names = new string[args.Length];
! for (int i = 0; i < args.Length; i++)
! {
! names[i] = args[i].Name;
! }
! return names;
! }
#endif
--- 152,190 ----
#if NET_2_0
! /// <summary>
! /// Returns an array of <see langword="string"/>s that represent
! /// the names of the generic type parameter.
! /// </summary>
! /// <param name="method">The method.</param>
! /// <returns>An array containing the parameter names.</returns>
! /// <exception cref="System.ArgumentNullException">
! /// If <paramref name="method"/> is <see langword="null"/>.
! /// </exception>
! public static string[] GetGenericParameterNames(MethodInfo method)
! {
! AssertUtils.ArgumentNotNull(method, "method");
! return GetGenericParameterNames(method.GetGenericArguments());
! }
! /// <summary>
! /// Returns an array of <see langword="string"/>s that represent
! /// the names of the generic type parameter.
! /// </summary>
! /// <param name="args">The parameter info array.</param>
! /// <returns>An array containing parameter names.</returns>
! /// <exception cref="System.ArgumentNullException">
! /// If <paramref name="args"/> is <see langword="null"/> or any of the
! /// elements <paramref name="args"/> is <see langword="null"/>.
! /// </exception>
! public static string[] GetGenericParameterNames(Type[] args)
! {
! AssertUtils.ArgumentNotNull(args, "args");
! string[] names = new string[args.Length];
! for (int i = 0; i < args.Length; i++)
! {
! names[i] = args[i].Name;
! }
! return names;
! }
#endif
***************
*** 236,377 ****
}
! public static MethodInfo GetMethodByArgumentValues(MethodInfo[] methods, object[] argValues)
! {
! return (MethodInfo) GetMethodBaseByArgumentValues("method", methods, argValues);
! }
! public static ConstructorInfo GetConstructorByArgumentValues(ConstructorInfo[] methods, object[] argValues)
! {
! return (ConstructorInfo)GetMethodBaseByArgumentValues("constructr", methods, argValues);
! }
- private static MethodBase GetMethodBaseByArgumentValues(string methodTypeName, MethodBase[] methods, object[] argValues)
- {
- MethodBase match = null;
- int matchCount = 0;
! foreach (MethodBase m in methods)
! {
! ParameterInfo[] parameters = m.GetParameters();
! bool isMatch = true;
! bool isExactMatch = true;
! object[] paramValues = argValues;
! try
! {
! if (parameters.Length > 0)
! {
! ParameterInfo lastParameter = parameters[parameters.Length - 1];
! if (lastParameter.GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0)
! {
! paramValues =
! PackageParamArray(argValues, parameters.Length,
! lastParameter.ParameterType.GetElementType());
! }
! }
! for (int i = 0; i < parameters.Length; i++)
! {
! Type paramType = parameters[i].ParameterType;
! object paramValue = paramValues[i];
! if ( (paramValue == null && paramType.IsValueType)
! || (paramValue != null && !paramType.IsAssignableFrom(paramValue.GetType())) )
! {
! isMatch = false;
! break;
! }
! if ( paramValue == null || paramType != paramValue.GetType())
! {
! isExactMatch = false;
! }
! }
! }
! catch (InvalidCastException)
! {
! isMatch = false;
! }
! if (isMatch)
! {
! if (isExactMatch)
! {
! return m;
! }
! matchCount++;
! if (matchCount == 1)
! {
! match = m;
! }
! else
! {
! throw new AmbiguousMatchException(string.Format("Ambiguous match for {0} '{1}' for the specified number and types of arguments.", methodTypeName, m.Name));
! }
! }
! }
! return match;
! }
! /// <summary>
! /// Packages arguments into argument list containing parameter array as a last argument.
! /// </summary>
! /// <param name="argValues">Argument vaklues to package.</param>
! /// <param name="argCount">Total number of oarameters.</param>
! /// <param name="elementType">Type of the param array element.</param>
! /// <returns>Packaged arguments.</returns>
! public static object[] PackageParamArray(object[] argValues, int argCount, Type elementType)
! {
! object[] values = new object[argCount];
! int i = 0;
! // copy regular arguments
! while (i < argCount - 1)
! {
! values[i] = argValues[i];
! i++;
! }
! // package param array into last argument
! Array paramArray = Array.CreateInstance(elementType, argValues.Length - i);
! int j = 0;
! while (i < argValues.Length)
! {
! paramArray.SetValue(argValues[i++], j++);
! }
! values[values.Length - 1] = paramArray;
! return values;
! }
! /// <summary>
! /// Convenience method to convert an interface <see cref="System.Type"/>
! /// to a <see cref="System.Type"/> array that contains
! /// all the interfaces inherited and the specified interface.
! /// </summary>
! /// <param name="intf">The interface to convert.</param>
! /// <returns>An array of interface <see cref="System.Type"/>s.</returns>
! /// <exception cref="System.ArgumentException">
! /// If the <see cref="System.Type"/> specified is not an interface.
! /// </exception>
! /// <exception cref="System.ArgumentNullException">
! /// If <paramref name="intf"/> is <see langword="null"/>.
! /// </exception>
! public static Type[] ToInterfaceArray(Type intf)
! {
! AssertUtils.ArgumentNotNull(intf, "intf");
! if (!intf.IsInterface)
! {
! throw new ArgumentException(
! string.Format(CultureInfo.InvariantCulture,
! "[{0}] is a class.",
! intf.FullName));
! }
! ArrayList interfaces = new ArrayList(intf.GetInterfaces());
! interfaces.Add(intf);
! return (Type[])interfaces.ToArray(typeof(Type));
! }
/// <summary>
--- 239,413 ----
}
! /// <summary>
! /// From a given list of methods, selects the method having an exact match on the given <paramref name="argValues"/>' types.
! /// </summary>
! /// <param name="methods">the list of methods to choose from</param>
! /// <param name="argValues">the arguments to the method</param>
! /// <returns>the method matching exactly the passed <paramref name="argValues"/>' types</returns>
! /// <exception cref="AmbiguousMatchException">
! /// If more than 1 matching methods are found in the <paramref name="methods"/> list.
! /// </exception>
! public static MethodInfo GetMethodByArgumentValues(MethodInfo[] methods, object[] argValues)
! {
! return (MethodInfo) GetMethodBaseByArgumentValues("method", methods, argValues);
! }
! /// <summary>
! /// From a given list of constructors, selects the constructor having an exact match on the given <paramref name="argValues"/>' types.
! /// </summary>
! /// <param name="methods">the list of constructors to choose from</param>
! /// <param name="argValues">the arguments to the method</param>
! /// <returns>the constructor matching exactly the passed <paramref name="argValues"/>' types</returns>
! /// <exception cref="AmbiguousMatchException">
! /// If more than 1 matching methods are found in the <paramref name="methods"/> list.
! /// </exception>
! public static ConstructorInfo GetConstructorByArgumentValues(ConstructorInfo[] methods, object[] argValues)
! {
! return (ConstructorInfo) GetMethodBaseByArgumentValues("constructor", methods, argValues);
! }
! /// <summary>
! /// From a given list of methods, selects the method having an exact match on the given <paramref name="argValues"/>' types.
! /// </summary>
! /// <param name="methodTypeName">the type of method (used for exception reporting only)</param>
! /// <param name="methods">the list of methods to choose from</param>
! /// <param name="argValues">the arguments to the method</param>
! /// <returns>the method matching exactly the passed <paramref name="argValues"/>' types</returns>
! /// <exception cref="AmbiguousMatchException">
! /// If more than 1 matching methods are found in the <paramref name="methods"/> list.
! /// </exception>
! private static MethodBase GetMethodBaseByArgumentValues(string methodTypeName, MethodBase[] methods,
! object[] argValues)
! {
! MethodBase match = null;
! int matchCount = 0;
! foreach (MethodBase m in methods)
! {
! ParameterInfo[] parameters = m.GetParameters();
! bool isMatch = true;
! bool isExactMatch = true;
! object[] paramValues = argValues;
! try
! {
! if (parameters.Length > 0)
! {
! ParameterInfo lastParameter = parameters[parameters.Length - 1];
! if (lastParameter.GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0)
! {
! paramValues =
! PackageParamArray(argValues, parameters.Length,
! lastParameter.ParameterType.GetElementType());
! }
! }
! for (int i = 0; i < parameters.Length; i++)
! {
! Type paramType = parameters[i].ParameterType;
! object paramValue = paramValues[i];
! if ((paramValue == null && paramType.IsValueType)
! || (paramValue != null && !paramType.IsAssignableFrom(paramValue.GetType())))
! {
! isMatch = false;
! break;
! }
! if (paramValue == null || paramType != paramValue.GetType())
! {
! isExactMatch = false;
! }
! }
! }
! catch (InvalidCastException)
! {
! isMatch = false;
! }
! if (isMatch)
! {
! if (isExactMatch)
! {
! return m;
! }
! matchCount++;
! if (matchCount == 1)
! {
! match = m;
! }
! else
! {
! throw new AmbiguousMatchException(
! string.Format("Ambiguous match for {0} '{1}' for the specified number and types of arguments.", methodTypeName,
! m.Name));
! }
! }
! }
! return match;
! }
! /// <summary>
! /// Packages arguments into argument list containing parameter array as a last argument.
! /// </summary>
! /// <param name="argValues">Argument vaklues to package.</param>
! /// <param name="argCount">Total number of oarameters.</param>
! /// <param name="elementType">Type of the param array element.</param>
! /// <returns>Packaged arguments.</returns>
! public static object[] PackageParamArray(object[] argValues, int argCount, Type elementType)
! {
! object[] values = new object[argCount];
! int i = 0;
! // copy regular arguments
! while (i < argCount - 1)
! {
! values[i] = argValues[i];
! i++;
! }
! // package param array into last argument
! Array paramArray = Array.CreateInstance(elementType, argValues.Length - i);
! int j = 0;
! while (i < argValues.Length)
! {
! paramArray.SetValue(argValues[i++], j++);
! }
! values[values.Length - 1] = paramArray;
! return values;
! }
! /// <summary>
! /// Convenience method to convert an interface <see cref="System.Type"/>
! /// to a <see cref="System.Type"/> array that contains
! /// all the interfaces inherited and the specified interface.
! /// </summary>
! /// <param name="intf">The interface to convert.</param>
! /// <returns>An array of interface <see cref="System.Type"/>s.</returns>
! /// <exception cref="System.ArgumentException">
! /// If the <see cref="System.Type"/> specified is not an interface.
! /// </exception>
! /// <exception cref="System.ArgumentNullException">
! /// If <paramref name="intf"/> is <see langword="null"/>.
! /// </exception>
! public static Type[] ToInterfaceArray(Type intf)
! {
! AssertUtils.ArgumentNotNull(intf, "intf");
! if (!intf.IsInterface)
! {
! throw new ArgumentException(
! string.Format(CultureInfo.InvariantCulture,
! "[{0}] is a class.",
! intf.FullName));
! }
!
! ArrayList interfaces = new ArrayList(intf.GetInterfaces());
! interfaces.Add(intf);
!
! return (Type[]) interfaces.ToArray(typeof(Type));
! }
/// <summary>
***************
*** 394,410 ****
public static bool PropertyIsIndexer(string propertyName, Type type)
{
! DefaultMemberAttribute[] attribs = (DefaultMemberAttribute[]) type.GetCustomAttributes(typeof(DefaultMemberAttribute), true);
! if (attribs.Length != 0)
! {
! foreach (DefaultMemberAttribute attrib in attribs)
! {
! if (attrib.MemberName.Equals(propertyName))
! {
! return true;
! }
! }
! }
! return false;
! }
/// <summary>
--- 430,447 ----
public static bool PropertyIsIndexer(string propertyName, Type type)
{
! DefaultMemberAttribute[] attribs =
! (DefaultMemberAttribute[]) type.GetCustomAttributes(typeof(DefaultMemberAttribute), true);
! if (attribs.Length != 0)
! {
! foreach (DefaultMemberAttribute attrib in attribs)
! {
! if (attrib.MemberName.Equals(propertyName))
! {
! return true;
! }
! }
! }
! return false;
! }
/// <summary>
***************
*** 485,497 ****
return null;
}
! if (type == typeof (Boolean))
{
return false;
}
! if (type == typeof (DateTime))
{
return DateTime.MinValue;
}
! if (type == typeof (Char))
{
return Char.MinValue;
--- 522,534 ----
return null;
}
! if (type == typeof(Boolean))
{
return false;
}
! if (type == typeof(DateTime))
{
return DateTime.MinValue;
}
! if (type == typeof(Char))
{
return Char.MinValue;
***************
*** 609,613 ****
{
object arg = args[i];
! paramsType[i] = (arg != null) ? args[i].GetType() : typeof (object);
}
return paramsType;
--- 646,650 ----
{
object arg = args[i];
! paramsType[i] = (arg != null) ? args[i].GetType() : typeof(object);
}
return paramsType;
***************
*** 637,658 ****
public static bool HasAtLeastOneMethodWithName(Type type, string name)
{
! if (type == null || StringUtils.IsNullOrEmpty(name))
! {
! return false;
! }
return MethodCountForName(type, name) > 0;
}
! public static int MethodCountForName(Type type, string name)
! {
! AssertUtils.ArgumentNotNull(type, "type", "Type must not be null");
! AssertUtils.ArgumentNotNull(name, "name", "Method name must not be null");
! MemberInfo[] methods = type.FindMembers(
! MemberTypes.Method,
! ReflectionUtils.AllMembersCaseInsensitiveFlags,
! new MemberFilter(ReflectionUtils.MethodNameFilter),
! name);
! return methods.Length;
! }
private static bool MethodNameFilter(MemberInfo member, object criteria)
--- 674,701 ----
public static bool HasAtLeastOneMethodWithName(Type type, string name)
{
! if (type == null || StringUtils.IsNullOrEmpty(name))
! {
! return false;
! }
return MethodCountForName(type, name) > 0;
}
! /// <summary>
! /// Within <paramref name="type"/>, counts the number of overloads for the method with the given (case-insensitive!) <paramref name="name"/>
! /// </summary>
! /// <param name="type">The type to be searched</param>
! /// <param name="name">the name of the method for which overloads shall be counted</param>
! /// <returns>The number of overloads for method <paramref name="name"/> within type <paramref name="type"/></returns>
! public static int MethodCountForName(Type type, string name)
! {
! AssertUtils.ArgumentNotNull(type, "type", "Type must not be null");
! AssertUtils.ArgumentNotNull(name, "name", "Method name must not be null");
! MemberInfo[] methods = type.FindMembers(
! MemberTypes.Method,
! ReflectionUtils.AllMembersCaseInsensitiveFlags,
! new MemberFilter(ReflectionUtils.MethodNameFilter),
! name);
! return methods.Length;
! }
private static bool MethodNameFilter(MemberInfo member, object criteria)
***************
*** 701,705 ****
AssertUtils.ArgumentNotNull(type, "type");
! if (!typeof (Attribute).IsAssignableFrom(type))
{
throw new ArgumentException(
--- 744,748 ----
AssertUtils.ArgumentNotNull(type, "type");
! if (!typeof(Attribute).IsAssignableFrom(type))
{
throw new ArgumentException(
***************
*** 710,777 ****
#endregion
! ConstructorInfo ci = type.GetConstructor(ReflectionUtils.GetTypes(ctorArgs));
! if (ci == null && ctorArgs.Length == 0)
! {
! ci = type.GetConstructors()[0];
! ctorArgs = GetDefaultValues(GetParameterTypes(ci.GetParameters()));
! }
if (sourceAttribute != null)
{
! object defaultAttribute = null;
! try
! {
! defaultAttribute = ci.Invoke(ctorArgs);
! }
! catch { }
!
! IList getSetProps = new ArrayList();
! IList getSetValues = new ArrayList();
! IList readOnlyProps = new ArrayList();
foreach (PropertyInfo pi in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
{
! if (pi.DeclaringType == typeof(Attribute))
! continue;
if (pi.CanRead)
{
! if (pi.CanWrite)
! {
! object propValue = pi.GetValue(sourceAttribute, null);
! if (defaultAttribute != null)
! {
! object defaultValue = pi.GetValue(defaultAttribute, null);
! if ((propValue == null && defaultValue == null) ||
! (propValue != null && propValue.Equals(defaultValue)))
! continue;
! }
! getSetProps.Add(pi);
! getSetValues.Add(propValue);
! }
! else
! {
! readOnlyProps.Add(pi);
! }
}
}
! if (readOnlyProps.Count == 1)
! {
! PropertyInfo pi = readOnlyProps[0] as PropertyInfo;
! ConstructorInfo ciTemp = type.GetConstructor(new Type[1] { pi.PropertyType });
! if (ciTemp != null)
! {
! ci = ciTemp;
! ctorArgs = new object[1] { pi.GetValue(sourceAttribute, null) };
! }
! }
! PropertyInfo[] propertyInfos = new PropertyInfo[getSetProps.Count];
! getSetProps.CopyTo(propertyInfos, 0);
object[] propertyValues = new object[getSetValues.Count];
! getSetValues.CopyTo(propertyValues, 0);
! return new CustomAttributeBuilder(ci, ctorArgs, propertyInfos, propertyValues);
}
else
--- 753,822 ----
#endregion
! ConstructorInfo ci = type.GetConstructor(ReflectionUtils.GetTypes(ctorArgs));
! if (ci == null && ctorArgs.Length == 0)
! {
! ci = type.GetConstructors()[0];
! ctorArgs = GetDefaultValues(GetParameterTypes(ci.GetParameters()));
! }
if (sourceAttribute != null)
{
! object defaultAttribute = null;
! try
! {
! defaultAttribute = ci.Invoke(ctorArgs);
! }
! catch
! {
! }
!
! IList getSetProps = new ArrayList();
! IList getSetValues = new ArrayList();
! IList readOnlyProps = new ArrayList();
foreach (PropertyInfo pi in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
{
! if (pi.DeclaringType == typeof(Attribute))
! continue;
if (pi.CanRead)
{
! if (pi.CanWrite)
! {
! object propValue = pi.GetValue(sourceAttribute, null);
! if (defaultAttribute != null)
! {
! object defaultValue = pi.GetValue(defaultAttribute, null);
! if ((propValue == null && defaultValue == null) ||
! (propValue != null && propValue.Equals(defaultValue)))
! continue;
! }
! getSetProps.Add(pi);
! getSetValues.Add(propValue);
! }
! else
! {
! readOnlyProps.Add(pi);
! }
}
}
! if (readOnlyProps.Count == 1)
! {
! PropertyInfo pi = readOnlyProps[0] as PropertyInfo;
! ConstructorInfo ciTemp = type.GetConstructor(new Type[1] {pi.PropertyType});
! if (ciTemp != null)
! {
! ci = ciTemp;
! ctorArgs = new object[1] {pi.GetValue(sourceAttribute, null)};
! }
! }
! PropertyInfo[] propertyInfos = new PropertyInfo[getSetProps.Count];
! getSetProps.CopyTo(propertyInfos, 0);
object[] propertyValues = new object[getSetValues.Count];
! getSetValues.CopyTo(propertyValues, 0);
! return new CustomAttributeBuilder(ci, ctorArgs, propertyInfos, propertyValues);
}
else
***************
*** 916,921 ****
#if NET_2_0
! private static readonly MethodInfo Exception_InternalPreserveStackTrace =
! typeof(Exception).GetMethod("InternalPreserveStackTrace", BindingFlags.Instance | BindingFlags.NonPublic);
#else
private static readonly FieldInfo Exception_RemoteStackTraceString =
--- 961,966 ----
#if NET_2_0
! private static readonly MethodInfo Exception_InternalPreserveStackTrace =
! typeof(Exception).GetMethod("InternalPreserveStackTrace", BindingFlags.Instance | BindingFlags.NonPublic);
#else
private static readonly FieldInfo Exception_RemoteStackTraceString =
***************
*** 923,990 ****
#endif
! /// <summary>
! /// Unwraps the supplied <see cref="System.Reflection.TargetInvocationException"/>
! /// and returns the inner exception preserving the stack trace.
! /// </summary>
! /// <param name="ex">
! /// The <see cref="System.Reflection.TargetInvocationException"/> to unwrap.
! /// </param>
! /// <returns>The unwrapped exception.</returns>
! public static Exception UnwrapTargetInvocationException(TargetInvocationException ex)
! {
#if NET_2_0
! Exception_InternalPreserveStackTrace.Invoke(ex.InnerException, new Object[] { });
#else
Exception_RemoteStackTraceString.SetValue(ex.InnerException, ex.InnerException.StackTrace + Environment.NewLine);
#endif
! return ex.InnerException;
! }
! /// <summary>
! /// Is the supplied <paramref name="type"/> can be accessed outside the assembly ?
! /// </summary>
! /// <param name="type">The type to check.</param>
! /// <returns>
! /// <see langword="true"/> if the type can be accessed outside the assembly;
! /// Otherwise <see langword="false"/>.
! /// </returns>
! public static bool IsTypeVisible(Type type)
! {
! return IsTypeVisible(type, null);
! }
! /// <summary>
! /// Is the supplied <paramref name="type"/> can be accessed
! /// from the supplied friendly assembly ?
! /// </summary>
! /// <param name="type">The type to check.</param>
! /// <param name="friendlyAssemblyName">The friendly assembly name.</param>
! /// <returns>
! /// <see langword="true"/> if the type can be accessed
! /// from the supplied friendly assembly; Otherwise <see langword="false"/>.
! /// </returns>
! public static bool IsTypeVisible(Type type, string friendlyAssemblyName)
! {
#if NET_2_0
! if (type.IsVisible)
! {
! return true;
! }
! else
! {
! if (!StringUtils.IsNullOrEmpty(friendlyAssemblyName) &&
! (!type.IsNested || type.IsNestedPublic ||
! (!type.IsNestedPrivate && (type.IsNestedAssembly || type.IsNestedFamORAssem))))
! {
! object[] attrs = type.Assembly.GetCustomAttributes(typeof(InternalsVisibleToAttribute), false);
! foreach(InternalsVisibleToAttribute ivta in attrs)
! {
! if (ivta.AssemblyName == friendlyAssemblyName)
! {
! return true;
! }
! }
! }
! }
#else
if (type.IsPublic || (type.IsNestedPublic && type.DeclaringType.IsPublic))
--- 968,1035 ----
#endif
! /// <summary>
! /// Unwraps the supplied <see cref="System.Reflection.TargetInvocationException"/>
! /// and returns the inner exception preserving the stack trace.
! /// </summary>
! /// <param name="ex">
! /// The <see cref="System.Reflection.TargetInvocationException"/> to unwrap.
! /// </param>
! /// <returns>The unwrapped exception.</returns>
! public static Exception UnwrapTargetInvocationException(TargetInvocationException ex)
! {
#if NET_2_0
! Exception_InternalPreserveStackTrace.Invoke(ex.InnerException, new Object[] {});
#else
Exception_RemoteStackTraceString.SetValue(ex.InnerException, ex.InnerException.StackTrace + Environment.NewLine);
#endif
! return ex.InnerException;
! }
! /// <summary>
! /// Is the supplied <paramref name="type"/> can be accessed outside the assembly ?
! /// </summary>
! /// <param name="type">The type to check.</param>
! /// <returns>
! /// <see langword="true"/> if the type can be accessed outside the assembly;
! /// Otherwise <see langword="false"/>.
! /// </returns>
! public static bool IsTypeVisible(Type type)
! {
! return IsTypeVisible(type, null);
! }
! /// <summary>
! /// Is the supplied <paramref name="type"/> can be accessed
! /// from the supplied friendly assembly ?
! /// </summary>
! /// <param name="type">The type to check.</param>
! /// <param name="friendlyAssemblyName">The friendly assembly name.</param>
! /// <returns>
! /// <see langword="true"/> if the type can be accessed
! /// from the supplied friendly assembly; Otherwise <see langword="false"/>.
! /// </returns>
! public static bool IsTypeVisible(Type type, string friendlyAssemblyName)
! {
#if NET_2_0
! if (type.IsVisible)
! {
! return true;
! }
! else
! {
! if (!StringUtils.IsNullOrEmpty(friendlyAssemblyName) &&
! (!type.IsNested || type.IsNestedPublic ||
! (!type.IsNestedPrivate && (type.IsNestedAssembly || type.IsNestedFamORAssem))))
! {
! object[] attrs = type.Assembly.GetCustomAttributes(typeof(InternalsVisibleToAttribute), false);
! foreach (InternalsVisibleToAttribute ivta in attrs)
! {
! if (ivta.AssemblyName == friendlyAssemblyName)
! {
! return true;
! }
! }
! }
! }
#else
if (type.IsPublic || (type.IsNestedPublic && type.DeclaringType.IsPublic))
***************
*** 993,999 ****
}
#endif
! return false;
! }
!
/// <summary>
/// Copies all fields from one object to another.
--- 1038,1044 ----
}
#endif
! return false;
! }
!
/// <summary>
/// Copies all fields from one object to another.
***************
*** 1054,1058 ****
ArrayList fieldList = new ArrayList();
CollectFieldsRecursive(type, fieldList);
! fields = (FieldInfo[]) fieldList.ToArray(typeof (FieldInfo));
s_fieldCache[type] = fields;
}
--- 1099,1103 ----
ArrayList fieldList = new ArrayList();
CollectFieldsRecursive(type, fieldList);
! fields = (FieldInfo[]) fieldList.ToArray(typeof(FieldInfo));
s_fieldCache[type] = fields;
}
***************
*** 1063,1067 ****
private static void CollectFieldsRecursive(Type type, ArrayList fieldList)
{
! if (type == typeof (object)) return;
FieldInfo[] fields = type.GetFields(FIELDBINDINGS);
--- 1108,1112 ----
private static void CollectFieldsRecursive(Type type, ArrayList fieldList)
{
! if (type == typeof(object)) return;
FieldInfo[] fields = type.GetFields(FIELDBINDINGS);
***************
*** 1072,1102 ****
#endregion Field Cache Management for "MemberwiseCopy"
! private static MethodInfo[] GetCandidateMethods(Type type, string methodName, BindingFlags bindingFlags, int argCount)
! {
! MethodInfo[] methods = type.GetMethods(bindingFlags);
! ArrayList matches = new ArrayList();
! foreach (MethodInfo method in methods)
! {
! if (method.Name == methodName)
! {
! ParameterInfo[] parameters = method.GetParameters();
! if (parameters.Length == argCount)
! {
! matches.Add(method);
! }
! else if (parameters.Length > 0)
! {
! ParameterInfo lastParameter = parameters[parameters.Length - 1];
! if (lastParameter.GetCustomAttributes(typeof (ParamArrayAttribute), false).Length > 0)
! {
! matches.Add(method);
! }
! }
! }
! }
! return (MethodInfo[]) matches.ToArray(typeof(MethodInfo));
! }
}
}
\ No newline at end of file
--- 1117,1147 ----
#endregion Field Cache Management for "MemberwiseCopy"
! private static MethodInfo[] GetCandidateMethods(Type type, string methodName, BindingFlags bindingFlags, int argCount)
! {
! MethodInfo[] methods = type.GetMethods(bindingFlags);
! ArrayList matches = new ArrayList();
! foreach (MethodInfo method in methods)
! {
! if (method.Name == methodName)
! {
! ParameterInfo[] parameters = method.GetParameters();
! if (parameters.Length == argCount)
! {
! matches.Add(method);
! }
! else if (parameters.Length > 0)
! {
! ParameterInfo lastParameter = parameters[parameters.Length - 1];
! if (lastParameter.GetCustomAttributes(typeof(ParamArrayAttribute), false).Length > 0)
! {
! matches.Add(method);
! }
! }
! }
! }
! return (MethodInfo[]) matches.ToArray(typeof(MethodInfo));
! }
}
}
\ No newline at end of file
|