Commit ab19c049 authored by Martin Finkel's avatar Martin Finkel

Set to use C# 7.3 and use readonly structs

parent 01be5bef
......@@ -7,7 +7,7 @@
<TargetFrameworks>netstandard2.0;netstandard1.1;MonoAndroid81;Xamarin.iOS10;Xamarin.Mac20;net40</TargetFrameworks>
<RootNamespace>LibVLCSharp</RootNamespace>
<NeutralLanguage>en</NeutralLanguage>
<LangVersion>default</LangVersion>
<LangVersion>7.3</LangVersion>
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' ">true</GeneratePackageOnBuild>
<GenerateDocumentationFile Condition=" '$(Configuration)' == 'Release' ">true</GenerateDocumentationFile>
<UseFullSemVerForNuGet>false</UseFullSemVerForNuGet>
......
using System;
using LibVLCSharp.Shared.Helpers;
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
......
......@@ -9,34 +9,28 @@ namespace LibVLCSharp.Shared.Helpers
/// </summary>
/// <param name="s">AudioOutputDescriptionStructure from interop</param>
/// <returns>public AudioOutputDescription to be consumed by the user</returns>
internal static AudioOutputDescription Build(this AudioOutputDescriptionStructure s) => new AudioOutputDescription
{
Name = Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(s.Name) as string,
Description = Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(s.Description) as string,
};
internal static AudioOutputDescription Build(this AudioOutputDescriptionStructure s) =>
new AudioOutputDescription(Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(s.Name) as string,
Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(s.Description) as string);
/// <summary>
/// Helper method that creates a managed type from the internal interop structure.
/// </summary>
/// <param name="s">AudioOutputDeviceStructure from interop</param>
/// <returns>public AudioOutputDevice to be consumed by the user</returns>
internal static AudioOutputDevice Build(this AudioOutputDeviceStructure s) => new AudioOutputDevice
{
DeviceIdentifier = Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(s.DeviceIdentifier) as string,
Description = Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(s.Description) as string,
};
internal static AudioOutputDevice Build(this AudioOutputDeviceStructure s) =>
new AudioOutputDevice(Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(s.DeviceIdentifier) as string,
Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(s.Description) as string);
/// <summary>
/// Helper method that creates a managed type from the internal interop structure.
/// </summary>
/// <param name="s">ModuleDescriptionStructure from interop</param>
/// <returns>public ModuleDescription to be consumed by the user</returns>
internal static ModuleDescription Build(this ModuleDescriptionStructure s) => new ModuleDescription
{
Name = Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(s.Name) as string,
ShortName = Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(s.ShortName) as string,
LongName = Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(s.LongName) as string,
Help = Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(s.Help) as string
};
internal static ModuleDescription Build(this ModuleDescriptionStructure s) =>
new ModuleDescription(Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(s.Name) as string,
Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(s.ShortName) as string,
Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(s.LongName) as string,
Utf8StringMarshaler.GetInstance().MarshalNativeToManaged(s.Help) as string);
}
}
\ No newline at end of file
......@@ -489,7 +489,8 @@ namespace LibVLCSharp.Shared
/// <para>explicit audio device.</para>
/// <para>LibVLC 2.1.0 or later.</para>
/// </remarks>
public AudioOutputDevice[] AudioOutputDevices(string audioOutputName) => MarshalUtils.Retrieve(() => Native.LibVLCAudioOutputDeviceListGet(NativeReference, Utf8StringMarshaler.GetInstance().MarshalManagedToNative(audioOutputName)),
public AudioOutputDevice[] AudioOutputDevices(string audioOutputName) =>
MarshalUtils.Retrieve(() => Native.LibVLCAudioOutputDeviceListGet(NativeReference, Utf8StringMarshaler.GetInstance().MarshalManagedToNative(audioOutputName)),
MarshalUtils.PtrToStructure<AudioOutputDeviceStructure>,
s => s.Build(),
device => device.Next,
......
......@@ -2,22 +2,39 @@
using System.Runtime.InteropServices;
namespace LibVLCSharp.Shared.Structures
{
{
[StructLayout(LayoutKind.Sequential)]
internal struct AudioOutputDescriptionStructure
internal readonly struct AudioOutputDescriptionStructure
{
public IntPtr Name;
public IntPtr Description;
public IntPtr NextAudioOutputDescription;
public readonly IntPtr Name;
public readonly IntPtr Description;
public readonly IntPtr NextAudioOutputDescription;
}
/// <summary>
/// Description for audio output.
/// </summary>
public class AudioOutputDescription
public readonly struct AudioOutputDescription
{
public string Name;
public string Description;
/// <summary>
/// AudioOutputDescription default constructor
/// </summary>
/// <param name="name">Audio output name</param>
/// <param name="description">Audio output description</param>
internal AudioOutputDescription(string name, string description)
{
Name = name;
Description = description;
}
/// <summary>
/// Audio output name
/// </summary>
public readonly string Name;
/// <summary>
/// Audio output description
/// </summary>
public readonly string Description;
}
}
}
\ No newline at end of file
......@@ -4,26 +4,37 @@ using System.Runtime.InteropServices;
namespace LibVLCSharp.Shared.Structures
{
[StructLayout(LayoutKind.Sequential)]
internal struct AudioOutputDeviceStructure
internal readonly struct AudioOutputDeviceStructure
{
public IntPtr Next;
public IntPtr DeviceIdentifier;
public IntPtr Description;
public readonly IntPtr Next;
public readonly IntPtr DeviceIdentifier;
public readonly IntPtr Description;
}
/// <summary>
/// Description for audio output device
/// </summary>
public class AudioOutputDevice
public readonly struct AudioOutputDevice
{
/// <summary>
/// AudioOutputDevice default constructor
/// </summary>
/// <param name="deviceIdentifier">Device identifier string</param>
/// <param name="description">User-friendly device description</param>
internal AudioOutputDevice(string deviceIdentifier, string description)
{
DeviceIdentifier = deviceIdentifier;
Description = description;
}
/// <summary>
/// Device identifier string.
/// </summary>
public string DeviceIdentifier;
public readonly string DeviceIdentifier;
/// <summary>
/// User-friendly device description.
/// </summary>
public string Description;
public readonly string Description;
}
}
\ No newline at end of file
......@@ -4,23 +4,53 @@ using System.Runtime.InteropServices;
namespace LibVLCSharp.Shared.Structures
{
[StructLayout(LayoutKind.Sequential)]
internal struct ModuleDescriptionStructure
internal readonly struct ModuleDescriptionStructure
{
internal IntPtr Name;
internal IntPtr ShortName;
internal IntPtr LongName;
internal IntPtr Help;
internal IntPtr Next;
internal readonly IntPtr Name;
internal readonly IntPtr ShortName;
internal readonly IntPtr LongName;
internal readonly IntPtr Help;
internal readonly IntPtr Next;
}
/// <summary>
/// Description of a module.
/// </summary>
public class ModuleDescription
public readonly struct ModuleDescription
{
public string Name;
public string ShortName;
public string LongName;
public string Help;
/// <summary>
/// Default constructor for ModuleDescription
/// </summary>
/// <param name="name">Module name</param>
/// <param name="shortName">Module short name</param>
/// <param name="longName">Module long name</param>
/// <param name="help">Module help</param>
internal ModuleDescription(string name, string shortName, string longName, string help)
{
Name = name;
ShortName = shortName;
LongName = longName;
Help = help;
}
/// <summary>
/// Module name
/// </summary>
public readonly string Name;
/// <summary>
/// Module short name
/// </summary>
public readonly string ShortName;
/// <summary>
/// Module long name
/// </summary>
public readonly string LongName;
/// <summary>
/// Module help
/// </summary>
public readonly string Help;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment