public void GetAttributeInstance_ReturnsAttribute_FromParameterInfo() { MethodInfo methodInfo = GetType().GetMethod("TheTestMethod", BindingFlags.NonPublic | BindingFlags.Instance); ParameterInfo parameterInfo = methodInfo.GetParameters()[0]; SoapParameterAttribute actual = ReflectionExtensions.GetAttributeInstance <SoapParameterAttribute>(parameterInfo); Assert.IsNotNull(actual); }
/// <summary>Gets an appropriate SOAP-related attribute for the specified class member or method parameter. </summary> /// <param name="reflectionObject">A class member or method parameter.</param> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Infrastructure" /> /// </PermissionSet> public static SoapAttribute GetCachedSoapAttribute(object reflectionObject) { object syncRoot = InternalRemotingServices._soapAttributes.SyncRoot; SoapAttribute result; lock (syncRoot) { SoapAttribute soapAttribute = InternalRemotingServices._soapAttributes[reflectionObject] as SoapAttribute; if (soapAttribute != null) { result = soapAttribute; } else { ICustomAttributeProvider customAttributeProvider = (ICustomAttributeProvider)reflectionObject; object[] customAttributes = customAttributeProvider.GetCustomAttributes(typeof(SoapAttribute), true); if (customAttributes.Length > 0) { soapAttribute = (SoapAttribute)customAttributes[0]; } else if (reflectionObject is Type) { soapAttribute = new SoapTypeAttribute(); } else if (reflectionObject is FieldInfo) { soapAttribute = new SoapFieldAttribute(); } else if (reflectionObject is MethodBase) { soapAttribute = new SoapMethodAttribute(); } else if (reflectionObject is ParameterInfo) { soapAttribute = new SoapParameterAttribute(); } soapAttribute.SetReflectionObject(reflectionObject); InternalRemotingServices._soapAttributes[reflectionObject] = soapAttribute; result = soapAttribute; } } return(result); }
public static SoapAttribute GetCachedSoapAttribute(object reflectionObject) { lock (_soapAttributes.SyncRoot) { SoapAttribute att = _soapAttributes [reflectionObject] as SoapAttribute; if (att != null) { return(att); } ICustomAttributeProvider ap = (ICustomAttributeProvider)reflectionObject; object[] atts = ap.GetCustomAttributes(typeof(SoapAttribute), true); if (atts.Length > 0) { att = (SoapAttribute)atts[0]; } else { if (reflectionObject is Type) { att = new SoapTypeAttribute(); } else if (reflectionObject is FieldInfo) { att = new SoapFieldAttribute(); } else if (reflectionObject is MethodBase) { att = new SoapMethodAttribute(); } else if (reflectionObject is ParameterInfo) { att = new SoapParameterAttribute(); } } att.SetReflectionObject(reflectionObject); _soapAttributes [reflectionObject] = att; return(att); } }
// Get the cached SOAP attribute data for an object. public static SoapAttribute GetCachedSoapAttribute(Object reflectionObject) { // Validate the paramter to ensure that it is a // legitimate reflection object. if (reflectionObject == null) { return(null); } else if (!(reflectionObject is MemberInfo) && !(reflectionObject is ParameterInfo)) { return(null); } lock (typeof(InternalRemotingServices)) { Object attr; Object[] attrs; // Look for a cached value from last time. if (attributeHash == null) { attributeHash = new Hashtable(); } else if ((attr = attributeHash[reflectionObject]) != null) { return(attr as SoapAttribute); } // Get the attribute information from the type. if (reflectionObject is Type) { attrs = ((Type)reflectionObject).GetCustomAttributes (typeof(SoapTypeAttribute), true); if (attrs == null || attrs.Length < 1) { attr = new SoapTypeAttribute(); } else { attr = attrs[0]; } } else if (reflectionObject is MethodBase) { attrs = ((MethodBase)reflectionObject) .GetCustomAttributes (typeof(SoapMethodAttribute), true); if (attrs == null || attrs.Length < 1) { attr = new SoapMethodAttribute(); } else { attr = attrs[0]; } } else if (reflectionObject is FieldInfo) { attrs = ((FieldInfo)reflectionObject) .GetCustomAttributes (typeof(SoapFieldAttribute), true); if (attrs == null || attrs.Length < 1) { attr = new SoapFieldAttribute(); } else { attr = attrs[0]; } } else if (reflectionObject is ParameterInfo) { attrs = ((ParameterInfo)reflectionObject) .GetCustomAttributes (typeof(SoapParameterAttribute), true); if (attrs == null || attrs.Length < 1) { attr = new SoapParameterAttribute(); } else { attr = attrs[0]; } } else { attrs = ((MemberInfo)reflectionObject) .GetCustomAttributes(typeof(SoapAttribute), true); if (attrs == null || attrs.Length < 1) { attr = new SoapAttribute(); } else { attr = attrs[0]; } } ((SoapAttribute)attr).SetReflectInfo(reflectionObject); return((SoapAttribute)attr); } }