Skip to content

Commit

Permalink
Fix TypeInitializationException in SymbolStartAnalysisContextWrapper (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-strecker-sonarsource authored Mar 28, 2024
1 parent 1fb5367 commit 6f9fee8
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ static SymbolStartAnalysisContextWrapper()
// receiverParameter => ((symbolStartAnalysisContextType)receiverParameter)."propertyName"
Func<object, TProperty> CreatePropertyAccessor<TProperty>(string propertyName)
{
if (symbolStartAnalysisContextType == null)
{
return static _ => default;
}
var receiverParameter = Parameter(typeof(object));
return Lambda<Func<object, TProperty>>(
Property(Convert(receiverParameter, symbolStartAnalysisContextType), propertyName),
Expand All @@ -86,6 +90,10 @@ Func<object, TProperty> CreatePropertyAccessor<TProperty>(string propertyName)
// ((symbolStartAnalysisContextType)receiverParameter)."registrationMethodName"<typeArguments>(registerActionParameter)
Action<object, Action<TContext>> CreateRegistrationMethod<TContext>(string registrationMethodName, params Type[] typeArguments)
{
if (symbolStartAnalysisContextType == null)
{
return static (_, _) => { };
}
var receiverParameter = Parameter(typeof(object));
var registerActionParameter = Parameter(typeof(Action<TContext>));
return Lambda<Action<object, Action<TContext>>>(
Expand All @@ -98,6 +106,10 @@ Action<object, Action<TContext>> CreateRegistrationMethod<TContext>(string regis
// ((symbolStartAnalysisContextType)receiverParameter)."registrationMethodName"<typeArguments>(registerActionParameter, additionalParameter)
Action<object, Action<TContext>, TParameter> CreateRegistrationMethodWithAdditionalParameter<TContext, TParameter>(string registrationMethodName, params Type[] typeArguments)
{
if (symbolStartAnalysisContextType == null)
{
return static (_, _, _) => { };
}
var receiverParameter = Parameter(typeof(object));
var registerActionParameter = Parameter(typeof(Action<TContext>));
var additionalParameter = Parameter(typeof(TParameter));
Expand Down

0 comments on commit 6f9fee8

Please sign in to comment.