Added StyleCop with a ruleset. Formatted code according to rules.

This commit is contained in:
Max Mommersteeg 2018-12-24 11:11:29 +01:00
parent 7176335166
commit e9c9b6041b
76 changed files with 896 additions and 612 deletions

115
StyleCop.ruleset Normal file
View file

@ -0,0 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Rules for Qml.Net" Description="Code analysis rules for Qml.Net" ToolsVersion="15.0">
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rule Id="CA1001" Action="Warning" />
<Rule Id="CA1009" Action="Warning" />
<Rule Id="CA1016" Action="Warning" />
<Rule Id="CA1033" Action="Warning" />
<Rule Id="CA1049" Action="Warning" />
<Rule Id="CA1060" Action="Warning" />
<Rule Id="CA1061" Action="Warning" />
<Rule Id="CA1063" Action="Warning" />
<Rule Id="CA1065" Action="Warning" />
<Rule Id="CA1301" Action="Warning" />
<Rule Id="CA1400" Action="Warning" />
<Rule Id="CA1401" Action="Warning" />
<Rule Id="CA1403" Action="Warning" />
<Rule Id="CA1404" Action="Warning" />
<Rule Id="CA1405" Action="Warning" />
<Rule Id="CA1410" Action="Warning" />
<Rule Id="CA1415" Action="Warning" />
<Rule Id="CA1821" Action="Warning" />
<Rule Id="CA1900" Action="Warning" />
<Rule Id="CA1901" Action="Warning" />
<Rule Id="CA2002" Action="Warning" />
<Rule Id="CA2100" Action="Warning" />
<Rule Id="CA2101" Action="Warning" />
<Rule Id="CA2108" Action="Warning" />
<Rule Id="CA2111" Action="Warning" />
<Rule Id="CA2112" Action="Warning" />
<Rule Id="CA2114" Action="Warning" />
<Rule Id="CA2116" Action="Warning" />
<Rule Id="CA2117" Action="Warning" />
<Rule Id="CA2122" Action="Warning" />
<Rule Id="CA2123" Action="Warning" />
<Rule Id="CA2124" Action="Warning" />
<Rule Id="CA2126" Action="Warning" />
<Rule Id="CA2131" Action="Warning" />
<Rule Id="CA2132" Action="Warning" />
<Rule Id="CA2133" Action="Warning" />
<Rule Id="CA2134" Action="Warning" />
<Rule Id="CA2137" Action="Warning" />
<Rule Id="CA2138" Action="Warning" />
<Rule Id="CA2140" Action="Warning" />
<Rule Id="CA2141" Action="Warning" />
<Rule Id="CA2146" Action="Warning" />
<Rule Id="CA2147" Action="Warning" />
<Rule Id="CA2149" Action="Warning" />
<Rule Id="CA2200" Action="Warning" />
<Rule Id="CA2202" Action="Warning" />
<Rule Id="CA2207" Action="Warning" />
<Rule Id="CA2212" Action="Warning" />
<Rule Id="CA2213" Action="Warning" />
<Rule Id="CA2214" Action="Warning" />
<Rule Id="CA2216" Action="Warning" />
<Rule Id="CA2220" Action="Warning" />
<Rule Id="CA2229" Action="Warning" />
<Rule Id="CA2231" Action="Warning" />
<Rule Id="CA2232" Action="Warning" />
<Rule Id="CA2235" Action="Warning" />
<Rule Id="CA2236" Action="Warning" />
<Rule Id="CA2237" Action="Warning" />
<Rule Id="CA2238" Action="Warning" />
<Rule Id="CA2240" Action="Warning" />
<Rule Id="CA2241" Action="Warning" />
<Rule Id="CA2242" Action="Warning" />
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA1008" Action="None" />
<Rule Id="SA1009" Action="None" />
<Rule Id="SA1101" Action="None" />
<Rule Id="SA1108" Action="None" />
<Rule Id="SA1118" Action="None" />
<Rule Id="SA1121" Action="None" />
<Rule Id="SA1122" Action="None" />
<Rule Id="SA1129" Action="None" />
<Rule Id="SA1119" Action="None" />
<Rule Id="SA1124" Action="None" />
<Rule Id="SA1200" Action="None" />
<Rule Id="SA1201" Action="None" />
<Rule Id="SA1202" Action="None" />
<Rule Id="SA1204" Action="None" />
<Rule Id="SA1214" Action="None" />
<Rule Id="SA1300" Action="None" />
<Rule Id="SA1304" Action="None" />
<Rule Id="SA1306" Action="None" />
<Rule Id="SA1307" Action="None" />
<Rule Id="SA1309" Action="None" />
<Rule Id="SA1312" Action="None" />
<Rule Id="SA1400" Action="None" />
<Rule Id="SA1401" Action="None" />
<Rule Id="SA1402" Action="None" />
<Rule Id="SA1501" Action="None" />
<Rule Id="SA1503" Action="None" />
<Rule Id="SA1513" Action="None" />
<Rule Id="SA1515" Action="None" />
<Rule Id="SA1520" Action="None" />
<Rule Id="SA1611" Action="None" />
<Rule Id="SA1615" Action="None" />
<Rule Id="SA1633" Action="None" />
<Rule Id="SA1634" Action="None" />
<Rule Id="SA1635" Action="None" />
<Rule Id="SA1636" Action="None" />
<Rule Id="SA1637" Action="None" />
<Rule Id="SA1638" Action="None" />
<Rule Id="SA1640" Action="None" />
<Rule Id="SA1641" Action="None" />
<Rule Id="SA1642" Action="None" />
<Rule Id="SA1643" Action="None" />
<Rule Id="SA1648" Action="None" />
<Rule Id="SA1649" Action="None" />
<Rule Id="SA1652" Action="None" />
<Rule Id="IDE1006" Action="None" />
<Rule Id="SX1101" Action="Warning" />
</Rules>
</RuleSet>

View file

@ -4,7 +4,7 @@ using BenchmarkDotNet.Jobs;
namespace Qml.Net.Benchmarks
{
public class Config: ManualConfig
public class Config : ManualConfig
{
public Config()
{

View file

@ -2,6 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<CodeAnalysisRuleSet>../../../StyleCop.ruleset</CodeAnalysisRuleSet>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
@ -9,5 +10,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.11.3" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

View file

@ -22,7 +22,7 @@ namespace Qml.Net.Benchmarks
[IterationSetup]
public void Setup()
{
_guiApplication = new QGuiApplication(new[]{"-platform", "offscreen"});
_guiApplication = new QGuiApplication(new[] { "-platform", "offscreen" });
_qmlApplicationEngine = new QQmlApplicationEngine();
}
@ -86,7 +86,6 @@ namespace Qml.Net.Benchmarks
public class InnerType
{
}
}
}

View file

@ -2,6 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<CodeAnalysisRuleSet>../../../StyleCop.ruleset</CodeAnalysisRuleSet>
<LangVersion>7.1</LangVersion>
<IsPackable>false</IsPackable>
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
@ -15,6 +16,10 @@
<None Include="Program.Tests.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.core" Version="2.4.1" />
<PackageReference Include="xunit.runner.utility" Version="2.4.1" />
</ItemGroup>

View file

@ -1,12 +1,9 @@
using Qml.Net.Internal;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Xunit;
using FluentAssertions;
using System.Threading;
using FluentAssertions;
using Qml.Net.Internal;
using Xunit;
namespace Qml.Net.Tests.Internal
{
@ -21,7 +18,7 @@ namespace Qml.Net.Tests.Internal
{
ObjectTagger tagger = new ObjectTagger(10);
List<object> handledObjects = new List<object>();
for(int i=0; i < 9; i++)
for (int i = 0; i < 9; i++)
{
var obj = new object();
tagger.GetOrCreateTag(obj);
@ -42,15 +39,16 @@ namespace Qml.Net.Tests.Internal
tagger.GetOrCreateTag(obj);
handledObjects.Add(obj);
}
//Ids are all used
// Ids are all used.
handledObjects.Clear();
GC.Collect(2, GCCollectionMode.Forced, true);
Thread.Sleep(100);
//the next one is the already prepared next id
// The next one is the already prepared next id.
var obj10 = new object();
var tag10 = tagger.GetOrCreateTag(obj10);
tag10.Should().Be(10ul);
//the next after that will overflow
// The next after that will overflow.
var obj1 = new object();
var tag1 = tagger.GetOrCreateTag(obj1);
tag1.Should().Be(1ul);

View file

@ -10,7 +10,7 @@ namespace Qml.Net.Tests
public MockTypeCreator(params Tuple<Type, object>[] instances)
{
_instances = new Dictionary<Type, object>();
foreach(var tuple in instances)
foreach (var tuple in instances)
{
_instances[tuple.Item1] = tuple.Item2;
}

View file

@ -1,12 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<CodeAnalysisRuleSet>../../../StyleCop.ruleset</CodeAnalysisRuleSet>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="5.5.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />

View file

@ -18,17 +18,15 @@ namespace Qml.Net.Tests.Qml
public virtual Task<string> TestAsyncWithResult()
{
return Task.FromResult("");
return Task.FromResult(string.Empty);
}
public virtual void TestMethod()
{
}
public virtual void TestMethodWithArg(string arg)
{
}
}

View file

@ -31,6 +31,7 @@ namespace Qml.Net.Tests.Qml
{
private readonly QGuiApplication _coreApplication;
protected readonly QQmlApplicationEngine qmlApplicationEngine;
protected MockTypeCreator TypeCreator { get; private set; }
readonly List<Type> _registeredTypes = new List<Type>();
@ -38,7 +39,7 @@ namespace Qml.Net.Tests.Qml
protected AbstractBaseQmlTests()
{
_coreApplication = new QGuiApplication(new []{ "-platform", "offscreen" });
_coreApplication = new QGuiApplication(new[] { "-platform", "offscreen" });
qmlApplicationEngine = new QQmlApplicationEngine();
TypeCreator = new MockTypeCreator();
Net.TypeCreator.Current = TypeCreator;
@ -61,10 +62,11 @@ namespace Qml.Net.Tests.Qml
{
CancellationTokenSource cts = new CancellationTokenSource();
CancellationToken ct = cts.Token;
Task.Factory.StartNew(() =>
Task.Factory.StartNew(
() =>
{
Thread.Sleep(timeoutMs);
if(!ct.IsCancellationRequested)
if (!ct.IsCancellationRequested)
{
_coreApplication.Exit(-1);
}
@ -77,8 +79,10 @@ namespace Qml.Net.Tests.Qml
protected void RunQmlTest(string instanceId, string componentOnCompletedCode)
{
NetTestHelper.RunQml(qmlApplicationEngine,
string.Format(@"
NetTestHelper.RunQml(
qmlApplicationEngine,
string.Format(
@"
import QtQuick 2.0
import tests 1.0
{0} {{
@ -104,7 +108,8 @@ namespace Qml.Net.Tests.Qml
}
}
public abstract class BaseQmlTests<T> : AbstractBaseQmlTests<T> where T:class
public abstract class BaseQmlTests<T> : AbstractBaseQmlTests<T>
where T : class
{
protected readonly Mock<T> Mock;
@ -116,7 +121,8 @@ namespace Qml.Net.Tests.Qml
}
}
public abstract class BaseQmlTestsWithInstance<T> : AbstractBaseQmlTests<T> where T : class, new()
public abstract class BaseQmlTestsWithInstance<T> : AbstractBaseQmlTests<T>
where T : class, new()
{
protected readonly T Instance;
@ -128,7 +134,8 @@ namespace Qml.Net.Tests.Qml
}
}
public abstract class BaseQmlMvvmTestsWithInstance<T> : AbstractBaseQmlTests<T> where T : class, new()
public abstract class BaseQmlMvvmTestsWithInstance<T> : AbstractBaseQmlTests<T>
where T : class, new()
{
protected readonly T Instance;

View file

@ -14,12 +14,10 @@ namespace Qml.Net.Tests.Qml
public virtual void MethodParameter(bool value)
{
}
public virtual void MethodParameterNullable(bool? value)
{
}
public virtual bool MethodReturn()

View file

@ -14,12 +14,10 @@ namespace Qml.Net.Tests.Qml
public virtual void MethodParameter(char value)
{
}
public virtual void MethodParameterNullable(char? value)
{
}
public virtual char MethodReturn()

View file

@ -15,12 +15,10 @@ namespace Qml.Net.Tests.Qml
public virtual void Method(DateTimeOffset value)
{
}
public virtual void MethodNullable(DateTimeOffset? value)
{
}
}
@ -28,7 +26,7 @@ namespace Qml.Net.Tests.Qml
public void Can_read_write_property()
{
var value = DateTimeOffset.Now;
// This trims some percision off of the milliseconds, makes the comparison accurate.
// This trims some precision off of the milliseconds, makes the comparison accurate.
value = new DateTimeOffset(value.Year, value.Month, value.Day, value.Hour, value.Minute, value.Second, value.Millisecond, value.Offset);
Mock.SetupGet(x => x.Property).Returns(value);
Mock.SetupSet(x => x.Property = value);

View file

@ -1,5 +1,4 @@
using Qml.Net.Internal.Qml;
using System;
using System;
using Moq;
using Xunit;

View file

@ -12,7 +12,6 @@ namespace Qml.Net.Tests.Qml
public virtual void MethodParameter(double value)
{
}
public virtual double MethodReturn()

View file

@ -12,7 +12,6 @@ namespace Qml.Net.Tests.Qml
public virtual void MethodParameter(int value)
{
}
public virtual int MethodReturn()

View file

@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using FluentAssertions;
using FluentAssertions.Common;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Moq;
using Qml.Net.Internal.Qml;
using Xunit;
using Qml.Net.Extensions;
using Xunit;
namespace Qml.Net.Tests.Qml
{
@ -16,22 +13,18 @@ namespace Qml.Net.Tests.Qml
{
public virtual void Method(dynamic value)
{
}
public virtual void Method(dynamic value1, dynamic value2)
{
}
public virtual void MethodWithoutParams()
{
}
public virtual void MethodWithParameters(string param1, int param2)
{
}
public virtual void CallMethodWithJsValue(INetJsValue value, INetJsValue method)
@ -259,11 +252,11 @@ namespace Qml.Net.Tests.Qml
Mock.Verify(x => x.Method(It.IsAny<INetJsValue>()), Times.Exactly(1));
Mock.Verify(x => x.GetTestObject(), Times.Exactly(1));
((object) result.nonExistant).Should().BeNull();
((int) result.test1).Should().Be(34);
((string) result.test2).Should().Be("test3");
((object)result.nonExistant).Should().BeNull();
((int)result.test1).Should().Be(34);
((string)result.test2).Should().Be("test3");
((object)result.test3).Should().BeSameAs(testObject);
((string) result.test4.test5).Should().Be("test5");
((string)result.test4.test5).Should().Be("test5");
}
[Fact]
@ -303,11 +296,11 @@ namespace Qml.Net.Tests.Qml
Mock.Verify(x => x.Method(It.IsAny<INetJsValue>()), Times.Exactly(1));
Mock.Verify(x => x.Method(It.IsAny<INetJsValue>(), It.IsAny<INetJsValue>()), Times.Exactly(1));
Mock.Verify(x => x.GetTestObject(), Times.Exactly(1));
((object) result).Should().NotBeNull();
((int) result.dest1).Should().Be(123);
((string) result.dest2).Should().Be("value");
((object) result.dest3).Should().BeSameAs(testObject);
((object) result.dest4).Should().BeAssignableTo<INetJsValue>();
((object)result).Should().NotBeNull();
((int)result.dest1).Should().Be(123);
((string)result.dest2).Should().Be("value");
((object)result.dest3).Should().BeSameAs(testObject);
((object)result.dest4).Should().BeAssignableTo<INetJsValue>();
}
[Fact]
@ -316,7 +309,7 @@ namespace Qml.Net.Tests.Qml
List<string> result = null;
Mock.Setup(x => x.Method(It.IsAny<INetJsValue>())).Callback(new Action<dynamic>(param =>
{
result = ((INetJsValue) param).AsList<string>();
result = ((INetJsValue)param).AsList<string>();
}));
RunQmlTest(
@ -341,7 +334,7 @@ namespace Qml.Net.Tests.Qml
List<int> result = null;
Mock.Setup(x => x.Method(It.IsAny<INetJsValue>())).Callback(new Action<dynamic>(param =>
{
result = ((INetJsValue) param).AsList<int>();
result = ((INetJsValue)param).AsList<int>();
}));
RunQmlTest(

View file

@ -6,7 +6,6 @@ using Xunit;
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
namespace Qml.Net.Tests.Qml
{
public class LifetimeTests : BaseQmlTestsWithInstance<LifetimeTests.NetInteropTestQml>
@ -187,7 +186,7 @@ namespace Qml.Net.Tests.Qml
Assert.True(Instance.TestResult);
}
[Fact()]
[Fact]
public void Can_handle_instance_deref_of_all_refs_in_qml_and_net()
{
qmlApplicationEngine.LoadData(@"

View file

@ -18,7 +18,6 @@ namespace Qml.Net.Tests.Qml
public virtual void Test(object param)
{
}
}
@ -43,7 +42,8 @@ namespace Qml.Net.Tests.Qml
Mock.Setup(x => x.GetNetObjectList()).Returns(list);
Mock.Setup(x => x.Test(It.IsAny<object>())).Callback(new Action<object>(o => result.Add((TestNetObject)o)));
NetTestHelper.RunQml(qmlApplicationEngine,
NetTestHelper.RunQml(
qmlApplicationEngine,
@"
import QtQuick 2.0
import tests 1.0
@ -67,7 +67,7 @@ namespace Qml.Net.Tests.Qml
}
");
Mock.Verify(x => x.GetNetObjectList(),Times.Once);
Mock.Verify(x => x.GetNetObjectList(), Times.Once);
Mock.Verify(x => x.Test(It.IsAny<object>()), Times.Exactly(3));
list.Count.Should().Be(result.Count);
list[0].Prop.Should().Be(result[0].Prop);

View file

@ -1,8 +1,7 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Xunit;
using FluentAssertions;
using Qml.Net.Internal.Qml;
using Xunit;
namespace Qml.Net.Tests.Qml
{
@ -47,13 +46,15 @@ namespace Qml.Net.Tests.Qml
{
public event PropertyChangedEventHandler PropertyChanged;
private string _stringProperty = "";
private string _stringProperty = string.Empty;
public string StringProperty
{
get
{
return _stringProperty;
}
set
{
if (!Equals(value, _stringProperty))
@ -65,6 +66,7 @@ namespace Qml.Net.Tests.Qml
}
private int _intProperty;
public int IntProperty
{
get => _intProperty;
@ -79,6 +81,7 @@ namespace Qml.Net.Tests.Qml
}
private int _customIntProperty;
[NotifySignal("customIntPropertyChangedSignal")]
public int CustomIntProperty
{
@ -86,6 +89,7 @@ namespace Qml.Net.Tests.Qml
{
return _customIntProperty;
}
set
{
if (!Equals(value, _customIntProperty))
@ -97,6 +101,7 @@ namespace Qml.Net.Tests.Qml
}
private int _customMvvmStyleIntProperty;
[NotifySignal]
public int CustomMvvmStyleIntProperty
{
@ -104,6 +109,7 @@ namespace Qml.Net.Tests.Qml
{
return _customMvvmStyleIntProperty;
}
set
{
if (!Equals(value, _customMvvmStyleIntProperty))
@ -115,6 +121,7 @@ namespace Qml.Net.Tests.Qml
}
private int _notifyOnlyIntProperty;
[NotifySignal]
public int NotifyOnlyIntProperty
{
@ -122,6 +129,7 @@ namespace Qml.Net.Tests.Qml
{
return _notifyOnlyIntProperty;
}
set
{
if (!Equals(value, _notifyOnlyIntProperty))
@ -133,6 +141,7 @@ namespace Qml.Net.Tests.Qml
}
private int _customNotifyOnlyIntProperty;
[NotifySignal("customNotifyIntPropertyChangedSignal")]
public int CustomNotifyOnlyIntProperty
{
@ -140,6 +149,7 @@ namespace Qml.Net.Tests.Qml
{
return _customNotifyOnlyIntProperty;
}
set
{
if (!Equals(value, _customNotifyOnlyIntProperty))

View file

@ -10,7 +10,6 @@ namespace Qml.Net.Tests.Qml
{
public class TestObject
{
}
[Fact]

View file

@ -15,25 +15,20 @@ namespace Qml.Net.Tests.Qml
public virtual void TestMethodParameter(ObjectTestsQmlReturnType parameter)
{
}
public virtual void Overload()
{
}
public virtual void Overload(string param)
{
}
public object TestObjectProperty { get; set; }
public virtual void TestObjectPropertyTest(string result)
{
}
}
@ -41,7 +36,6 @@ namespace Qml.Net.Tests.Qml
{
public virtual void TestMethod()
{
}
}

View file

@ -23,7 +23,7 @@ namespace Qml.Net.Tests.Qml
var o = new QQmlApplicationEngineQml();
o.Guid = Guid.NewGuid();
qmlApplicationEngine.SetContextProperty(propName, o);
((QQmlApplicationEngineQml) qmlApplicationEngine.GetContextProperty(propName)).Guid.Should().Be(o.Guid);
((QQmlApplicationEngineQml)qmlApplicationEngine.GetContextProperty(propName)).Guid.Should().Be(o.Guid);
}
}
}

View file

@ -19,17 +19,14 @@ namespace Qml.Net.Tests.Qml
public virtual void MethodWithArgs(string arg1, int arg2)
{
}
public virtual void TestMethod()
{
}
public virtual void TestMethodWithArgs(string arg1, int arg2)
{
}
private string _someStringPropertyValue = "";
@ -38,7 +35,8 @@ namespace Qml.Net.Tests.Qml
public string SomeStringProperty
{
get => _someStringPropertyValue;
set {
set
{
if (_someStringPropertyValue == value)
return;
_someStringPropertyValue = value;
@ -52,7 +50,8 @@ namespace Qml.Net.Tests.Qml
public int SomeIntProperty
{
get => _someIntPropertyValue;
set {
set
{
if (_someIntPropertyValue == value)
return;
_someIntPropertyValue = value;
@ -64,8 +63,13 @@ namespace Qml.Net.Tests.Qml
public bool SomeBoolProperty
{
get => _someBoolPropertyValue;
set {
get
{
return _someBoolPropertyValue;
}
set
{
if (_someBoolPropertyValue == value)
return;
_someBoolPropertyValue = value;
@ -85,7 +89,6 @@ namespace Qml.Net.Tests.Qml
[Signal("testSignalWithNetArg", NetVariantType.Object)]
public class SignalObject
{
}
[Fact]
@ -262,7 +265,7 @@ namespace Qml.Net.Tests.Qml
string message2 = null;
o.AttachToSignal("testSignalWithArgs1", new Action<string, int>((m, _) => { message1 = m; }));
o.AttachToSignal("testSignalWithArgs2", new Action<string,int>((m, _) => { message2 = m; }));
o.AttachToSignal("testSignalWithArgs2", new Action<string, int>((m, _) => { message2 = m; }));
o.ActivateSignal("testSignalWithArgs1", "message1", 3);
message1.Should().Be("message1");

View file

@ -15,7 +15,8 @@ namespace Qml.Net.Tests.Qml
[Fact]
public void Can_register_singleton()
{
NetTestHelper.RunQml(qmlApplicationEngine,
NetTestHelper.RunQml(
qmlApplicationEngine,
@"
import QtQuick 2.0
import tests 1.0

View file

@ -12,7 +12,6 @@ namespace Qml.Net.Tests.Qml
public virtual void MethodParameter(string value)
{
}
public virtual string MethodReturn()

View file

@ -12,7 +12,6 @@ namespace Qml.Net.Tests.Qml
public virtual void MethodParameter(uint value)
{
}
public virtual uint MethodReturn()

View file

@ -55,7 +55,7 @@ namespace Qml.Net.Tests.Types
{
var type = NetTypeManager.GetTypeInfo<TestObject>();
using(var instance = new NetReference(Interop.Callbacks.InstantiateType(type.Handle), false))
using (var instance = new NetReference(Interop.Callbacks.InstantiateType(type.Handle), false))
{
instance.Instance.Should().NotBeNull();
instance.Instance.Should().BeOfType<TestObject>();

View file

@ -8,7 +8,6 @@ namespace Qml.Net.Tests.Types
{
class TestObject
{
}
[Fact]

View file

@ -12,7 +12,6 @@ namespace Qml.Net.Tests.Types
{
public void TestMethod()
{
}
public int TestProperty { get; set; }
@ -35,7 +34,6 @@ namespace Qml.Net.Tests.Types
{
public void TestMethod(int parameter1, TestType1 parameter2)
{
}
}
@ -88,7 +86,6 @@ namespace Qml.Net.Tests.Types
{
public void TestMethod()
{
}
}
@ -105,7 +102,6 @@ namespace Qml.Net.Tests.Types
{
public void ThisIsMethodName()
{
}
}
@ -142,7 +138,6 @@ namespace Qml.Net.Tests.Types
[Signal("testSignal", NetVariantType.DateTime, NetVariantType.Object)]
public class TestType7
{
}
[Fact]
@ -222,7 +217,6 @@ namespace Qml.Net.Tests.Types
public class InnerType
{
}
}
@ -246,12 +240,10 @@ namespace Qml.Net.Tests.Types
{
public void LocalMethod()
{
}
public static void StaticMethod()
{
}
}

View file

@ -59,7 +59,6 @@ namespace Qml.Net
protected virtual void DisposeManaged()
{
}
protected abstract void DisposeUnmanaged(IntPtr ptr);

View file

@ -1,7 +1,7 @@
using Qml.Net.Internal.Types;
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Qml.Net.Internal.Types;
namespace Qml.Net.Internal.Behaviors
{
@ -18,6 +18,7 @@ namespace Qml.Net.Internal.Behaviors
// ReSharper disable once MemberCanBePrivate.Local
// ReSharper disable once UnusedAutoPropertyAccessor.Local
public string Name { get; }
public string SignalName { get; }
}
@ -54,7 +55,7 @@ namespace Qml.Net.Internal.Behaviors
}
if (!(instance is INotifyPropertyChanged castedInstance))
{
//invalid type
// Invalid type.
return;
}
castedInstance.PropertyChanged += PropertyChangedHandler;
@ -68,7 +69,7 @@ namespace Qml.Net.Internal.Behaviors
}
if (!(instance is INotifyPropertyChanged castedInstance))
{
//invalid type
// Invalid type.
return;
}
@ -81,7 +82,8 @@ namespace Qml.Net.Internal.Behaviors
{
return;
}
//fire signal according to the property that got changed
// Fire signal according to the property that got changed.
var type = sender.GetType();
if (TypeInfos.TryGetValue(type, out var typeInfo))
{
@ -118,30 +120,32 @@ namespace Qml.Net.Internal.Behaviors
var property = netTypeInfo.GetProperty(i);
if (property.NotifySignal != null)
{
//in this case some other behavior or the user has already set up a notify signal for this property
//we don't want to destroy that
// In this case some other behavior or the user has already set up a notify signal for this property.
// We don't want to destroy that.
mvvmTypeInfo.AddPropertyInfo(property.Name, property.NotifySignal.Name);
continue;
}
var signalName = CalculateSignalNameFromPropertyName(property.Name);
mvvmTypeInfo.AddPropertyInfo(property.Name, signalName);
//check if this signal already has been registered
for(var signalIndex = 0; signalIndex < netTypeInfo.SignalCount; signalIndex++)
// Check if this signal already has been registered.
for (var signalIndex = 0; signalIndex < netTypeInfo.SignalCount; signalIndex++)
{
var signal = netTypeInfo.GetSignal(signalIndex);
if(string.Equals(signalName, signal.Name))
if (string.Equals(signalName, signal.Name))
{
existingSignalIndex = signalIndex;
break;
}
}
if(existingSignalIndex.HasValue)
if (existingSignalIndex.HasValue)
{
//signal for this property is already existent but not registered (we check that above)
// Signal for this property is already existent but not registered (we check that above).
property.NotifySignal = netTypeInfo.GetSignal(existingSignalIndex.Value);
continue;
}
//create a new signal and link it to the property
// Create a new signal and link it to the property.
var notifySignalInfo = new NetSignalInfo(netTypeInfo, signalName);
netTypeInfo.AddSignal(notifySignalInfo);
property.NotifySignal = notifySignalInfo;

View file

@ -1,6 +1,4 @@
using Qml.Net.Internal.Qml;
using Qml.Net.Internal.Types;
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
@ -8,6 +6,8 @@ using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.CSharp.RuntimeBinder;
using Qml.Net.Internal.Qml;
using Qml.Net.Internal.Types;
namespace Qml.Net.Internal
{
@ -24,11 +24,15 @@ namespace Qml.Net.Internal
using (var type = new NetTypeInfo(t))
{
var typeInfo = Type.GetType(type.FullTypeName);
if (typeInfo == null) throw new InvalidOperationException();
if (typeInfo == null)
{
throw new InvalidOperationException();
}
type.ClassName = typeInfo.Name;
type.PrefVariantType = GetPrefVariantType(typeInfo);
// All the methods/properties/signals are later populated when needed.
}
}
@ -44,7 +48,10 @@ namespace Qml.Net.Internal
}
// Don't grab properties and methods for system-level types.
if (Helpers.IsPrimitive(typeInfo)) return;
if (Helpers.IsPrimitive(typeInfo))
{
return;
}
if (typeInfo.IsArray)
{
@ -58,7 +65,7 @@ namespace Qml.Net.Internal
}
else if (typeInfo.IsGenericType)
{
if(typeof(IList<>).IsAssignableFrom(typeInfo.GetGenericTypeDefinition()))
if (typeof(IList<>).IsAssignableFrom(typeInfo.GetGenericTypeDefinition()))
{
type.IsList = true;
}
@ -129,6 +136,7 @@ namespace Qml.Net.Internal
if (signals.ContainsKey(name))
{
notifySignal = signals[name];
// Make sure the signal we are referencing has no parameters.
if (notifySignal.ParameterCount != 0)
{
@ -174,7 +182,7 @@ namespace Qml.Net.Internal
public void ReleaseNetDelegateGCHandle(IntPtr handle)
{
NetDelegate.ReleaseGCHandle(((GCHandle)handle));
NetDelegate.ReleaseGCHandle((GCHandle)handle);
}
public IntPtr InstantiateType(IntPtr type)
@ -183,9 +191,9 @@ namespace Qml.Net.Internal
{
var typeName = Utilities.ContainerToString(Interop.NetTypeInfo.GetFullTypeName(type));
var typeInfo = Type.GetType(typeName);
if(typeInfo == null) throw new InvalidOperationException($"Invalid type {typeName}");
if (typeInfo == null) throw new InvalidOperationException($"Invalid type {typeName}");
var netReference = NetReference.CreateForObject(TypeCreator.Create(typeInfo));
// When .NET collects this NetReference, we don't want it to delete this
// handle. Ownership has been passed to the caller.
return Interop.NetReference.Clone(netReference.Handle);
@ -198,24 +206,23 @@ namespace Qml.Net.Internal
public void ReadProperty(IntPtr p, IntPtr t, IntPtr ip, IntPtr r)
{
using(var property = new NetPropertyInfo(p))
using(var target = new NetReference(t))
using(var indexParameter = ip != IntPtr.Zero ? new NetVariant(ip) : null)
using(var result = new NetVariant(r))
using (var property = new NetPropertyInfo(p))
using (var target = new NetReference(t))
using (var indexParameter = ip != IntPtr.Zero ? new NetVariant(ip) : null)
using (var result = new NetVariant(r))
{
var o = target.Instance;
var propertInfo = o.GetType()
.GetProperty(property.Name, BindingFlags.Instance | BindingFlags.Public);
if(propertInfo == null)
if (propertInfo == null)
throw new InvalidOperationException($"Invalid property {property.Name}");
if (indexParameter != null)
{
object indexParameterValue = null;
Helpers.Unpackvalue(ref indexParameterValue, indexParameter);
Helpers.PackValue(propertInfo.GetValue(o, new[]{indexParameterValue}), result);
Helpers.PackValue(propertInfo.GetValue(o, new[] { indexParameterValue }), result);
}
else
{
@ -246,7 +253,7 @@ namespace Qml.Net.Internal
{
object indexParameterValue = null;
Helpers.Unpackvalue(ref indexParameterValue, indexParameter);
propertInfo.SetValue(o, newValue, new[]{indexParameterValue});
propertInfo.SetValue(o, newValue, new[] { indexParameterValue });
}
else
{
@ -297,6 +304,7 @@ namespace Qml.Net.Internal
// Get all the parameters for the method we are invoking.
var parameterTypes = method.GetAllParameters().Select(x => x.Type.FullTypeName).ToList();
// And find a good method to invoke.
foreach (var potentialMethod in methods)
{
@ -384,8 +392,8 @@ namespace Qml.Net.Internal
public async Task AwaitTask(IntPtr t, IntPtr sc, IntPtr fc)
{
using (var target = new NetReference(t))
using(var successCallback = new NetJsValue(sc))
using(var failureCallback = fc != IntPtr.Zero ? new NetJsValue(fc) : null)
using (var successCallback = new NetJsValue(sc))
using (var failureCallback = fc != IntPtr.Zero ? new NetJsValue(fc) : null)
{
var taskObject = target.Instance;
if (taskObject is Task task)

View file

@ -19,10 +19,12 @@ namespace Qml.Net.Internal
{
return false;
}
if (type.Name == "Array")
{
return false;
}
return true;
}
@ -40,26 +42,26 @@ namespace Qml.Net.Internal
var type = source.GetType();
if (type == typeof(bool))
destination.Bool = (bool)source;
else if(type == typeof(char))
else if (type == typeof(char))
destination.Char = (char)source;
else if(type == typeof(float))
else if (type == typeof(float))
destination.Float = (float)source;
else if(type == typeof(double))
else if (type == typeof(double))
destination.Double = (double)source;
else if (type == typeof(int))
destination.Int = (int)source;
else if(type == typeof(uint))
else if (type == typeof(uint))
destination.UInt = (uint)source;
else if (type == typeof(long))
destination.Long = (long)source;
else if(type == typeof(ulong))
else if (type == typeof(ulong))
destination.ULong = (ulong)source;
else if (type == typeof(string))
destination.String = (string)source;
else if (type == typeof(DateTimeOffset))
destination.DateTime = ((DateTimeOffset) source).DateTime;
destination.DateTime = ((DateTimeOffset)source).DateTime;
else if (typeof(INetJsValue).IsAssignableFrom(type))
destination.JsValue = ((NetJsValue.NetJsValueDynamic) source).JsValue;
destination.JsValue = ((NetJsValue.NetJsValueDynamic)source).JsValue;
else
{
destination.Instance = NetReference.CreateForObject(source);

View file

@ -1,7 +1,5 @@
using Qml.Net.Internal.Types;
using System;
using System.Collections.Generic;
using System.Text;
using System;
using Qml.Net.Internal.Types;
namespace Qml.Net.Internal
{

View file

@ -78,7 +78,8 @@ namespace Qml.Net.Internal
// the folder to the path. The reason is because QML plugins aren't
// in the same directory and have trouble finding dependencies
// that are within our lib folder.
Environment.SetEnvironmentVariable("PATH",
Environment.SetEnvironmentVariable(
"PATH",
Environment.GetEnvironmentVariable("PATH") + $";{libDirectory}");
}
}
@ -112,11 +113,11 @@ namespace Qml.Net.Internal
Utilities = LoadInteropType<UtilitiesInterop>(library, loader);
QtWebEngine = LoadInteropType<QtWebEngineInterop>(library, loader);
if(!string.IsNullOrEmpty(pluginsDirectory))
if (!string.IsNullOrEmpty(pluginsDirectory))
{
Qt.PutEnv("QT_PLUGIN_PATH", pluginsDirectory);
}
if(!string.IsNullOrEmpty(qmlDirectory))
if (!string.IsNullOrEmpty(qmlDirectory))
{
Qt.PutEnv("QML2_IMPORT_PATH", qmlDirectory);
}
@ -163,7 +164,8 @@ namespace Qml.Net.Internal
public static QtWebEngineInterop QtWebEngine { get; }
private static T LoadInteropType<T>(IntPtr library, NetNativeLibLoader.Loader.IPlatformLoader loader) where T:new()
private static T LoadInteropType<T>(IntPtr library, NetNativeLibLoader.Loader.IPlatformLoader loader)
where T : new()
{
var result = new T();
LoadDelegates(result, library, loader);

View file

@ -8,6 +8,7 @@ namespace Qml.Net.Internal
internal static class InteropBehaviors
{
private static List<IQmlInteropBehavior> _QmlInteropBehaviors = new List<IQmlInteropBehavior>();
public static IEnumerable<IQmlInteropBehavior> QmlInteropBehaviors => _QmlInteropBehaviors;
private static IEnumerable<IQmlInteropBehavior> GetApplicableInteropBehaviors(Type forType)
@ -19,10 +20,10 @@ namespace Qml.Net.Internal
/// <summary>
/// Registers an additional Qml Interop behavior. This behavior only gets applied to types and instances created or registered after this behavior registration
/// </summary>
/// <param name="behavior"></param>
/// <param name="behavior">IQmlInteropBehavior</param>
public static void RegisterQmlInteropBehavior(IQmlInteropBehavior behavior, bool addIfTypeAlreadyExists = false)
{
if(!addIfTypeAlreadyExists && _QmlInteropBehaviors.Any(ib => ib.GetType() == behavior.GetType()))
if (!addIfTypeAlreadyExists && _QmlInteropBehaviors.Any(ib => ib.GetType() == behavior.GetType()))
{
return;
}

View file

@ -19,7 +19,7 @@ namespace Qml.Net.Internal
{
var result = _original.Resolve(library);
if(!result.IsSuccess && library == "QmlNet")
if (!result.IsSuccess && library == "QmlNet")
{
// Try to let .NET load the library.
try

View file

@ -18,7 +18,7 @@ namespace Qml.Net.Internal
{
var result = _original.Resolve(library);
if(!result.IsSuccess && library == "QmlNet")
if (!result.IsSuccess && library == "QmlNet")
{
// Try to let .NET load the library.
try
@ -39,7 +39,6 @@ namespace Qml.Net.Internal
return result;
}
var info = new DlInfo();
if (dladdr(sym, ref info) != 1)
{
@ -48,11 +47,12 @@ namespace Qml.Net.Internal
var location = Marshal.PtrToStringAnsi(info.fname);
if(File.Exists(location))
if (File.Exists(location))
{
return ResolvePathResult.FromSuccess(location);
}
}
// ReSharper disable EmptyGeneralCatchClause
catch (Exception)
// ReSharper restore EmptyGeneralCatchClause

View file

@ -13,7 +13,6 @@ namespace Qml.Net.Internal
public void Dispose()
{
}
public Dictionary<string, List<Delegate>> Delegates { get; }
@ -31,7 +30,7 @@ namespace Qml.Net.Internal
{
signals.Delegates[signal].Add(del);
}
signals.Delegates.Add(signal, new List<Delegate>{del});
signals.Delegates.Add(signal, new List<Delegate> { del });
}
public static List<Delegate> GetAttachedDelegates(this object obj, string signal)

View file

@ -38,7 +38,7 @@ namespace Qml.Net.Internal
~ObjectId()
{
if(_Tagger != null)
if (_Tagger != null)
{
_Tagger.FreeId(Id);
}

View file

@ -9,7 +9,6 @@ namespace Qml.Net.Internal.Qml
public NetJsValue(IntPtr handle, bool ownsHandle = true)
: base(handle, ownsHandle)
{
}
public bool IsCallable => Interop.NetJsValue.IsCallable(Handle);
@ -193,30 +192,37 @@ namespace Qml.Net.Internal.Qml
{
[NativeSymbol(Entrypoint = "net_js_value_destroy")]
public DestroyDel Destroy { get; set; }
public delegate void DestroyDel(IntPtr jsValue);
[NativeSymbol(Entrypoint = "net_js_value_isCallable")]
public IsCallableDel IsCallable { get; set; }
public delegate bool IsCallableDel(IntPtr jsValue);
[NativeSymbol(Entrypoint = "net_js_value_isArray")]
public IsArrayDel IsArray { get; set; }
public delegate bool IsArrayDel(IntPtr jsValue);
[NativeSymbol(Entrypoint = "net_js_value_call")]
public CallDel Call { get; set; }
public delegate IntPtr CallDel(IntPtr jsValue, IntPtr parameters);
[NativeSymbol(Entrypoint = "net_js_value_getProperty")]
public GetPropertyDel GetProperty { get; set; }
public delegate IntPtr GetPropertyDel(IntPtr jsValue, [MarshalAs(UnmanagedType.LPWStr)] string propertyName);
[NativeSymbol(Entrypoint = "net_js_value_getItemAtIndex")]
public GetItemAtIndexDel GetItemAtIndex { get; set; }
public delegate IntPtr GetItemAtIndexDel(IntPtr jsValue, int arrayIndex);
[NativeSymbol(Entrypoint = "net_js_value_setProperty")]
public SetPropertyDel SetProperty { get; set; }
public delegate void SetPropertyDel(IntPtr jsValue, [MarshalAs(UnmanagedType.LPWStr)] string propertyName, IntPtr value);
}
}

View file

@ -15,6 +15,7 @@ namespace Qml.Net.Internal.Qml
{
[NativeSymbol(Entrypoint = "net_test_helper_runQml")]
public RunQmlDel RunQml { get; set; }
public delegate void RunQmlDel(IntPtr qmlEngine, [MarshalAs(UnmanagedType.LPWStr)]string qml);
}
}

View file

@ -9,13 +9,11 @@ namespace Qml.Net.Internal.Qml
public NetVariant()
: this(Interop.NetVariant.Create())
{
}
public NetVariant(IntPtr handle, bool ownsHandle = true)
: base(handle, ownsHandle)
{
}
public NetVariantType VariantType => Interop.NetVariant.GetVariantType(Handle);
@ -92,7 +90,8 @@ namespace Qml.Net.Internal.Qml
Interop.NetVariant.GetDateTime(Handle, ref dateTime);
if (dateTime.IsNull)
return null;
return new DateTimeOffset(dateTime.Year,
return new DateTimeOffset(
dateTime.Year,
dateTime.Month,
dateTime.Day,
dateTime.Hour,
@ -101,6 +100,7 @@ namespace Qml.Net.Internal.Qml
dateTime.Msec,
TimeSpan.FromSeconds(dateTime.OffsetSeconds));
}
set
{
var dateTime = new DateTimeContainer();
@ -150,103 +150,142 @@ namespace Qml.Net.Internal.Qml
{
[NativeSymbol(Entrypoint = "net_variant_create")]
public CreateDel Create { get; set; }
public delegate IntPtr CreateDel();
[NativeSymbol(Entrypoint = "net_variant_destroy")]
public DestroyDel Destroy { get; set; }
public delegate void DestroyDel(IntPtr variant);
[NativeSymbol(Entrypoint = "net_variant_getVariantType")]
public GetVariantTypeDel GetVariantType { get; set; }
public delegate NetVariantType GetVariantTypeDel(IntPtr variant);
[NativeSymbol(Entrypoint = "net_variant_setNetReference")]
public SetNetReferenceDel SetNetReference { get; set; }
public delegate void SetNetReferenceDel(IntPtr variant, IntPtr instance);
[NativeSymbol(Entrypoint = "net_variant_getNetReference")]
public GetNetReferenceDel GetNetReference { get; set; }
public delegate IntPtr GetNetReferenceDel(IntPtr variant);
[NativeSymbol(Entrypoint = "net_variant_setBool")]
public SetBoolDel SetBool { get; set; }
public delegate void SetBoolDel(IntPtr variant, bool value);
[NativeSymbol(Entrypoint = "net_variant_getBool")]
public GetBoolDel GetBool { get; set; }
public delegate bool GetBoolDel(IntPtr variant);
[NativeSymbol(Entrypoint = "net_variant_setChar")]
public SetCharDel SetChar { get; set; }
public delegate void SetCharDel(IntPtr variant, ushort value);
[NativeSymbol(Entrypoint = "net_variant_getChar")]
public GetCharDel GetChar { get; set; }
public delegate ushort GetCharDel(IntPtr variant);
[NativeSymbol(Entrypoint = "net_variant_setInt")]
public SetIntDel SetInt { get; set; }
public delegate void SetIntDel(IntPtr variant, int value);
[NativeSymbol(Entrypoint = "net_variant_getInt")]
public GetIntDel GetInt { get; set; }
public delegate int GetIntDel(IntPtr variant);
[NativeSymbol(Entrypoint = "net_variant_setUInt")]
public SetUIntDel SetUInt { get; set; }
public delegate void SetUIntDel(IntPtr variant, uint value);
[NativeSymbol(Entrypoint = "net_variant_getUInt")]
public GetUIntDel GetUInt { get; set; }
public delegate uint GetUIntDel(IntPtr variant);
[NativeSymbol(Entrypoint = "net_variant_setLong")]
public SetLongDel SetLong { get; set; }
public delegate void SetLongDel(IntPtr variant, long value);
[NativeSymbol(Entrypoint = "net_variant_getLong")]
public GetLongDel GetLong { get; set; }
public delegate long GetLongDel(IntPtr variant);
[NativeSymbol(Entrypoint = "net_variant_setULong")]
public SetULongDel SetULong { get; set; }
public delegate void SetULongDel(IntPtr variant, ulong value);
[NativeSymbol(Entrypoint = "net_variant_getULong")]
public GetULongDel GetULong { get; set; }
public delegate ulong GetULongDel(IntPtr variant);
[NativeSymbol(Entrypoint = "net_variant_setFloat")]
public SetFloatDel SetFloat { get; set; }
public delegate void SetFloatDel(IntPtr variant, float value);
[NativeSymbol(Entrypoint = "net_variant_getFloat")]
public GetFloatDel GetFloat { get; set; }
public delegate float GetFloatDel(IntPtr variant);
[NativeSymbol(Entrypoint = "net_variant_setDouble")]
public SetDoubleDel SetDouble { get; set; }
public delegate void SetDoubleDel(IntPtr variant, double value);
[NativeSymbol(Entrypoint = "net_variant_getDouble")]
public GetDoubleDel GetDouble { get; set; }
public delegate double GetDoubleDel(IntPtr variant);
[NativeSymbol(Entrypoint = "net_variant_setString")]
public SetStringDel SetString { get; set; }
public delegate void SetStringDel(IntPtr variant, [MarshalAs(UnmanagedType.LPWStr)]string value);
[NativeSymbol(Entrypoint = "net_variant_getString")]
public GetStringDel GetString { get; set; }
public delegate IntPtr GetStringDel(IntPtr variant);
[NativeSymbol(Entrypoint = "net_variant_setDateTime")]
public SetDateTimeDel SetDateTime { get; set; }
public delegate void SetDateTimeDel(IntPtr variant, ref DateTimeContainer dateTime);
[NativeSymbol(Entrypoint = "net_variant_getDateTime")]
public GetDateTimeDel GetDateTime { get; set; }
public delegate void GetDateTimeDel(IntPtr variant, ref DateTimeContainer dateTime);
[NativeSymbol(Entrypoint = "net_variant_setJsValue")]
public SetJsValueDel SetJsValue { get; set; }
public delegate void SetJsValueDel(IntPtr variant, IntPtr jsValue);
[NativeSymbol(Entrypoint = "net_variant_getJsValue")]
public GetJsValueDel GetJsValue { get; set; }
public delegate IntPtr GetJsValueDel(IntPtr variant);
[NativeSymbol(Entrypoint = "net_variant_clear")]
public ClearDel Clear { get; set; }
public delegate void ClearDel(IntPtr variant);
}

View file

@ -7,13 +7,11 @@ namespace Qml.Net.Internal.Qml
public NetVariantList()
: this(Interop.NetVariantList.Create())
{
}
public NetVariantList(IntPtr handle, bool ownsHandle = true)
: base(handle, ownsHandle)
{
}
public int Count => Interop.NetVariantList.Count(Handle);
@ -50,26 +48,37 @@ namespace Qml.Net.Internal.Qml
{
[NativeSymbol(Entrypoint = "net_variant_list_create")]
public CreateDel Create { get; set; }
public delegate IntPtr CreateDel();
[NativeSymbol(Entrypoint = "net_variant_list_destroy")]
public DestroyDel Destroy { get; set; }
public delegate void DestroyDel(IntPtr list);
[NativeSymbol(Entrypoint = "net_variant_list_count")]
public CountDel Count { get; set; }
public delegate int CountDel(IntPtr list);
[NativeSymbol(Entrypoint = "net_variant_list_add")]
public AddDel Add { get; set; }
public delegate void AddDel(IntPtr list, IntPtr variant);
[NativeSymbol(Entrypoint = "net_variant_list_get")]
public GetDel Get { get; set; }
public delegate IntPtr GetDel(IntPtr list, int index);
[NativeSymbol(Entrypoint = "net_variant_list_remove")]
public RemoveDel Remove { get; set; }
public delegate void RemoveDel(IntPtr list, int index);
[NativeSymbol(Entrypoint = "net_variant_list_clear")]
public ClearDel Clear { get; set; }
public delegate void ClearDel(IntPtr list);
}
}

View file

@ -26,26 +26,32 @@ namespace Qml.Net.Internal.Types
{
[NativeSymbol(Entrypoint = "type_info_callbacks_registerCallbacks")]
public RegisterCallbacksDel RegisterCallbacks { get; set; }
public delegate void RegisterCallbacksDel(ref Callbacks callbacks);
[NativeSymbol(Entrypoint = "type_info_callbacks_isTypeValid")]
public IsTypeValidDel IsTypeValid { get; set; }
public delegate bool IsTypeValidDel([MarshalAs(UnmanagedType.LPWStr)]string typeName);
[NativeSymbol(Entrypoint = "type_info_callbacks_releaseNetReferenceGCHandle")]
public ReleaseNetReferenceDel ReleaseNetReference { get; set; }
public delegate void ReleaseNetReferenceDel(UInt64 objectId);
[NativeSymbol(Entrypoint = "type_info_callbacks_releaseNetDelegateGCHandle")]
public ReleaseNetDelegateGCHandleDel ReleaseNetDelegateGCHandle { get; set; }
public delegate void ReleaseNetDelegateGCHandleDel(IntPtr handle);
[NativeSymbol(Entrypoint = "type_info_callbacks_instantiateType")]
public InstantiateTypeDel InstantiateType { get; set; }
public delegate IntPtr InstantiateTypeDel(IntPtr type);
[NativeSymbol(Entrypoint = "type_info_callbacks_invokeMethod")]
public InvokeMethodDel InvokeMethod { get; set; }
public delegate void InvokeMethodDel(IntPtr method, IntPtr target, IntPtr variants, IntPtr result);
}
@ -228,7 +234,8 @@ namespace Qml.Net.Internal.Types
_callbacks.GCCollect(maxGeneration);
}
private bool RaiseNetSignals(IntPtr target,
private bool RaiseNetSignals(
IntPtr target,
string signalName,
IntPtr parameters)
{

View file

@ -8,7 +8,6 @@ namespace Qml.Net.Internal.Types
public NetDelegate(IntPtr handle)
: base(handle)
{
}
public static NetDelegate FromDelegate(Delegate del)
@ -22,7 +21,6 @@ namespace Qml.Net.Internal.Types
handle.Free();
}
public Delegate Delegate
{
get
@ -42,13 +40,17 @@ namespace Qml.Net.Internal.Types
{
[NativeSymbol(Entrypoint = "delegate_create")]
public CreateDel Create { get; set; }
public delegate IntPtr CreateDel(IntPtr handle);
[NativeSymbol(Entrypoint = "delegate_destroy")]
public DestroyDel Destroy { get; set; }
public delegate void DestroyDel(IntPtr del);
[NativeSymbol(Entrypoint = "delegate_getHandle")]
public GetHandleDel GetHandle { get; set; }
public delegate IntPtr GetHandleDel(IntPtr del);
}
}

View file

@ -1,33 +1,33 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Qml.Net.Internal;
namespace Qml.Net.Internal.Types
{
internal class NetMethodInfo : BaseDisposable
{
public NetMethodInfo(NetTypeInfo parentTypeInfo,
public NetMethodInfo(
NetTypeInfo parentTypeInfo,
string methodName,
NetTypeInfo returnTypeInfo,
bool isStatic)
: this(Create(parentTypeInfo, methodName, returnTypeInfo, isStatic))
{
}
public NetMethodInfo(IntPtr handle, bool ownsHandle = true)
:base(handle, ownsHandle)
: base(handle, ownsHandle)
{
}
private static IntPtr Create(NetTypeInfo parentTypeInfo,
private static IntPtr Create(
NetTypeInfo parentTypeInfo,
string methodName,
NetTypeInfo returnTypeInfo,
bool isStatic)
{
return Interop.NetMethodInfo.Create(parentTypeInfo?.Handle ?? IntPtr.Zero,
return Interop.NetMethodInfo.Create(
parentTypeInfo?.Handle ?? IntPtr.Zero,
methodName,
returnTypeInfo?.Handle ?? IntPtr.Zero,
isStatic);
@ -83,7 +83,6 @@ namespace Qml.Net.Internal.Types
public NetMethodInfoParameter(IntPtr handle)
: base(handle)
{
}
public string Name => Utilities.ContainerToString(Interop.NetMethodInfo.GetParameterName(Handle));
@ -108,46 +107,57 @@ namespace Qml.Net.Internal.Types
{
[NativeSymbol(Entrypoint = "method_info_parameter_destroy")]
public DestroyParameterDel DestroyParameter { get; set; }
public delegate void DestroyParameterDel(IntPtr parameter);
[NativeSymbol(Entrypoint = "method_info_parameter_getName")]
public GetParameterNameDel GetParameterName { get; set; }
public delegate IntPtr GetParameterNameDel(IntPtr methodParameter);
[NativeSymbol(Entrypoint = "method_info_parameter_getType")]
public GetParameterTypeDel GetParameterType { get; set; }
public delegate IntPtr GetParameterTypeDel(IntPtr methodParameter);
[NativeSymbol(Entrypoint = "method_info_create")]
public CreateDel Create { get; set; }
public delegate IntPtr CreateDel(IntPtr parentTypeInfo, [MarshalAs(UnmanagedType.LPWStr)]string methodName, IntPtr returnTypeInfo, bool isStatic);
[NativeSymbol(Entrypoint = "method_info_destroy")]
public DestroyDel Destroy { get; set; }
public delegate void DestroyDel(IntPtr methodInfo);
[NativeSymbol(Entrypoint = "method_info_getMethodName")]
public GetMethodNameDel GetMethodName { get; set; }
public delegate IntPtr GetMethodNameDel(IntPtr method);
[NativeSymbol(Entrypoint = "method_info_getReturnType")]
public GetReturnTypeDel GetReturnType { get; set; }
public delegate IntPtr GetReturnTypeDel(IntPtr method);
[NativeSymbol(Entrypoint = "method_info_isStatic")]
public GetIsStaticDel GetIsStatic { get; set; }
public delegate bool GetIsStaticDel(IntPtr method);
[NativeSymbol(Entrypoint = "method_info_addParameter")]
public AddParameterDel AddParameter { get; set; }
public delegate void AddParameterDel(IntPtr method, [MarshalAs(UnmanagedType.LPWStr)]string name, IntPtr type);
[NativeSymbol(Entrypoint = "method_info_getParameterCount")]
public GetParameterCountDel GetParameterCount { get; set; }
public delegate int GetParameterCountDel(IntPtr method);
[NativeSymbol(Entrypoint = "method_info_getParameter")]
public GetParameterDel GetParameter { get; set; }
public delegate IntPtr GetParameterDel(IntPtr method, int index);
}
}

View file

@ -1,41 +1,42 @@
using System;
using System.Runtime.InteropServices;
using Qml.Net.Internal;
namespace Qml.Net.Internal.Types
{
internal class NetPropertyInfo : BaseDisposable
{
public NetPropertyInfo(NetTypeInfo parentType,
public NetPropertyInfo(
NetTypeInfo parentType,
string name,
NetTypeInfo returnType,
bool canRead,
bool canWrite,
NetSignalInfo notifySignal)
: this(Create(parentType,
: this(Create(
parentType,
name,
returnType,
canRead,
canWrite,
notifySignal))
{
}
public NetPropertyInfo(IntPtr handle, bool ownsHandle = true)
: base(handle, ownsHandle)
{
}
private static IntPtr Create(NetTypeInfo parentType,
private static IntPtr Create(
NetTypeInfo parentType,
string name,
NetTypeInfo returnType,
bool canRead,
bool canWrite,
NetSignalInfo notifySignal)
{
return Interop.NetPropertyInfo.Create(parentType?.Handle ?? IntPtr.Zero,
return Interop.NetPropertyInfo.Create(
parentType?.Handle ?? IntPtr.Zero,
name,
returnType?.Handle ?? IntPtr.Zero,
canRead,
@ -60,6 +61,7 @@ namespace Qml.Net.Internal.Types
var result = Interop.NetPropertyInfo.GetNotifySignal(Handle);
return result == IntPtr.Zero ? null : new NetSignalInfo(result);
}
set
{
Interop.NetPropertyInfo.SetNotifySignal(Handle, value.Handle);
@ -76,7 +78,9 @@ namespace Qml.Net.Internal.Types
{
[NativeSymbol(Entrypoint = "property_info_create")]
public CreateDel Create { get; set; }
public delegate IntPtr CreateDel(IntPtr parentType,
public delegate IntPtr CreateDel(
IntPtr parentType,
[MarshalAs(UnmanagedType.LPWStr)]string methodName,
IntPtr returnType,
bool canRead,
@ -85,34 +89,42 @@ namespace Qml.Net.Internal.Types
[NativeSymbol(Entrypoint = "property_info_destroy")]
public DestroyDel Destroy { get; set; }
public delegate void DestroyDel(IntPtr property);
[NativeSymbol(Entrypoint = "property_info_getParentType")]
public GetParentTypeDel GetParentType { get; set; }
public delegate IntPtr GetParentTypeDel(IntPtr property);
[NativeSymbol(Entrypoint = "property_info_getPropertyName")]
public GetPropertyNameDel GetPropertyName { get; set; }
public delegate IntPtr GetPropertyNameDel(IntPtr property);
[NativeSymbol(Entrypoint = "property_info_getReturnType")]
public GetReturnTypeDel GetReturnType { get; set; }
public delegate IntPtr GetReturnTypeDel(IntPtr property);
[NativeSymbol(Entrypoint = "property_info_canRead")]
public GetCanReadDel GetCanRead { get; set; }
public delegate bool GetCanReadDel(IntPtr property);
[NativeSymbol(Entrypoint = "property_info_canWrite")]
public GetCanWriteDel GetCanWrite { get; set; }
public delegate bool GetCanWriteDel(IntPtr property);
[NativeSymbol(Entrypoint = "property_info_getNotifySignal")]
public GetNotifySignalDel GetNotifySignal { get; set; }
public delegate IntPtr GetNotifySignalDel(IntPtr property);
[NativeSymbol(Entrypoint = "property_info_setNotifySignal")]
public SetNotifySignalDel SetNotifySignal { get; set; }
public delegate void SetNotifySignalDel(IntPtr property, IntPtr signal);
}
}

View file

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Qml.Net.Internal;
using Qml.Net.Internal.Qml;
namespace Qml.Net.Internal.Types
@ -9,21 +8,20 @@ namespace Qml.Net.Internal.Types
internal class NetReference : BaseDisposable
{
private NetReference(UInt64 objectId, NetTypeInfo type, bool ownsHandle = true)
:base(Interop.NetReference.Create(objectId, type.Handle), ownsHandle)
: base(Interop.NetReference.Create(objectId, type.Handle), ownsHandle)
{
}
public NetReference(IntPtr handle, bool ownsHandle = true)
: base(handle, ownsHandle)
{
}
public object Instance
{
get
{
if(ObjectIdReferenceTracker.TryGetObjectFor(ObjectId, out var obj))
if (ObjectIdReferenceTracker.TryGetObjectFor(ObjectId, out var obj))
{
return obj;
}
@ -83,7 +81,10 @@ namespace Qml.Net.Internal.Types
}
var typeInfo = NetTypeManager.GetTypeInfo(GetUnproxiedType(value.GetType()));
if(typeInfo == null) throw new InvalidOperationException($"Couldn't create type info from {value.GetType().AssemblyQualifiedName}");
if (typeInfo == null)
{
throw new InvalidOperationException($"Couldn't create type info from {value.GetType().AssemblyQualifiedName}");
}
objectId = value.GetOrCreateTag();
var newNetReference = new NetReference(objectId.Value, typeInfo);
@ -105,22 +106,27 @@ namespace Qml.Net.Internal.Types
{
[NativeSymbol(Entrypoint = "net_instance_create")]
public CreateDel Create { get; set; }
public delegate IntPtr CreateDel(UInt64 objectId, IntPtr type);
[NativeSymbol(Entrypoint = "net_instance_destroy")]
public DestroyDel Destroy { get; set; }
public delegate void DestroyDel(IntPtr instance);
[NativeSymbol(Entrypoint = "net_instance_clone")]
public CloneDel Clone { get; set; }
public delegate IntPtr CloneDel(IntPtr instance);
[NativeSymbol(Entrypoint = "net_instance_getObjectId")]
public GetObjectIdDel GetObjectId { get; set; }
public delegate UInt64 GetObjectIdDel(IntPtr instance);
[NativeSymbol(Entrypoint = "net_instance_activateSignal")]
public ActivateSignalDel ActivateSignal { get; set; }
public delegate bool ActivateSignalDel(IntPtr instance, [MarshalAs(UnmanagedType.LPWStr)]string signalName, IntPtr variants);
}
@ -129,6 +135,7 @@ namespace Qml.Net.Internal.Types
class ObjectEntry
{
public object Obj { get; private set; }
public UInt64 Counter { get; set; }
public ObjectEntry(object obj, UInt64 count)
@ -143,9 +150,9 @@ namespace Qml.Net.Internal.Types
internal static bool TryGetObjectFor(UInt64 objectId, out object obj)
{
lock(_LockObject)
lock (_LockObject)
{
if(_ObjectIdObjectLookup.ContainsKey(objectId))
if (_ObjectIdObjectLookup.ContainsKey(objectId))
{
obj = _ObjectIdObjectLookup[objectId].Obj;
return true;
@ -164,13 +171,16 @@ namespace Qml.Net.Internal.Types
throw new InvalidOperationException("Releasing a NetReference that hasn't been counted!");
}
_ObjectIdObjectLookup[objectId].Counter--;
//when there are no more QML references
// When there are no more QML references.
if (_ObjectIdObjectLookup[objectId].Counter == 0)
{
var obj = _ObjectIdObjectLookup[objectId].Obj;
//remove object entry
// Remove object entry.
_ObjectIdObjectLookup.Remove(objectId);
//and notify the behaviors
// And notify the behaviors.
InteropBehaviors.OnObjectLeavesNative(obj, objectId);
}
}

View file

@ -8,13 +8,11 @@ namespace Qml.Net.Internal.Types
internal NetSignalInfo(IntPtr handle, bool ownsHandle = true)
: base(handle, ownsHandle)
{
}
public NetSignalInfo(NetTypeInfo parentType, string name)
: this(Interop.NetSignalInfo.Create(parentType.Handle, name))
{
}
public NetTypeInfo ParentType => new NetTypeInfo(Interop.NetSignalInfo.GetParentType(Handle));
@ -43,26 +41,37 @@ namespace Qml.Net.Internal.Types
{
[NativeSymbol(Entrypoint = "signal_info_create")]
public CreateDel Create { get; set; }
public delegate IntPtr CreateDel(IntPtr parentType, [MarshalAs(UnmanagedType.LPWStr)] string name);
[NativeSymbol(Entrypoint = "signal_info_destroy")]
public DestroyDel Destroy { get; set; }
public delegate void DestroyDel(IntPtr signal);
[NativeSymbol(Entrypoint = "signal_info_getParentType")]
public GetParentTypeDel GetParentType { get; set; }
public delegate IntPtr GetParentTypeDel(IntPtr signal);
[NativeSymbol(Entrypoint = "signal_info_getName")]
public GetNameDel GetName { get; set; }
public delegate IntPtr GetNameDel(IntPtr signal);
[NativeSymbol(Entrypoint = "signal_info_addParameter")]
public AddParameterDel AddParameter { get; set; }
public delegate void AddParameterDel(IntPtr signal, NetVariantType type);
[NativeSymbol(Entrypoint = "signal_info_getParameterCount")]
public GetParameterCountDel GetParameterCount { get; set; }
public delegate int GetParameterCountDel(IntPtr signal);
[NativeSymbol(Entrypoint = "signal_info_getParameter")]
public GetParameterDel GetParameter { get; set; }
public delegate NetVariantType GetParameterDel(IntPtr signal, int index);
}
}

View file

@ -6,14 +6,13 @@ namespace Qml.Net.Internal.Types
internal class NetTypeInfo : BaseDisposable
{
public NetTypeInfo(string fullTypeName)
:this(Interop.NetTypeInfo.Create(fullTypeName))
: this(Interop.NetTypeInfo.Create(fullTypeName))
{
}
public NetTypeInfo(IntPtr handle, bool ownsHandle = true)
:base(handle, ownsHandle)
: base(handle, ownsHandle)
{
}
public string FullTypeName => Utilities.ContainerToString(Interop.NetTypeInfo.GetFullTypeName(Handle));
@ -121,110 +120,137 @@ namespace Qml.Net.Internal.Types
{
[NativeSymbol(Entrypoint = "type_info_create")]
public CreateDel Create { get; set; }
public delegate IntPtr CreateDel([MarshalAs(UnmanagedType.LPWStr)]string fullTypeName);
[NativeSymbol(Entrypoint = "type_info_destroy")]
public DestroyDel Destroy { get; set; }
public delegate void DestroyDel(IntPtr netTypeInfo);
[NativeSymbol(Entrypoint = "type_info_getFullTypeName")]
public GetFullTypeNameDel GetFullTypeName { get; set; }
public delegate IntPtr GetFullTypeNameDel(IntPtr netTypeInfo);
[NativeSymbol(Entrypoint = "type_info_setClassName")]
public SetClassNameDel SetClassName { get; set; }
public delegate void SetClassNameDel(IntPtr netTypeInfo, [MarshalAs(UnmanagedType.LPWStr)]string className);
[NativeSymbol(Entrypoint = "type_info_getClassName")]
public GetClassNameDel GetClassName { get; set; }
public delegate IntPtr GetClassNameDel(IntPtr netTypeInfo);
[NativeSymbol(Entrypoint = "type_info_setPrefVariantType")]
public SetPrefVariantTypeDel SetPrefVariantType { get; set; }
public delegate void SetPrefVariantTypeDel(IntPtr netTypeInfo, NetVariantType variantType);
[NativeSymbol(Entrypoint = "type_info_getPrefVariantType")]
public GetPrefVariantTypeDel GetPrefVariantType { get; set; }
public delegate NetVariantType GetPrefVariantTypeDel(IntPtr netTypeInfo);
[NativeSymbol(Entrypoint = "type_info_setIsArray")]
public GetIsArrayDel GetIsArray { get; set; }
public delegate bool GetIsArrayDel(IntPtr netTypeInfo);
[NativeSymbol(Entrypoint = "type_info_getIsArray")]
public SetIsArrayDel SetIsArray { get; set; }
public delegate void SetIsArrayDel(IntPtr netTypeInfo, bool isArray);
[NativeSymbol(Entrypoint = "type_info_setIsList")]
public GetIsListDel GetIsList { get; set; }
public delegate bool GetIsListDel(IntPtr netTypeInfo);
[NativeSymbol(Entrypoint = "type_info_getIsList")]
public SetIsListDel SetIsList { get; set; }
public delegate void SetIsListDel(IntPtr netTypeInfo, bool isList);
[NativeSymbol(Entrypoint = "type_info_addMethod")]
public AddMethodDel AddMethod { get; set; }
public delegate void AddMethodDel(IntPtr typeInfo, IntPtr methodInfo);
[NativeSymbol(Entrypoint = "type_info_getMethodCount")]
public GetMethodCountDel GetMethodCount { get; set; }
public delegate int GetMethodCountDel(IntPtr typeInfo);
[NativeSymbol(Entrypoint = "type_info_getMethodInfo")]
public GetMethodInfoDel GetMethodInfo { get; set; }
public delegate IntPtr GetMethodInfoDel(IntPtr typeInfo, int index);
[NativeSymbol(Entrypoint = "type_info_getLocalMethodCount")]
public GetLocalMethodCountDel GetLocalMethodCount { get; set; }
public delegate int GetLocalMethodCountDel(IntPtr typeInfo);
[NativeSymbol(Entrypoint = "type_info_getLocalMethodInfo")]
public GetLocalMethodInfoDel GetLocalMethodInfo { get; set; }
public delegate IntPtr GetLocalMethodInfoDel(IntPtr typeInfo, int index);
[NativeSymbol(Entrypoint = "type_info_getStaticMethodCount")]
public GetStaticMethodCountDel GetStaticMethodCount { get; set; }
public delegate int GetStaticMethodCountDel(IntPtr typeInfo);
[NativeSymbol(Entrypoint = "type_info_getStaticMethodInfo")]
public GetStaticMethodInfoDel GetStaticMethodInfo { get; set; }
public delegate IntPtr GetStaticMethodInfoDel(IntPtr typeInfo, int index);
[NativeSymbol(Entrypoint = "type_info_addProperty")]
public AddPropertyDel AddProperty { get; set; }
public delegate void AddPropertyDel(IntPtr typeInfo, IntPtr property);
[NativeSymbol(Entrypoint = "type_info_getPropertyCount")]
public GetPropertyCountDel GetPropertyCount { get; set; }
public delegate int GetPropertyCountDel(IntPtr typeInfo);
[NativeSymbol(Entrypoint = "type_info_getProperty")]
public GetPropertyDel GetProperty { get; set; }
public delegate IntPtr GetPropertyDel(IntPtr typeInfo, int index);
[NativeSymbol(Entrypoint = "type_info_addSignal")]
public AddSignalDel AddSignal { get; set; }
public delegate void AddSignalDel(IntPtr typeInfo, IntPtr signal);
[NativeSymbol(Entrypoint = "type_info_getSignalCount")]
public GetSignalCountDel GetSignalCount { get; set; }
public delegate int GetSignalCountDel(IntPtr typeInfo);
[NativeSymbol(Entrypoint = "type_info_getSignal")]
public GetSignalDel GetSignal { get; set; }
public delegate IntPtr GetSignalDel(IntPtr typeInfo, int index);
[NativeSymbol(Entrypoint = "type_info_isLoaded")]
public IsLoadedDel IsLoaded { get; set; }
public delegate bool IsLoadedDel(IntPtr typeInfo);
[NativeSymbol(Entrypoint = "type_info_isLoading")]
public IsLoadingDel IsLoading { get; set; }
public delegate bool IsLoadingDel(IntPtr typeInfo);
[NativeSymbol(Entrypoint = "type_info_ensureLoaded")]
public EnsureLoadedDel EnsureLoaded { get; set; }
public delegate void EnsureLoadedDel(IntPtr typeInfo);
}
}

View file

@ -12,7 +12,7 @@ namespace Qml.Net.Internal.Types
public static NetTypeInfo GetTypeInfo(Type type)
{
if(type == null)
if (type == null)
{
return null;
}
@ -26,6 +26,7 @@ namespace Qml.Net.Internal.Types
{
[NativeSymbol(Entrypoint = "type_manager_getTypeInfo")]
public GetTypeInfoDel GetTypeInfo { get; set; }
public delegate IntPtr GetTypeInfoDel([MarshalAs(UnmanagedType.LPWStr)]string fullTypeName);
}
}

View file

@ -18,7 +18,7 @@ namespace Qml.Net.Internal
{
var result = _original.Resolve(library);
if(!result.IsSuccess && library == "QmlNet")
if (!result.IsSuccess && library == "QmlNet")
{
// Try to let .NET load the library.
try
@ -34,7 +34,7 @@ namespace Qml.Net.Internal
var path = Marshal.PtrToStringAnsi(bytes);
Marshal.FreeHGlobal(bytes);
if(File.Exists(path))
if (File.Exists(path))
{
return ResolvePathResult.FromSuccess(path);
}

View file

@ -7,7 +7,6 @@ namespace Qml.Net
{
public NotifySignalAttribute()
{
}
public NotifySignalAttribute(string name)

View file

@ -15,13 +15,12 @@ namespace Qml.Net
readonly SynchronizationContext _oldSynchronizationContext;
public QGuiApplication()
:this(null)
: this(null)
{
}
public QGuiApplication(string[] args)
:base(Create(args?.ToList()))
: base(Create(args?.ToList()))
{
TriggerDelegate triggerDelegate = Trigger;
_triggerHandle = GCHandle.Alloc(triggerDelegate);
@ -33,7 +32,7 @@ namespace Qml.Net
}
internal QGuiApplication(IntPtr existingApp)
:base(CreateFromExisting(existingApp))
: base(CreateFromExisting(existingApp))
{
TriggerDelegate triggerDelegate = Trigger;
_triggerHandle = GCHandle.Alloc(triggerDelegate);
@ -119,6 +118,7 @@ namespace Qml.Net
strings.Add(variant);
}
}
return Interop.QGuiApplication.Create(strings.Handle, IntPtr.Zero);
}
}
@ -146,30 +146,37 @@ namespace Qml.Net
{
[NativeSymbol(Entrypoint = "qguiapplication_create")]
public CreateDel Create { get; set; }
public delegate IntPtr CreateDel(IntPtr args, IntPtr existingApp);
[NativeSymbol(Entrypoint = "qguiapplication_destroy")]
public DestroyDel Destroy { get; set; }
public delegate void DestroyDel(IntPtr app);
[NativeSymbol(Entrypoint = "qguiapplication_exec")]
public ExecDel Exec { get; set; }
public delegate int ExecDel();
[NativeSymbol(Entrypoint = "qguiapplication_addTriggerCallback")]
public AddTriggerCallbackDel AddTriggerCallback { get; set; }
public delegate void AddTriggerCallbackDel(IntPtr app, IntPtr callback);
[NativeSymbol(Entrypoint = "qguiapplication_requestTrigger")]
public RequestTriggerDel RequestTrigger { get; set; }
public delegate void RequestTriggerDel(IntPtr app);
[NativeSymbol(Entrypoint = "qguiapplication_exit")]
public ExitDel Exit { get; set; }
public delegate void ExitDel(int returnCode);
[NativeSymbol(Entrypoint = "qguiapplication_internalPointer")]
public InternalPointerDel InternalPointer { get; set; }
public delegate IntPtr InternalPointerDel(IntPtr app);
}
}

View file

@ -10,15 +10,13 @@ namespace Qml.Net
public sealed class QQmlApplicationEngine : BaseDisposable
{
public QQmlApplicationEngine()
:base(Interop.QQmlApplicationEngine.Create(IntPtr.Zero))
: base(Interop.QQmlApplicationEngine.Create(IntPtr.Zero))
{
}
internal QQmlApplicationEngine(IntPtr existingEngine)
:base(Interop.QQmlApplicationEngine.Create(existingEngine))
: base(Interop.QQmlApplicationEngine.Create(existingEngine))
{
}
public void Load(string path)
@ -105,46 +103,57 @@ namespace Qml.Net
{
[NativeSymbol(Entrypoint = "qqmlapplicationengine_create")]
public CreateDel Create { get; set; }
public delegate IntPtr CreateDel(IntPtr existingEngine);
[NativeSymbol(Entrypoint = "qqmlapplicationengine_destroy")]
public DestroyDel Destroy { get; set; }
public delegate void DestroyDel(IntPtr engine);
[NativeSymbol(Entrypoint = "qqmlapplicationengine_load")]
public LoadDel Load { get; set; }
public delegate int LoadDel(IntPtr engine, [MarshalAs(UnmanagedType.LPWStr)]string path);
[NativeSymbol(Entrypoint = "qqmlapplicationengine_loadData")]
public LoadDataDel LoadData { get; set; }
public delegate int LoadDataDel(IntPtr engine, [MarshalAs(UnmanagedType.LPWStr)]string path);
[NativeSymbol(Entrypoint = "qqmlapplicationengine_registerType")]
public RegisterTypeDel RegisterType { get; set; }
public delegate int RegisterTypeDel(IntPtr type, [MarshalAs(UnmanagedType.LPWStr)]string uri, int versionMajor, int versionMinor, [MarshalAs(UnmanagedType.LPWStr)]string qmlName);
[NativeSymbol(Entrypoint = "qqmlapplicationengine_registerSingletonTypeQml")]
public RegisterSingletonTypeQmlDel RegisterSingletonTypeQml { get; set; }
public delegate int RegisterSingletonTypeQmlDel([MarshalAs(UnmanagedType.LPWStr)]string url, [MarshalAs(UnmanagedType.LPWStr)]string uri, int versionMajor, int versionMinor, [MarshalAs(UnmanagedType.LPWStr)]string qmlName);
[NativeSymbol(Entrypoint = "qqmlapplicationengine_registerSingletonTypeNet")]
public RegisterSingletonTypeNetDel RegisterSingletonTypeNet { get; set; }
public delegate int RegisterSingletonTypeNetDel(IntPtr type, [MarshalAs(UnmanagedType.LPWStr)]string uri, int versionMajor, int versionMinor, [MarshalAs(UnmanagedType.LPWStr)]string typeName);
[NativeSymbol(Entrypoint = "qqmlapplicationengine_addImportPath")]
public AddImportPathDel AddImportPath { get; set; }
public delegate void AddImportPathDel(IntPtr engine, [MarshalAs(UnmanagedType.LPWStr)]string path);
[NativeSymbol(Entrypoint = "qqmlapplicationengine_internalPointer")]
public InternalPointerDel InternalPointer { get; set; }
public delegate IntPtr InternalPointerDel(IntPtr app);
[NativeSymbol(Entrypoint = "qqmlapplicationengine_getContextProperty")]
public GetContextPropertyDel GetContextProperty { get; set; }
public delegate IntPtr GetContextPropertyDel(IntPtr app, [MarshalAs(UnmanagedType.LPWStr)]string name);
[NativeSymbol(Entrypoint = "qqmlapplicationengine_setContextProperty")]
public SetContextPropertyDel SetContextProperty { get; set; }
public delegate void SetContextPropertyDel(IntPtr app, [MarshalAs(UnmanagedType.LPWStr)]string path, IntPtr value);
}
}

View file

@ -20,10 +20,12 @@ namespace Qml.Net
{
[NativeSymbol(Entrypoint = "qquickstyle_setFallbackStyle")]
public SetFallbackStyleDel SetFallbackStyle { get; set; }
public delegate void SetFallbackStyleDel([MarshalAs(UnmanagedType.LPWStr)]string style);
[NativeSymbol(Entrypoint = "qquickstyle_setStyle")]
public SetStyleDel SetStyle { get; set; }
public delegate void SetStyleDel([MarshalAs(UnmanagedType.LPWStr)]string style);
}
}

View file

@ -20,9 +20,12 @@ namespace Qml.Net
{
[NativeSymbol(Entrypoint = "qresource_registerResource")]
public RegisterResourceDel RegisterResource { get; set; }
public delegate bool RegisterResourceDel([MarshalAs(UnmanagedType.LPWStr)]string rccFileName, [MarshalAs(UnmanagedType.LPWStr)]string resourceRoot);
[NativeSymbol(Entrypoint = "qresource_unregisterResource")]
public UnregisterResourceDel UnregisterResource { get; set; }
public delegate bool UnregisterResourceDel([MarshalAs(UnmanagedType.LPWStr)]string rccFileName, [MarshalAs(UnmanagedType.LPWStr)]string resourceRoot);
}
}

View file

@ -1,10 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<CodeAnalysisRuleSet>../../../StyleCop.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
<PackageReference Include="NetNativeLibLoader" Version="0.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />
</ItemGroup>
</Project>

View file

@ -1,6 +1,6 @@
using Qml.Net.Internal;
using System;
using System;
using System.Runtime.InteropServices;
using Qml.Net.Internal;
namespace Qml.Net
{
@ -26,12 +26,17 @@ namespace Qml.Net
{
[NativeSymbol(Entrypoint = "qt_putenv")]
public PutEnvDel PutEnv { get; set; }
public delegate bool PutEnvDel([MarshalAs(UnmanagedType.LPStr)]string name, [MarshalAs(UnmanagedType.LPStr)]string value);
[NativeSymbol(Entrypoint = "qt_getenv")]
public GetEnvDel GetEnv { get; set; }
public delegate IntPtr GetEnvDel(string name);
[NativeSymbol(Entrypoint = "qt_version")]
public QtVersionDel QtVersion { get; set; }
public delegate IntPtr QtVersionDel();
}
}

View file

@ -14,6 +14,7 @@ namespace Qml.Net
{
[NativeSymbol(Entrypoint = "qtwebebengine_initialize")]
public InitializeDel Initialize { get; set; }
public delegate void InitializeDel();
}
}

View file

@ -11,7 +11,6 @@ namespace Qml.Net
Parameters = parameters;
}
public string Name { get; }
public NetVariantType[] Parameters { get; }

View file

@ -31,6 +31,7 @@ namespace Qml.Net
{
[NativeSymbol(Entrypoint = "freeString")]
public FreeStringDel FreeString { get; set; }
public delegate void FreeStringDel(IntPtr container);
}
}