Apparatus.AOT.Reflection icon indicating copy to clipboard operation
Apparatus.AOT.Reflection copied to clipboard

Can you add GetMethods()

Open vesnx opened this issue 7 months ago • 0 comments

I was wondering if you could have a generic way to solve:

public Frame(StackFrame? frame)
{
    _methodBase = frame.GetMethod();
}


When you look at the inplementation you can see that it's not available in IOT

///

/// Returns the method the frame is executing /// [RequiresUnreferencedCode("Metadata for the method might be incomplete or removed")] public virtual MethodBase? GetMethod() { return _method; }

       ```

if (exception is not null && exception.GetType().Name.Equals("SqlException", StringComparison.OrdinalIgnoreCase)) { #pragma warning disable IL2075 // 'this' argument does not satisfy 'DynamicallyAccessedMembersAttribute' in call to target method. The return value of the source method does not have matching annotations. var props = GetExceptionTypeWithProperties(exception).GetProperties(BindingFlags.Public | BindingFlags.Instance); #pragma warning restore IL2075 // 'this' argument does not satisfy 'DynamicallyAccessedMembersAttribute' in call to target method. The return value of the source method does not have matching annotations.

            foreach (var property in props)
            {
                //sqlException
                switch (property.Name)
                {
                    case "Procedure":
                        _sqlProcedureName = property.GetValue(exception) as string;
                        break;

                    case "LineNumber":
                        if (property.GetValue(exception) is int iSqlLineNumber)
                            _sqlLineNumber = iSqlLineNumber;
                        break;

                    case "Number":
                        if (property.GetValue(exception) is int iSqlErrorNumber)
                            _sqlErrorNumber = iSqlErrorNumber;
                        break;

                    case "Server":
                        _sqlServer = property.GetValue(exception) as string;
                        break;

                    case "Source":
                        _tSql = property.GetValue(exception) as string;
                        break;

                    case "ErrorCode":
                        if (property.GetValue(exception) is int iSqlErrorCode)
                            _sqlErrorCode = iSqlErrorCode;
                        break;
                }
            }
        }
            
SqlException comes from more than one namespace and in my lib I do not reference any of them but I am still interested in sending crash diagnostics without having to write a special resolver for it.


vesnx avatar Nov 17 '23 09:11 vesnx