[WORKAROUND] Unimplemented form of generic method parameter: 'T'.
Posted: Tue Feb 06, 2018 11:54 pm
When I try to run my app there is an error while generating javascript files:
ERROR: C#/XAML for HTML5: JavaScriptGenerator failed: System.Exception: Error occurred while generating javascript for assembly 'Manufaktura.Controls.XamlForHtml5.MusicShadow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. ---> System.Exception: An error occurred while declaring the type 'Manufaktura.Music.Xml.XAttributeHelper' ---> System.Exception: An error occurred while declaring the type 'Manufaktura.Music.Xml.XHelperBase' ---> System.NotImplementedException: Unimplemented form of generic method parameter: 'T'.
I thought that it might be related to nullable generic parameter:
private static T? ParseValue<T>(string value) where T : struct
but it seems that it's not the case.
Can you tell me which form of generic parameter is unsupported here? This is my class:
public abstract class XHelperBase : IXHelper
{
public XHelperExistsResult Exists()
{
return new XHelperExistsResult(ElementExists(), GetObject(), GetValue());
}
public XHelperHasValueResult<string> HasAnyValue()
{
if (!ElementExists()) return new XHelperHasValueResult<string>(null, null, false);
var value = GetValue();
return !string.IsNullOrWhiteSpace(value) ? new XHelperHasValueResult<string>(value, value, true) : new XHelperHasValueResult<string>(null, null, false);
}
public XHelperHasValueResult<T> HasValue<T>(Dictionary<string, T> values)
{
if (ElementExists() && values.ContainsKey(GetValue())) return new XHelperHasValueResult<T>(values[GetValue()], GetValue(), true);
return new XHelperHasValueResult<T>(default(T), GetValue(), false);
}
public XHelperHasValueResult<T> HasValue<T>() where T : struct
{
if (!ElementExists()) return new XHelperHasValueResult<T>(default(T), null, false);
var unparsedValue = GetValue();
var value = ParseValue<T>(unparsedValue);
return value.HasValue ? new XHelperHasValueResult<T>(value.Value, GetValue(), true) : new XHelperHasValueResult<T>(default(T), GetValue(), false);
}
public XHelperHasValueResult<string> HasValue(string s)
{
if (!ElementExists()) return new XHelperHasValueResult<string>(null, null, false);
var value = GetValue();
return !string.IsNullOrWhiteSpace(value) && s == value ? new XHelperHasValueResult<string>(value, GetValue(), true) : new XHelperHasValueResult<string>(null, GetValue(), false);
}
protected abstract bool ElementExists();
protected abstract string GetValue();
protected abstract object GetObject();
private static T? ParseValue<T>(string value) where T : struct
{
if (typeof(T) == typeof(int)) return UsefulMath.TryParseInt(value) as T?;
if (typeof(T) == typeof(double)) return UsefulMath.TryParse(value) as T?;
if (typeof(T) == typeof(float)) return UsefulMath.TryParse(value) as T?;
if (typeof(T) == typeof(DateTime)) return UsefulMath.TryParseDateTime(value) as T?;
throw new NotImplementedException("Type not supported");
}
public XHelperHasValueResult<T> HasValue<T>(Func<Dictionary<string, T>, Dictionary<string, T>> valueFactory)
{
var dict = valueFactory(new Dictionary<string, T>());
return HasValue(dict);
}
}
Thanks in advance.
ERROR: C#/XAML for HTML5: JavaScriptGenerator failed: System.Exception: Error occurred while generating javascript for assembly 'Manufaktura.Controls.XamlForHtml5.MusicShadow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. ---> System.Exception: An error occurred while declaring the type 'Manufaktura.Music.Xml.XAttributeHelper' ---> System.Exception: An error occurred while declaring the type 'Manufaktura.Music.Xml.XHelperBase' ---> System.NotImplementedException: Unimplemented form of generic method parameter: 'T'.
I thought that it might be related to nullable generic parameter:
private static T? ParseValue<T>(string value) where T : struct
but it seems that it's not the case.
Can you tell me which form of generic parameter is unsupported here? This is my class:
public abstract class XHelperBase : IXHelper
{
public XHelperExistsResult Exists()
{
return new XHelperExistsResult(ElementExists(), GetObject(), GetValue());
}
public XHelperHasValueResult<string> HasAnyValue()
{
if (!ElementExists()) return new XHelperHasValueResult<string>(null, null, false);
var value = GetValue();
return !string.IsNullOrWhiteSpace(value) ? new XHelperHasValueResult<string>(value, value, true) : new XHelperHasValueResult<string>(null, null, false);
}
public XHelperHasValueResult<T> HasValue<T>(Dictionary<string, T> values)
{
if (ElementExists() && values.ContainsKey(GetValue())) return new XHelperHasValueResult<T>(values[GetValue()], GetValue(), true);
return new XHelperHasValueResult<T>(default(T), GetValue(), false);
}
public XHelperHasValueResult<T> HasValue<T>() where T : struct
{
if (!ElementExists()) return new XHelperHasValueResult<T>(default(T), null, false);
var unparsedValue = GetValue();
var value = ParseValue<T>(unparsedValue);
return value.HasValue ? new XHelperHasValueResult<T>(value.Value, GetValue(), true) : new XHelperHasValueResult<T>(default(T), GetValue(), false);
}
public XHelperHasValueResult<string> HasValue(string s)
{
if (!ElementExists()) return new XHelperHasValueResult<string>(null, null, false);
var value = GetValue();
return !string.IsNullOrWhiteSpace(value) && s == value ? new XHelperHasValueResult<string>(value, GetValue(), true) : new XHelperHasValueResult<string>(null, GetValue(), false);
}
protected abstract bool ElementExists();
protected abstract string GetValue();
protected abstract object GetObject();
private static T? ParseValue<T>(string value) where T : struct
{
if (typeof(T) == typeof(int)) return UsefulMath.TryParseInt(value) as T?;
if (typeof(T) == typeof(double)) return UsefulMath.TryParse(value) as T?;
if (typeof(T) == typeof(float)) return UsefulMath.TryParse(value) as T?;
if (typeof(T) == typeof(DateTime)) return UsefulMath.TryParseDateTime(value) as T?;
throw new NotImplementedException("Type not supported");
}
public XHelperHasValueResult<T> HasValue<T>(Func<Dictionary<string, T>, Dictionary<string, T>> valueFactory)
{
var dict = valueFactory(new Dictionary<string, T>());
return HasValue(dict);
}
}
Thanks in advance.