简体   繁体   中英

Extension method must be defined in a non-generic static class Error public static

I have problem in my project .

I have this code:

public static TitleInfoPacket GenerateTitInfo(this ICharacterDAO visualEntity)
{
    var visibleTitle = visualEntity.Titles.FirstOrDefault(s => s.Visible)?.TitleType;
    var effectiveTitle = visualEntity.Titles.FirstOrDefault(s => s.Active)?.TitleType;

    return new TitleInfoPacket
        {
            VisualId = visualEntity.VisualId,
            EffectiveTitle = effectiveTitle ?? 0,
            VisualType = visualEntity.VisualType,
            VisibleTitle = visibleTitle ?? 0,
        };
}

public TitlePacket GenerateTitle(this ICharacterDAO visualEntity)
{
    var data = visualEntity.Titles.Select(s => new TitleSubPacket
        {
            TitleId = (short)(s.TitleType - 9300),
            TitleStatus = (byte)((s.Visible ? 2 : 0) + (s.Active ? 4 : 0) + 1)
        }).ToList();

    return new TitlePacket
           {
                Data = data.Any() ? data : null
           };
}

and I get an error:

Extension method must be defined in a non-generic static class

I tried everything and still have this problem can someone explain me what I'm doing bad or show me something that i miss thank you anyway guys for any reply

observe that I placed the static keyword

public static class MyExtensionsClass {

   // extension methods here
    public static TitleInfoPacket GenerateTitInfo(this ICharacterDAO 

 visualEntity)
    {
      var visibleTitle = visualEntity.Titles.FirstOrDefault(s => s.Visible)?.TitleType;
      var effectiveTitle = visualEntity.Titles.FirstOrDefault(s => s.Active)?.TitleType;
return new TitleInfoPacket
    {
        VisualId = visualEntity.VisualId,
        EffectiveTitle = effectiveTitle ?? 0,
        VisualType = visualEntity.VisualType,
        VisibleTitle = visibleTitle ?? 0,
    };
  }
}

Hope This helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM