public void Dispose() { Name = null; m_Flags = 0; m_Field = null; m_Property = null; m_Method = null; ArrayUtils.Dispose(ref m_Parameters); ArrayUtils.Dispose(ref m_MethodParams); ArrayUtils.Dispose(ref m_DefaultParams); m_RequiredParamCount = 0; }
protected virtual bool ProcessField(FieldInfo inField) { if (!StringParser.CanConvertTo(inField.FieldType)) { return(false); } m_Field = inField; m_Flags |= InvocationFlags.Field; if (inField.IsStatic) { m_Flags |= InvocationFlags.Static; } return(true); }
[MethodImpl(MethodImplOptions.NoInlining)] // move lazy invocation flags population out of the hot path private static InvocationFlags ComputeAndUpdateInvocationFlags(ConstructorInfo constructorInfo, ref InvocationFlags flagsToUpdate) { InvocationFlags invocationFlags = InvocationFlags.IsConstructor; // this is a given Type?declaringType = constructorInfo.DeclaringType; if (declaringType == typeof(void) || declaringType != null && declaringType.ContainsGenericParameters || // Enclosing type has unbound generics (constructorInfo.CallingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs // Managed varargs ) { invocationFlags |= InvocationFlags.NoInvoke; } else if (constructorInfo.IsStatic) { invocationFlags |= InvocationFlags.RunClassConstructor | InvocationFlags.NoConstructorInvoke; } else if (declaringType != null && declaringType.IsAbstract) { invocationFlags |= InvocationFlags.NoConstructorInvoke; } else { // Check for byref-like types if (declaringType != null && declaringType.IsByRefLike) { invocationFlags |= InvocationFlags.ContainsStackPointers; } // Check for attempt to create a delegate class. if (typeof(Delegate).IsAssignableFrom(constructorInfo.DeclaringType)) { invocationFlags |= InvocationFlags.IsDelegateConstructor; } } invocationFlags |= InvocationFlags.Initialized; flagsToUpdate = invocationFlags; // accesses are guaranteed atomic return(invocationFlags); }
protected virtual bool ProcessMethod(MethodInfo inMethod) { if (inMethod.ReturnType != typeof(void)) { return(false); } m_Parameters = inMethod.GetParameters(); if (m_Parameters.Length > 0) { m_DefaultParams = new object[m_Parameters.Length]; for (int i = 0; i < m_Parameters.Length; ++i) { ParameterInfo info = m_Parameters[i]; Type paramType = info.ParameterType; if (!StringParser.CanConvertTo(paramType)) { m_Parameters = null; m_DefaultParams = null; return(false); } if ((info.Attributes & ParameterAttributes.HasDefault) != 0) { m_DefaultParams[i] = info.DefaultValue; } else { ++m_RequiredParamCount; } } } m_Method = inMethod; m_Flags |= InvocationFlags.Method; m_MethodParams = new object[m_Parameters.Length]; return(true); }
[MethodImpl(MethodImplOptions.NoInlining)] // move lazy invocation flags population out of the hot path private static InvocationFlags ComputeAndUpdateInvocationFlags(MethodInfo methodInfo, ref InvocationFlags flagsToUpdate) { InvocationFlags invocationFlags = InvocationFlags.Unknown; Type?declaringType = methodInfo.DeclaringType; if (methodInfo.ContainsGenericParameters || // Method has unbound generics IsDisallowedByRefType(methodInfo.ReturnType) || // Return type is an invalid by-ref (i.e., by-ref-like or void*) (methodInfo.CallingConvention & CallingConventions.VarArgs) == CallingConventions.VarArgs // Managed varargs ) { invocationFlags = InvocationFlags.NoInvoke; } else { if (declaringType != null) { if (declaringType.ContainsGenericParameters) // Enclosing type has unbound generics { invocationFlags = InvocationFlags.NoInvoke; } else if (declaringType.IsByRefLike) // Check for byref-like types { invocationFlags |= InvocationFlags.ContainsStackPointers; } } if (methodInfo.ReturnType.IsByRefLike) // Check for byref-like types for return { invocationFlags |= InvocationFlags.ContainsStackPointers; } } invocationFlags |= InvocationFlags.Initialized; flagsToUpdate = invocationFlags; // accesses are guaranteed atomic return(invocationFlags);
protected virtual bool ProcessProperty(PropertyInfo inProperty) { if (!StringParser.CanConvertTo(inProperty.PropertyType)) { return(false); } MethodInfo setter = inProperty.SetMethod; if (setter == null) { return(false); } m_Flags |= InvocationFlags.Property; if (setter.IsStatic) { m_Flags |= InvocationFlags.Static; } m_Method = setter; m_MethodParams = new object[1]; return(true); }
/// <summary> /// Convenience method so the parameter to HasFlag is typed to InvocationFlags rather than just Enum. /// </summary> public bool HasFlag(InvocationFlags flag) { return(Flags.HasFlag(flag)); }