Tag: postsharp

无法解析对程序集“PostSharp”的依赖性,因为它尚未预加载

我的项目结构 A.dll,它通过NuGet安装PostSharp并使用它。 B.exe,引用A并且不使用PostSharp。 编辑:我创建了一个测试解决方案,看看我是否可以重新创建问题,并且错误消失了,所以它似乎是原始项目中的其他构建时进程。 我还不知道是什么。 我的问题 目前这会导致B的编译错误。 未知的构建错误,’无法解析对程序集的依赖关系’PostSharp,Version = 3.0.40.9,Culture = neutral,PublicKeyToken = b13fd38b8f9c99d7’因为尚未预加载。 使用ReflectionOnly API时,必须通过ReflectionOnlyAssemblyResolve事件按需预加载或加载相关的程序集。 将PostSharp安装到B会导致新警告。 模块“B.exe”不包含任何方面或其他转换。 为了提高构建时性能,请考虑通过在项目中设置编译符号(aka constant)’SkipPostSharp’来禁用此模块的PostSharp,或者设置MSBuild属性’SkipPostSharp = True’。 如果我在项目属性中禁用PostSharp,我现在会收到此错误。 #error:’构建过程中未引入PostSharp。 如果NuGet刚刚恢复了PostSharp软件包,则需要重建解决方案。 它来自RequiresPostSharp.cs,它安装在每个PostSharp项目中。 我的目标 我需要消除所有错误和警告。 我建议的解决方案 我想如果我能消除第一个错误并且需要将PostSharp添加到B,一切都会好的。 我不知道怎么解决它。 我的问题 正确/推荐的解决方案是不将PostSharp安装到B,并修复第一个错误? 如果是这样,我该怎么做? 如果没有,我将如何找到合适的解决方案?

如何在postsharp中为类中的所有方法创建方面检查空引用

