Fixed generated code when a class extends multiple classes (#38)

* .

* .

* pnp

* ok

* compiles

* ?

* e

* set

* .ToArray()

* n

* ...

* ok

* pnp

* .

* .

* mapster
This commit is contained in:
Stef Heyenrath
2022-09-04 11:13:16 +02:00
committed by GitHub
parent ee35d1916f
commit 69fa995982
36 changed files with 824 additions and 340 deletions
@@ -1,10 +0,0 @@
using Microsoft.SharePoint.Client;
namespace ProxyInterfaceConsumer.PnP
{
[ProxyInterfaceGenerator.Proxy(typeof(ClientContext))]
public partial interface IClientContext
{
// public virtual void X();
}
}
@@ -1,10 +1,7 @@
using AutoMapper;
using DifferentNamespace;
using System;
using System.Collections.Generic;
using System.Text.Json;
using Microsoft.SharePoint.Client;
using ProxyInterfaceConsumer.PnP;
using DifferentNamespace;
namespace ProxyInterfaceConsumer
{
@@ -17,11 +14,6 @@ namespace ProxyInterfaceConsumer
public static void Main()
{
var cp = new ClientContextProxy(new ClientContext("x"));
cp.ExecuteQuery();
var webP = cp.Web;
var t = new TestProxy(new Test());
IPersonT<int> pT = new PersonTProxy<int>(new PersonT<int>());
@@ -1,42 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<OutputType>Exe</OutputType>
<LangVersion>9</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<OutputType>Exe</OutputType>
<LangVersion>9</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="IPersonTT.cs" />
<Compile Remove="PersonTT.cs" />
</ItemGroup>
<ItemGroup>
<Compile Remove="IPersonTT.cs" />
<Compile Remove="PersonTT.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="3.10.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.10.0" />
<PackageReference Include="PnP.Framework" Version="1.8.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="3.10.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.10.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ProxyInterfaceSourceGenerator\ProxyInterfaceSourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
<ItemGroup>
<Compile Update="PnP\IWeb.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Compile>
<Compile Update="PnP\IClientContext.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Compile>
<Compile Update="PnP\IClientRuntimeContext.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ProxyInterfaceSourceGenerator\ProxyInterfaceSourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
</Project>
@@ -0,0 +1,7 @@
namespace ProxyInterfaceConsumer
{
// [ProxyInterfaceGenerator.Proxy(typeof(Microsoft.CodeAnalysis.GeneratorExecutionContext))]
public partial interface IGeneratorExecutionContext
{
}
}
@@ -0,0 +1,9 @@
namespace ProxyInterfaceConsumer
{
[ProxyInterfaceGenerator.Proxy(typeof(ProxyInterfaceConsumer.PersonTT<,>))]
public partial interface IPersonTT<T1, T2>
where T1 : struct
where T2 : class, new()
{
}
}
@@ -0,0 +1,15 @@
namespace ProxyInterfaceConsumer
{
public class PersonTT<T1, T2>
where T1 : struct
where T2 : class, new()
{
public T1 TVal1 { get; set; }
public T2 TVal2 { get; set; }
public void Call(int x, T1 t1, T2 t2)
{
}
}
}
@@ -0,0 +1,188 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Security.Cryptography.X509Certificates;
using AutoMapper;
using Mapster;
using Microsoft.SharePoint.Client;
namespace ProxyInterfaceConsumer.PnP
{
[ProxyInterfaceGenerator.Proxy(typeof(Microsoft.SharePoint.Client.ClientContext))]
public partial interface IClientContext: IClientRuntimeContext
{
// public virtual void X();
}
}
namespace ProxyInterfaceConsumer.PnP
{
public class CustomResolver : IValueResolver<object, object, object>
{
public object Resolve(object source, object destination, object member, ResolutionContext context)
{
try
{
return member;
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
}
public class MyConverter : ITypeConverter<object, object>
{
public object Convert(object source, object destination, ResolutionContext context)
{
return System.Convert.ToDateTime(source);
}
}
public class MyWebConverter : ITypeConverter<Web, IWeb>
{
public IWeb Convert(Web source, IWeb destination, ResolutionContext context)
{
return new ProxyInterfaceConsumer.PnP.WebProxy(source);
}
}
public partial class ClientContextProxy
{
public void Test()
{
var mapper = new MapperConfiguration(cfg =>
{
//cfg.ForAllMaps((map, expression) =>
//{
// expression.ForAllMembers(configurationExpression =>
// configurationExpression.PreCondition((o, o1, arg3) =>
// {
// return true;
// })
// );
//});
// CreateMap<TSource, TDestination>();
cfg.CreateMap<Microsoft.SharePoint.Client.Web, ProxyInterfaceConsumer.PnP.IWeb>()
.ConstructUsing((instance_841809920, context) =>
{
try
{
var p = new ProxyInterfaceConsumer.PnP.WebProxy(instance_841809920);
return p;
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
})
//.ConvertUsing<MyWebConverter>()
.ForAllMembers(opt =>
{
//opt.MapFrom(x =>x , );
//opt.ConvertUsing<MyConverter, IWeb>( x=> x);
opt.PreCondition((src, dest, context) =>
{
try
{
var x = src != null;
return true;
}
catch
{
return false;
}
});
opt.MapAtRuntime();
opt.MapFrom<CustomResolver>();
})
//.ConstructUsing(instance_841809920 => new ProxyInterfaceConsumer.PnP.WebProxy(instance_841809920))
//.ForAllMembers(opt => {
// opt.PreCondition((src, dest, context) =>
// {
// try
// {
// var x = src != null;
// return true;
// }
// catch
// {
// return false;
// }
// });
//})
;
//cfg.CreateMap<ProxyInterfaceConsumer.PnP.IWeb, Microsoft.SharePoint.Client.Web>()
// .ConstructUsing(proxy1898650104 => ((ProxyInterfaceConsumer.PnP.WebProxy)proxy1898650104)._Instance)
// .ForAllMembers(opt => {
// opt.PreCondition((src, dest, context) =>
// {
// try
// {
// var x = src != null;
// return true;
// }
// catch
// {
// return false;
// }
// });
// });
}).CreateMapper();
//var web = _mapper.Map<Web>(Web);
//Load(web, w => w.Lists);
TypeAdapterConfig<Web, IWeb>.NewConfig().ConstructUsing(instance_841809920 => new ProxyInterfaceConsumer.PnP.WebProxy(instance_841809920));
TypeAdapterConfig<IWeb, Web>.NewConfig().MapWith(proxy1898650104 => ((ProxyInterfaceConsumer.PnP.WebProxy)proxy1898650104)._Instance);
var iweb = _Instance.Web.Adapt<IWeb>();
var web = iweb.Adapt<Web>();
//var mapped = mapper.Map<ProxyInterfaceConsumer.PnP.IWeb>(_Instance.Web);
Load3(Web, w => w.Lists);
}
public void LoadOriginal<T>(T clientObject, params System.Linq.Expressions.Expression<System.Func<T, object>>[] retrievals) where T : Microsoft.SharePoint.Client.ClientObject
{
T clientObject_ = clientObject;
System.Linq.Expressions.Expression<System.Func<T, object>>[] retrievals_ = retrievals;
_Instance.Load<T>(clientObject_, retrievals_);
}
//public void Load2(IClientObject clientObject, params Expression<Func<IClientObject, object>>[] retrievals)
//{
// ClientObject clientObject_ = _mapper.Map<ClientObject>(clientObject);
// Expression<Func<ClientObject, object>>[] retrievals_ = _mapper.Map<Expression<Func<ClientObject, object>>[]>(retrievals);
// _Instance.Load(clientObject_, retrievals_);
//}
public void Load3(IWeb clientObject, params System.Linq.Expressions.Expression<System.Func<IWeb, object>>[] retrievals)
{
var clientObject_ = (WebProxy) clientObject;
//Expression<Func<WebProxy, object>>[] retrievals_ = _mapper.Map<Expression<Func<WebProxy, object>>[]>(retrievals);
Load(clientObject_._Instance, null);
}
}
}
@@ -0,0 +1,7 @@
namespace ProxyInterfaceConsumer.PnP
{
[ProxyInterfaceGenerator.Proxy(typeof(Microsoft.SharePoint.Client.ClientObject))]
public partial interface IClientObject
{
}
}
@@ -3,6 +3,6 @@ namespace ProxyInterfaceConsumer.PnP
[ProxyInterfaceGenerator.Proxy(typeof(Microsoft.SharePoint.Client.ClientRuntimeContext))]
public partial interface IClientRuntimeContext
{
}
}
@@ -0,0 +1,8 @@
namespace ProxyInterfaceConsumer.PnP
{
[ProxyInterfaceGenerator.Proxy(typeof(Microsoft.SharePoint.Client.SecurableObject))]
public partial interface ISecurableObject : IClientObject
{
// public virtual void X();
}
}
@@ -1,7 +1,7 @@
namespace ProxyInterfaceConsumer.PnP
{
[ProxyInterfaceGenerator.Proxy(typeof(Microsoft.SharePoint.Client.Web))]
public partial interface IWeb
public partial interface IWeb: ISecurableObject
{
}
}
@@ -0,0 +1,14 @@
using Microsoft.SharePoint.Client;
using ProxyInterfaceConsumer.PnP;
namespace ProxyInterfaceConsumerForPnP
{
public class Program
{
public static void Main()
{
var cp = new ClientContextProxy(new ClientContext("https://heyenrath.nl"));
cp.Test();
}
}
}
@@ -0,0 +1,49 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<OutputType>Exe</OutputType>
<LangVersion>9</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="IPersonTT.cs" />
<Compile Remove="PersonTT.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="Mapster" Version="7.3.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="3.10.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.10.0" />
<PackageReference Include="PnP.Framework" Version="1.10.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ProxyInterfaceSourceGenerator\ProxyInterfaceSourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
<ItemGroup>
<Compile Update="PnP\ISecurableObject.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Compile>
<Compile Update="PnP\IClientObject.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Compile>
<Compile Update="PnP\IWeb.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Compile>
<Compile Update="PnP\IClientContext.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Compile>
<Compile Update="PnP\IClientRuntimeContext.cs">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Compile>
</ItemGroup>
</Project>