.Net Runtime Library for Delphi
How to: Use AsXXXX methods

The AsXXXX methods represent the conversion from the type to it inherited interfaces or classes. The XXXX represent the name of the inherited class or interfaces in c#. Example AsStream method is available to any interfaces if the class the interface represent or wrapped in c# inherits from Stream class. So in this case, XXXX represent the Stream, the base class.

program FromDerivedToBaseConv; {$APPTYPE CONSOLE} {$R *.res} uses CNClrLib.EnumTypes, CNClrLib.Core; var fileStream: _FileStream; stream: _Stream; idisposable: _IDisposable; begin fileStream := CoFileStream.CreateInstance('C:\Temp\Test.txt', fmOpenOrCreate); // The fileStream in C# inherits from the Stream Class, so to implicitly cast to the // base class Stream use the AsXXXX method on the FileStream interface. stream := fileStream.AsStream; //Convert to IDisposable interface which FileStream inherit from idisposable := fileStream.AsIDisposable; //To Convert back to FileStream Interface use the Wrap method fileStream := CoFileStream.Wrap(stream); end.