如何在postsharp中为类中的所有方法创建方面检查空引用。 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace test { [MethodParameterNullCheck] internal class Class { public Class() { } public void MethodA(int i, ClassA a, ClassB b) { //Some business logic } } } 然后,方面[MethodParameterNullCheck]应展开到以下代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace test { [MethodParameterNullCheck] internal class Class { public Class() […]

使用PostSharp跟踪属性更改

我想在所有前面的页面有效时启用给定的向导页面。 这是我的视图模型: [Aggregatable] [NotifyPropertyChanged] [ContentProperty(“Pages”)] public class Wizard { [Child, AggregateAllChanges] public AdvisableCollection Pages { get; } = new AdvisableCollection(); } 这是Page本身: [Aggregatable] [NotifyPropertyChanged] public class Page : INotifyPropertyChanged { [Parent] Wizard Wizard { get; set; } public string Name { get; set; } public bool Valid { get; set; } [SafeForDependencyAnalysis] public bool Enabled […]

如何使用自定义属性为C#Auto-Property提供默认值?

如何使用自定义属性为C#Auto-Property提供默认值? 这是我想看到的代码: class Person { [MyDefault(“William”)] public string Name { get; set; } } 我知道没有内置方法来使用属性初始化默认值 – 我可以编写自己的自定义类来使用我的自定义属性来初始化默认值吗?

如何确定在构建或运行时是否使用PostSharp方面修饰了类

我有一系列表格的WCF服务 [WCFEndpoint] public class MyWCFEndpoint : WCFSvcBase, IMyWCFEndpoint { } 其中WCFEndpoint是PostSharp OnMethodBoundaryAspect: [Serializable] public class WCFEndpointAttribute : OnMethodBoundaryAspect { } [WCFEndpoint]的主要目的是通过OverEntry和OnExit的覆盖以及其他诊断信息提供有关WCF调用的持续时间信息。 问题是开发人员偶尔忘记将[WCFEndpoint]添加到新的WCF服务(编辑:和其他开发代码评论的开发人员忘记提及它!)。 我的目标是保证从WCFSvcBase派生的每个类都使用[WCFEndpoint]属性进行修饰。 我的计划是编写一个自动(NUnit)测试来查找从WCFSvcBase派生的所有类,然后查看自定义属性并确认WCFEndpointAttribute在该集合中(为便于阅读而简化): Assembly assm = Assembly.GetAssembly(typeof(ReferenceSvc)); Type[] types = assm.GetTypes(); IEnumerable serviceTypes = types.Where(type => type.IsSubclassOf(typeof(WCFSvcBase)) && !type.IsAbstract ); foreach (Type serviceType in serviceTypes) { if (!serviceType.GetCustomAttributes(true).Any(x => x.GetType() == typeof(WCFEndpointAttribute))) { Assert.Fail( […]

PostSharp AssemblyLoadException Autofac

我正在建立一个新的解决方案,我想使用最新的Autofac(3.4)和PostSharp 3.1.42。 在引用NuGet包后,我得到以下错误,我无法弄清楚发生了什么。 我从未选择过Autofac 3.3.0软件包。 packages.config: MSBuild日志: Error 3 Unhandled exception (3.1.43.0, 32 bit, CLR 4.5, Release): PostSharp.Sdk.CodeModel.AssemblyLoadException: Cannot find assembly ‘autofac, version=3.3.0.0, culture=neutral, publickeytoken=17863af14b0044da’. [Version mismatch] ============ PostSharp Assembly Loading Log =================== LOG: Finding the assembly with binding identity ‘autofac, version=3.3.0.0, culture=neutral, publickeytoken=17863af14b0044da’. LOG: Found file ‘D:\web\Project\packages\Autofac.3.4.0\lib\net40\Autofac.dll’ with identity ‘autofac, version=3.4.0.0, culture=neutral, publickeytoken=17863af14b0044da, processorarchitecture=msil’. […]

如何从json序列化中排除特定类型

我正在将对WCF Web服务的所有请求(包括参数)记录到数据库中。 这就是我这样做的方式: 创建一个类WcfMethodEntry,它派生自PostSharp的方面OnMethodBoundaryAspect, 使用WcfMethodEntry属性注释所有WCF方法, 在WcfMethodEntry中,我使用JsonConvert.SerializeObject方法将方法参数序列化为json并将其保存到数据库中。 这工作正常,但有时参数非常大,例如一个自定义类,带有几个带有照片,指纹的字节数组等。我想从序列化中排除所有这些字节数组数据类型,这将是最好的方法做到了吗? 序列化json的示例: [ { “SaveCommand”:{ “Id”:5, “PersonalData”:{ “GenderId”:2, “NationalityCode”:”DEU”, “FirstName”:”John”, “LastName”:”Doe”, }, “BiometricAttachments”:[ { “BiometricAttachmentTypeId”:1, “Parameters”:null, “Content”:”large Base64 encoded string” } ] } } ] 期望的输出: [ { “SaveCommand”:{ “Id”:5, “PersonalData”:{ “GenderId”:2, “NationalityCode”:”DEU”, “FirstName”:”John”, “LastName”:”Doe”, }, “BiometricAttachments”:[ { “BiometricAttachmentTypeId”:1, “Parameters”:null, “Content”:”…” } ] } } ] 编辑:我不能更改用作Web服务方法的参数的类 – 这也意味着我不能使用JsonIgnore属性。

PostSharp替代

我只是想了解PostSharp,说实话,我认为这太棒了。 但有一件事我很难在PostSharp方面无法完成纯dependency injection(不是服务定位器),也许是因为编译时编织的结果。 来自PHP背景,Symfony有JMSAopBundle ,它仍然允许dependency injection它的拦截器。 .Net有一些具有相同function的库吗? 或者我错过了PostSharp的东西?

如何在C#中使用System.Reflection.MethodBase找到方法的返回类型?

如何从MethodBase中找出方法的返回类型? 我正在使用PostSharp并尝试覆盖CompileTimeValidate(MethodBase方法)方法以确保该属性应用于具有正确签名的方法。 谢谢,

如何从PostSharp中的另一个方面调用注入的方法

我正在尝试使用PostSharp在学校应用程序上实现Observer模式。 情况如下:每次进行更改时,我都有一个存储库,我想通知每个TesterForm(允许在存储库中操作数据的表单)。 这是我想用来将Observable部分添加到我的存储库的方面: [Serializable] class ObservableAspect : InstanceLevelAspect { [IntroduceMember] List LT; [IntroduceMember] public void notifyChange() { foreach (TesterForm x in LT) { x.refreshListBoxBuguri(); } } [IntroduceMember] public void Subscribe(TesterForm t) { LT.Add(t); } } 然后,此方面应用于存储库中更改数据的每个方法: [Serializable] class ObservableNotify : OnMethodBoundaryAspect { public override void OnExit(MethodExecutionArgs args) { ((Repository)args.Instance).notifyChange(); } } 然后将此方面应用于我的TesterForm构造函数,以便它在创建后立即订阅到我的存储库: class ObserverAspect : […]