postsharp

How to use PostSharp to warn if a property is accessed before it has been initialized?

强颜欢笑 提交于 2020-01-15 09:08:10
问题 How would I use PostSharp to replace this: [WarnIfGetButUninitialized] public int MyProperty {get; set; } With this: /// <summary> /// Property which warns you if its value is fetched before it has been specifically instantiated. /// </summary> private bool backingFieldIsPopulated = false; private int backingField; public int MyProperty { get { if (backingFieldIsPopulated == false) { Console.WriteLine("Error: cannot fetch property before it has been initialized properly.\n"); return 0; }

How to use PostSharp to warn if a property is accessed before it has been initialized?

∥☆過路亽.° 提交于 2020-01-15 09:07:25
问题 How would I use PostSharp to replace this: [WarnIfGetButUninitialized] public int MyProperty {get; set; } With this: /// <summary> /// Property which warns you if its value is fetched before it has been specifically instantiated. /// </summary> private bool backingFieldIsPopulated = false; private int backingField; public int MyProperty { get { if (backingFieldIsPopulated == false) { Console.WriteLine("Error: cannot fetch property before it has been initialized properly.\n"); return 0; }

Postsharp does not log on trace level

半城伤御伤魂 提交于 2020-01-14 14:33:09
问题 I like to log some Postsharp messages on trace level. Unfortunately logs to this level print no output. All other levels are working. Same behavior with console or NLog backend or when I log from an other class. How can I enable the trace level? App.xaml.cs: [Log(AttributeExclude = true)] public partial class App { private static readonly LogSource LogSource = LogSources.Default.ForCurrentType().WithLevels(LogLevel.Trace, LogLevel.Error); protected override void OnStartup(StartupEventArgs e)

Cannot resolve dependency to assembly 'PostSharp' because it has not been preloaded

Deadly 提交于 2020-01-14 09:07:12
问题 My project structure A.dll, which has PostSharp installed via NuGet and uses it. B.exe, which references A and does not use PostSharp. Edit: I created a test solution to see if I could recreate the issue, and the error went away, so it appears to be some other build-time process in the original project. I don't know yet what. My problem Currently this causes a compilation error for B. Unknown build error, 'Cannot resolve dependency to assembly 'PostSharp, Version=3.0.40.9, Culture=neutral,

Cannot resolve dependency to assembly 'PostSharp' because it has not been preloaded

一个人想着一个人 提交于 2020-01-14 09:04:07
问题 My project structure A.dll, which has PostSharp installed via NuGet and uses it. B.exe, which references A and does not use PostSharp. Edit: I created a test solution to see if I could recreate the issue, and the error went away, so it appears to be some other build-time process in the original project. I don't know yet what. My problem Currently this causes a compilation error for B. Unknown build error, 'Cannot resolve dependency to assembly 'PostSharp, Version=3.0.40.9, Culture=neutral,

PostSharp - OnExceptionAspect - Get line number of exception

别来无恙 提交于 2020-01-14 03:15:31
问题 I've created an aspect that catches exceptions and logs them. Pretty basic stuff, but I'm trying to beef it up a bit and provide better information in the logs than just dumping the stack trace will provide. I've already added the "standard PostSharp goodies" like method name, arguments, etc. Is it possible to ascertain the line number of the exception via PostSharp without dumping the stack trace or parsing it and getting line number? Thank you in advance. 回答1: Without getting the stack info

实现INotifyPropertyChanged-是否存在更好的方法?

こ雲淡風輕ζ 提交于 2020-01-07 01:52:33
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> Microsoft应该为 INotifyPropertyChanged 实现了一些简单的功能,例如在自动属性中,只需指定 {get; set; notify;} {get; set; notify;} {get; set; notify;} 我认为这样做很有意义。 还是有任何并发​​症要做? 我们自己可以在属性中实现“通知”之类的功能吗? 是否存在用于在您的类中实现 INotifyPropertyChanged 的优雅解决方案,或者唯一的方法是通过在每个属性中引发 PropertyChanged 事件。 如果不能,我们可以写一些东西来自动生成引发 PropertyChanged 事件的代码吗? #1楼 从.Net 4.5开始,终于有了一种简单的方法。 .Net 4.5引入了新的呼叫者信息属性。 private void OnPropertyChanged<T>([CallerMemberName]string caller = null) { // make sure only to call this if the value actually changes var handler = PropertyChanged; if (handler != null) { handler(this, new

PostSharp , PDB Debugging and Referenced Assemblies

倾然丶 夕夏残阳落幕 提交于 2020-01-06 04:20:27
问题 When using PostSharp with a Referenced Assembly with proper PDB info( checked with chkmatch), it seems strange that the debug info gets lost by VStudio build and post compile process and I get the following error by using chkmatch to compare the assembly after the vstudio build. Error: Debug information not found in the executable. So it doesn't step into for debugging into this assembly. Does Post Sharp properly writes back the Assemblies without destroying the PDB location offset info as I

Team City build fails after upgrade to VS 2010

£可爱£侵袭症+ 提交于 2020-01-06 02:53:06
问题 I have a project that currently compiles happily on my dev machine using VS 2010 (presumably using MSBUILD v4.0), but it fails under MSBUILD v3.5 in Team City (running on a VM based on Win 2003 server w/ .NET 2, 3.5 and 4 installed). This project is newly upgraded to 2010, and is now failing on the CI build. I've Googled this and tried everything obvious (plus a few things that didn't make sense) and nothing affects the outcome. The project fails with a sequence of errors like this: error

PostSharp not building on TeamCity: Cannot find assembly mscorlib

蓝咒 提交于 2020-01-05 07:18:43
问题 PostSharp will build on local dev machine, it will not build on the TeamCity server, the error is: unknown error PS0264: Cannot find assembly 'mscorlib, version=2.0.5.0, culture=neutral, publickeytoken=7cec85d7bea7798e'. Here is an excerpt from the build log: [13:38:22][PostSharp30] Merging assembly binding policy files. [13:38:22][PostSharp30] Executing "C:\ProgramData\PostSharp\5.0.43\bin.Release\postsharp-net40-x86-native.exe" <REMOVED SENSITIVE INFORMATION> [13:38:25][PostSharp30] unknown