logo
down
shadow

Switch a Task<T> where T is an enum


Switch a Task<T> where T is an enum

Content Index :

Switch a Task<T> where T is an enum
Tag : chash , By : TBG
Date : November 24 2020, 09:00 AM

wish help you to fix your issue I want to get a Task which is returned by a property. ,
Why must it be Task?
ProgressStatus statusAfterAdding = await msg.Add;
switch (statusAfterAdding)
{
    // ...
}

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Can I construct an enum of enums and have a method switch the internal enum based on a variable


Tag : java , By : Lior
Date : March 29 2020, 07:55 AM
With these it helps This is how I ended up solving the issue. Each parameter to the enum represents separate environments, and I just use getter methods to return the correct id per environment.
public enum EnvironmentIds {

USER_MANAGER_CHANGED("e29e902c","28a6e01c", "281916f6"),
USER_ADDED_TO_GROUP("5059020b", "f039fc37", "0e480029"),
USER_CREATED("d9bc6a0c", "f26f0a23", "9261f53a"),
USER_REMOVED_FROM_GROUP("fc30b97c", "15528295", "c08af3b2");


String holdingId;
String productionId;
String stagingId;

EnvironmentIds(String holdingId, String stagingId, String productionId) {
    this.holdingId = holdingId;
    this.stagingId = stagingId;
    this.productionId = productionId;
}

public String getId(String environment) {
    switch(environment) {
        case "holding":
            return getHoldingId();
        case "production":
            return getProductionId();
        case "staging":
            return getStagingId();
        default:
            return null;
    }
}
public String getHoldingId() {return holdingId;}

public String getProductionId() {return productionId;}

public String getStagingId() {return stagingId;}
}

Is there any significant reason to use the ordinal of an enum in a switch case, instead of using the enum?


Tag : java , By : suresh
Date : March 29 2020, 07:55 AM
I wish did fix the issue. There's a good reason against it. The ordinals can change any time without breaking even binary compatibility. The names cannot so change at all.
A better solution would have been to build the returned values into the Enum itself.

Java forcing default return statement from method with enum switch with all enum values covered


Tag : java , By : Dennizzz
Date : March 29 2020, 07:55 AM
Hope that helps
Java forcing default return statement from method with enum switch with all enum values covered... What is the design decision behind such behaviour?
case ...:
     return ...;
default:
     // here in case someone updates the enum and forgets to update this code
     return "Unknown type";
case ...:
     return ...;
default:
     throw new IllegalStateException("unknown enum type found for" + mType);

Is it possible to give out a warning when switch (enum) does not cover every enum value AT COMPILE C#


Tag : chash , By : tanminivan
Date : March 29 2020, 07:55 AM
wish of those help No, it's not possible - at least not out of the box. Switch statements in C# do not have to be exhaustive, and there's no way to require them to be exhaustive.
(Switch expressions in C# 8 will give a warning if they're not exhaustive, but that probably doesn't help you right now.)
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Roslyn.Analyzers" Version="1.0.3.4" PrivateAssets="All" />
  </ItemGroup>

</Project>
using System;

enum Color
{
    Red, Green, Blue
}

sealed class Program
{
    static void Main(string[] args)
    {
        Color c = Color.Red;

        switch (c)
        {
            case Color.Red:
                Console.WriteLine("Red");
                break;
            case Color.Green:
                Console.WriteLine("Green");
                break;
//            case Color.Blue:
//                Console.WriteLine("Blue");
//                break;
            default:
                Console.WriteLine("Undefined color");
                break;
        }
    }
}

Using attributes to cut down on enum to enum mapping and enum/const to action switch statments


Tag : chash , By : nemof
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • What is "ByteArray.uncompress()" in AS3 equivalent to in C#?
  • Getting a specific letter from a string variable for my simple guessing game for clues
  • Send an email with Outlook without a subject --- dialog box issue
  • passing List<MyModel> from my controller in the "WebInterfaceProject" to the processor method in "D
  • How to convert Word document created from template by OpenXML into MemoryStream?
  • How can I make a single slider that changes the color of an object?
  • Remap JSON parameter in c#
  • What is the difference between "this ref" and "ref this" when talking about C# 7.2 ref extension met
  • Convert OpenSSL encryption into native C#
  • Accessing Properties in Razor Pages
  • How to get SOAP element value
  • Projection after Group
  • C# error cannot convert sytem.text.regularexpressions.match to string
  • Issues with Save/Load System in a Text Based Adventure game made with ScriptableObjects in Unity
  • VS2019 MSBuild.exe - ASP .Net MVC project fails to publish when using PublishProfile, but works when using OutDir parame
  • Does <pages validateRequest="false" /> in Web.config still matter?
  • How to send new request to redirect URL with new access token
  • Attempt to invoke virtual method on a null object reference Xamarin LockScreen
  • "The attribute names could not be inferred from bind attribute 'bind-value'" exception in Blazor
  • How to fix ''System.ArgumentException" in c#?
  • C#. Ref returning delegate for ref extension method
  • Swashbuckle Swagger generate an actual guid
  • Trying to make thousands of database calls simultaneously - they stack instead of running concurently
  • run mstest from cmd using testcontainer
  • How to make M:N (many-to-many) relationship where both M and N are the same entities?
  • Consume COM DLL from multiple clients
  • Convert json string response representing UCHAR array to Byte array
  • Why does this LinqPad program produce different results on the second run?
  • ServiceStack how to use MaxLoginAttempts feature
  • What does "late-bound access to the destination object" mean?
  • How to load appsettings.json inside a Static class based on deploy environment so that I can use in other class librarie
  • dynamically add images to view
  • Are static extension methods on User object safe?
  • Process thousands of database calls simultaneously
  • Trying to decrypt a string with public key(not private) using bouncycastle in .net
  • How to retrieve the name of an usb device
  • Query many-to-many related data using Entity Framework Core
  • ASP.NET MVC : how to find the view from a controller?
  • Inconsistent behaviour using Entity Framework for ASP.NET MVC app vs windows service
  • AutoFixture Customize vs Build
  • How to change textbox location at the click of a mouse in live mode?
  • How can I deserialize a XML file without defining the parent node?
  • asp.net core how decrease class coupling
  • ASP.NET Core Razor Pages Routing With parameters
  • String Escaping With $ Interpolation and @ Encoding
  • ConfigurationManager in ASP.NET WebAPI tested with HttpServer
  • Top down shooting in Unity 2D don't work as I want it to
  • Use own redirectUri when the Authentication expires
  • Using "foreach" in string array c#
  • "Object reference not set to an instance of an object" for create multiply models on one view
  • Get data passed trought pushAsync
  • Selector expression dynamic on IQueryable
  • Logut with SignInManager not calling method
  • Exit event handler with MessageBox OK button
  • Can not load view from Custom Renderer Xamarin Forms
  • Looking for a .Net ORM
  • Cost of SortedDictionary.Count
  • All possible combinations of n items selected randomly from a set of x items (algorithm)
  • Displaying process percentage on DOS screen
  • C# Importing Large Volume of Data from CSV to Database
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com