Ambiguous Generic restriction T:class vs T:struct
Posted
by Maslow
on Stack Overflow
See other posts from Stack Overflow
or by Maslow
Published on 2010-04-27T03:02:36Z
Indexed on
2010/04/27
3:03 UTC
Read the original article
Hit count: 336
This code generates a compiler error that the member is already defined with the same parameter types.
private T GetProperty<T>(Func<Settings, T> GetFunc) where T:class
{
try
{
return GetFunc(Properties.Settings.Default);
}
catch (Exception exception)
{
SettingReadException(this,exception);
return null;
}
}
private TNullable? GetProperty<TNullable>(Func<Settings, TNullable> GetFunc) where TNullable : struct
{
try
{
return GetFunc(Properties.Settings.Default);
}
catch (Exception ex)
{
SettingReadException(this, ex);
return new Nullable<TNullable>();
}
}
Is there a clean work around?
© Stack Overflow or respective owner