Note that there are some explanatory texts on larger screens.

plurals
  1. POImplicit conversion without assignment?
    text
    copied!<p><strong>Preserved question - see Edit at the bottom</strong><br/> I'm working on a small functional library, basically to provide some readability by hiding basic cyclomatic complexities. The provider is called <code>Select&lt;T&gt;</code> (with a helper factory called <code>Select</code>), and usage is similar to</p> <pre><code>public Guid? GetPropertyId(...) { return Select .Either(TryToGetTheId(...)) .Or(TrySomethingElseToGetTheId(...)) .Or(IGuessWeCanTryThisTooIfWeReallyHaveTo(...)) //etc. ; } </code></pre> <p>and the library will take care of the short circuiting, etc. I also added an implicit conversion from <code>Select&lt;T&gt;</code> to <code>T</code>, so I can write </p> <pre><code>public Guid GetPropertyId(...) { ServiceResult result = Select .Either(TryToGetTheId(...)) .Or(TrySomethingElseToGetTheId(...)); return result.Id; } </code></pre> <p>What I'd really like to be able to do is an implicit conversion to T without assignment:</p> <pre><code>public Guid GetPropertyId(...) { return //This is the part that I want to be implicitly cast to a ServiceResult Select .Either(TryToGetTheId(...)) .Or(TrySomethingElseToGetTheId(...)) //Then I want to access this property on the result of the cast .Id; } </code></pre> <p>However, the specified syntax doesn't work - I have to either assign it to a variable, or explicitly cast it. Is there a way to get an implicit cast inline?</p> <p><strong>EDIT</strong></p> <p>What I want to do is this:</p> <pre><code>class Foo { public int Fuh { get; set; } } class Bar { private Foo _foo; public static implicit operator Foo (Bar bar) { return bar._foo; } } //What I have to do Foo bar = GetABar(); DoSomethingWith(bar.Fuh); //What I want to do DoSomethingWith(GetABar().Fuh); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload