Skip to content

Commit

Permalink
Upload
Browse files Browse the repository at this point in the history
  • Loading branch information
seclerp committed Oct 31, 2023
1 parent 2d0f076 commit 3e29712
Show file tree
Hide file tree
Showing 202 changed files with 59,156 additions and 25 deletions.
13 changes: 13 additions & 0 deletions src/ChromeProtocol.Core/ChromeProtocol.Core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>ChromeProtocol.Core</PackageId>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json"/>
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions src/ChromeProtocol.Core/DomainEventHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace ChromeProtocol.Core;

public delegate Task DomainEventHandler<in TEvent>(TEvent @event)
where TEvent : IEvent;
13 changes: 13 additions & 0 deletions src/ChromeProtocol.Core/Extensions/ReflectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace ChromeProtocol.Core.Extensions;

public static class ReflectionExtensions
{
public static IEnumerable<Type> BaseTypesAndSelf(this Type type)
{
while (type != null)
{
yield return type;
type = type.BaseType;
}
}
}
10 changes: 10 additions & 0 deletions src/ChromeProtocol.Core/ICommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace ChromeProtocol.Core;

public interface ICommand
{
}

public interface ICommand<TResponse> : ICommand
where TResponse : IType
{
}
5 changes: 5 additions & 0 deletions src/ChromeProtocol.Core/IEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace ChromeProtocol.Core;

public interface IEvent
{
}
7 changes: 7 additions & 0 deletions src/ChromeProtocol.Core/IType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace ChromeProtocol.Core;

public interface IType
{
}

public record ExampleValue(string Value) : PrimitiveType<string>(Value);
16 changes: 16 additions & 0 deletions src/ChromeProtocol.Core/IsExternalInit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <auto-generated>
// ReSharper disable once CheckNamespace

using System.ComponentModel;

namespace System.Runtime.CompilerServices
{
/// <summary>
/// Reserved to be used by the compiler for tracking metadata.
/// This class should not be used by developers in source code.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class IsExternalInit
{
}
}
15 changes: 15 additions & 0 deletions src/ChromeProtocol.Core/MethodNameAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace ChromeProtocol.Core;

/// <summary>
/// Specifies method name to be used in context of given command or event.
/// </summary>
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public class MethodNameAttribute : Attribute
{
public string MethodName { get; }

public MethodNameAttribute(string methodName)
{
MethodName = methodName;
}
}
11 changes: 11 additions & 0 deletions src/ChromeProtocol.Core/PrimitiveType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace ChromeProtocol.Core;

public interface IPrimitiveType : IType
{
object? RawValue { get; }
}

public abstract record PrimitiveType<TValue>(TValue Value) : IPrimitiveType
{
object? IPrimitiveType.RawValue => Value;
}
32 changes: 32 additions & 0 deletions src/ChromeProtocol.Core/PrimitiveTypeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using ChromeProtocol.Core.Extensions;
using Newtonsoft.Json;

namespace ChromeProtocol.Core;

public class PrimitiveTypeConverter : JsonConverter
{
static Type? GetValueType(Type objectType) =>
objectType
.BaseTypesAndSelf()
.Where(t => t.IsGenericType && t.GetGenericTypeDefinition() == typeof(PrimitiveType<>))
.Select(t => t.GetGenericArguments()[0])
.FirstOrDefault();

public override bool CanConvert(Type objectType) => GetValueType(objectType) != null;

public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
return Activator.CreateInstance(objectType, null);

var valueType = GetValueType(objectType);
var value = serializer.Deserialize(reader, valueType);

return Activator.CreateInstance(objectType, value);
}

public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
{
serializer.Serialize(writer, ((IPrimitiveType?)value)?.RawValue);
}
}
17 changes: 17 additions & 0 deletions src/ChromeProtocol.Domains/ChromeProtocol.Domains.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>ChromeProtocol.Domains</PackageId>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ChromeProtocol.Core\ChromeProtocol.Core.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Generated\" />
</ItemGroup>

</Project>
Loading

0 comments on commit 3e29712

Please sign in to comment.