����λ�ã���ҳ > �����̳� > �̳� > c# 12 ʵ������Interceptor ��ʲô��
һֱ�кܶ�ת��dotnet��Interceptor˵���ĵ��ģ�������˵��Interceptor���ʹ�õģ�����дһƪ��ʾ����չʾһ�� c# 12 ʵ������Interceptor ��ʲô�� �ٷ��������£���ʵ��˵�����������������õľ�̬��֯��ʽ��aop���ܣ���ͬ������il�޸Ĵ���ķ�ʽ��ʹ���ϵý�
��dotnet�����У���Ȼ�кܶ����Interceptor��ת��˵���ĵ����������й���Interceptor���ʹ�õ���ϸ˵�������Ľ�ͨ��һ����ʾ����չʾInterceptor��ʹ�÷�����
Interceptor��һ�����õľ�̬��֯��ʽ��aop���ܣ�������il�޸Ĵ���ķ�ʽ��ͬ���������ڱ���ʱ��������ʽ���Կ����ط����ĵ����滻Ϊ���������ĵ��á�ͨ�������������������ص��õ�Դλ�ã����Խ��������滻������������������У�������Դ�������У������´��룬�Ӷ��ṩ�������д������������������
��Դ��������ʹ���������޸����б���Ĵ��룬�������������Ӵ��롣Դ���������Կ����ط����ĵ����滻Ϊ�������������ĵ��á�
���������Ȥ�����������������Ķ����ܹ淶���˽���ϸ��Ϣ�����ʹ�øù��ܣ���ȷ����ʱ�˽��ʵ�鹦�ܵĹ��ܹ淶�е��κθ��ġ�����ȷ�����ܺ���΢���ĵ�վ�������Ӹ���ָ����
����������һ���򵥵� static method ��Ϊ���Ǹ�д�������ݵ�Ŀ�ꡣ
public static partial class DBExtensions
{
public static string TestInterceptor(object o)
{
return o.GetType().ToString();
}
}
�����ľ�̬���������Ǽ����д��Ŀ��Ϊ����o����������һ��string���͵�����ֵ��
����Ӧ�ÿ���ͨ�����µ� UT ������
[Fact]
public void CallNoError()
{
Assert.Equal("sss", DBExtensions.TestInterceptor(new { A = "sss", C= "ddd" }));
}
����һ�� netstandard2.0 ����Ⲣ�������£�
netstandard2.0
preview
true
false
Generated Ŀ¼���ɴ����ļ���ʵ�ǷDZ���ģ�����Ϊ�˷����ҿ��� source generater ���ɵĴ����ļ����ݣ��������dz��γ���source generater���а�����
net8.0
enable
enable
false
true
Generated
$(InterceptorsPreviewNamespaces);Test.AOT
[Generator(LanguageNames.CSharp)]
public class InterceptorGenerator : IIncrementalGenerator
{
}
�����
IIncrementalGenerator
Ϊsource generater��ǿ��Ƶ�һ���ӿڣ��и�ǿ�����ܺ͸����������������������ʵ�ֽӿڡ�
[Generator(LanguageNames.CSharp)]
public class InterceptorGenerator : IIncrementalGenerator
{
public void Initialize(IncrementalGeneratorInitializationContext context)
{
var nodes = context.SyntaxProvider.CreateSyntaxProvider(FilterFunc, TransformFunc).Where(x => x is not null).Select((x, _) => x!);
var combined = context.CompilationProvider.Combine(nodes.Collect());
context.RegisterImplementationSourceOutput(combined, Generate);
}
}
����������ʵ��
FilterFunc
��
private bool FilterFunc(SyntaxNode node, CancellationToken token)
{
if (node is InvocationExpressionSyntax ie && ie.ChildNodes().FirstOrDefault() is MemberAccessExpressionSyntax ma)
{
return ma.Name.ToString().StartsWith("TestInterceptor");
}
return false;
}
����������ʵ��
TransformFunc
��
private TestData TransformFunc(GeneratorSyntaxContext ctx, CancellationToken token)
{
// ʵ�ִ���
}
����������ʵ��
Generate
��
private void Generate(SourceProductionContext ctx, (Compilation Left, ImmutableArray Right) state)
{
// ʵ�ִ���
}
������DZ�����򣬾ͻῴ���������������ļ����롣
// ���ɵĴ���
�������ut�����Ҳ��ȷ��debug���е���Ҳ�ɿ����ϵ��ܽ����������ɵĴ����ļ��С�
С���Ƽ��Ķ�ʹ��Blender���ɳ���ģ��
�Ķ�ȫ����������ERA5�����ط���
�Ķ�Xpath���������﷨
�Ķ�����ѧϰ�������繹�����£�
�Ķ���ΪMateƷ��ʢ�䣺HarmonyOS NEXT�ӳ�����Ϸ���ܵõ�����ͷ�
�Ķ�ʵ�ֶ��󼯺���DataTable���໥ת��
�Ķ�Ӳ�̵Ļ���֪ʶ��ѡ��ָ��
�Ķ�������й��ƶ��ı�ͼ��ײ�
�Ķ�����NEXTԪ�����������ѿ����ϼ���Ʒ
�Ķ��ᳲ���С������������Ƽ��رշ���
�Ķ������ArcMap�����н���դ��ͼ���ز�������
�Ķ��㷨�����ݽṹ 1 - ģ��
�Ķ���Ѷ�����߿ͷ���Ӫ��ϵͳ����
�Ķ���Ѷ��Ƶҹ��ģʽ���ý̳�
�Ķ����ں���NEXT��Ѫ���Ŵ���������������
�Ķ�5. Spring Cloud OpenFeign ����ʽ WebService �ͻ��˵ij���ϸʹ��
�Ķ�Java����ģʽ����̬�����Ͷ�̬�����ĶԱȷ���
�Ķ�Win11�ʼDZ����Զ�����Ӧ�õ���ɫ����ʾ����
�Ķ�˼�� V1.5.6 ��׿��
��ս�귨 V7.5.0 ��׿��
У��������������׵������� V1.0 ��׿��
��˸֮�� V1.9.7 ��׿��
������Ե����� v1.0.4 ��׿��
������֮ŠV5.2.3 ��׿��
��������������Դ V1.0 ��׿��
���֮Ϣ V1.0 ��׿��
��ħ������������䣩 V1.0 ��׿��
���ں�������ϵ�����������������վ�����������������Ƽ�����
Ƶ�� ����Ƶ��������ר������������׿�������app����
�Ƽ� ��Ô���������°��������ܿ������ز���
���� ����ɫ������������ ���������ս������������
ɨ��ά�����������ֻ��汾��
ɨ��ά����������΢�Ź��ںţ�
��վ�������������������ϴ��������ַ���İ�Ȩ���뷢�ʼ�[email protected]
��ICP��2022002427��-10 �湫��������43070202000427��© 2013~2025 haote.com ������