ExtensionsConvertionsAsT Method (Object) |
Namespace: Cauldron
public interface IFoo { string Name {get;} string Description {get;} } public class Foo : IFoo { public string Name {get; set;} public string Description {get; set;} } public class Bar : BarBase { private IFoo internalFoo; private Bar(IFoo foo) { this.internalFoo = foo; } public void DoSomeStuff() { } public void DoSomeOtherStuff() { } public static implicit operator Bar(Foo value) => new Boo(value); public static implicit operator Foo(Bar value) => value.internalFoo; } public class SomeOtherClass { public IFoo GetFooFromSomewhere(string fooId) => new Foo { Name = "A Foo", Description = "This is the foo you are looking for." }; }
var bar = someOtherClassInstance.GetFooFromSomewhere("fooThatINeed").As<Bar>();