Forum Xamarin.iOS

How to cast objects from binding library?

I'm using BindingLibrary for player and I've following interfaces in ApiDefinition file:


// @protocol MediaRepresentationProtocol
[BaseType(typeof(NSObject))]
[Protocol]
public interface MediaRepresentationProtocol
{
// @required @property (readonly, nonatomic) NSInteger representationIndex
[Export("representationIndex")]
nint RepresentationIndex { get; }

// @required @property (readonly, nonatomic) MediaStream * parentStream;
[Export("parentStream")]
MediaStream ParentStream { get; }

// @required @property (readonly, nonatomic) NSUInteger fourCC;
[Export("fourCC")]
nuint FourCC { get; }

// @required @property (readonly, nonatomic) NSUInteger bitRate;
[Export("bitRate")]
nuint BitRate { get; }

// @required @property (getter = isEnabled, nonatomic) BOOL enabled;
[Export("enabled")]
bool Enabled { [Bind("isEnabled")] get; set; }

}

// @public interface AudioInfo : NSObject
[BaseType(typeof(NSObject))]
public interface AudioInfo : MediaRepresentationProtocol
{
// @property (readonly, nonatomic) NSUInteger samplingRate;
[Export("samplingRate")]
nuint SamplingRate { get; }

// @property (readonly, nonatomic) NSUInteger channels;
[Export("channels")]
nuint Channels { get; }

// @property (readonly, nonatomic) NSUInteger bitPerSample;
[Export("bitPerSample")]
nuint BitPerSample { get; }

// @property (readonly, nonatomic) NSUInteger packetSize;
[Export("packetSize")]
nuint PacketSize { get; }

// @property (readonly, nonatomic) NSUInteger audioTag;
[Export("audioTag")]
nuint AudioTag { get; }

// @property (readonly, nonatomic) NSString * language;
[Export("language")]
string Language { get; }

}

Now in my C# code, I'm using native method which returns array of MediaRepresentationProtocol objects. Actually in this case, there are really AudioInfo objects (I see this in debugger). How Can I cast MediaRepresenationProtocol to AudioInfo in case if the second one is not deriving (in C#) from the first one?
Output objects both implements IMediaRepresentationProtocol interface which is generated in Xamarin.

Sign In or Register to comment.