Cool PostSharp aspects [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm looking for interesting PostSharp aspects - anything that you found useful and wouldn't mind sharing.

The coolest aspect of it for me is that it can help me implement the single responsibility principle:
"In object-oriented programming, the single responsibility principle states that every object should have a single responsibility, and that all its services should be narrowly aligned with that responsibility."
I hope to adopt this more fully with more experience in the future, but for now, I have just started with having it built in to my logging needs:
together with Log4PostSharp, I can do:
[Log(LogLevel.Info, "Counting characters.")]
int CountCharacters(string arg) {
return arg.Length;
}
What this means is that, the responsibility of logging is ascribed elsewhere (coding wise), and injected from a separate source by PostSharp and Log4PostSharp magic.

D. Patrick Caldwell has some cool ideas on his blog.
Validate Parameters Using Attributes and PostSharp
http://dpatrickcaldwell.blogspot.com/2009/03/validate-parameters-using-attributes.html
Implmementing Coding Contracts using PostSharp.
Memoizer Attribute Using PostSharp
http://dpatrickcaldwell.blogspot.com/2009/02/memoizer-attribute-using-postsharp.html
Basically, a light-weight field-value caching mechanism.

Daft question, but isn't that the purpose of the Contributions Directory?
There is an example of automatic property-change implementation - INotifyPropertyChanged.

Related

difference between EF and Entity-SQL when working with .net core [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I am beginner to .net core. And I am working on an enterprise application where there are multiple classes interfaces for multiple project inside a one solution. i know Entity Framework won't be a good idea if we are facing huge number of wrappers. But indeed its giving me efficiency of coding. On the other side of it Entity SQL has its own benefits.
But still want to really understand the best practice and which one to implement when it comes to Enterprise application knowing it will have number of classes, Data filtration, Generic Types, Flexibility, performance vise when querying DB.
Looking forward to get some really helpful understanding from experts. Thanks in advance.
TL;DR;
The "best practices" depends on the use case. Its a set of tools, not a silver bullet.
Sometimes EF works for your case, sometimes not. Sometimes you want a monolith, sometimes you dont.
Try, experiment fail and succeed.
Best practices regarding to techniques are irrelevant; implementation change all the time. So;
define functional requirements
define none functional requirements
do a PoC with some relevant loads etc.
At enterprise level consider these additional properties:
security
operational functionality
cloud / none-cloud
This is the best I can do, given your question.
Explain the case and we could give some direction; but its not a template fitted for all cases.

Modify method logic MOQ [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am new to unit testing so my questions might seem basic, apologies for that.
I am trying to figure out if there is such API in MOQ that can help me to modify a method logic.
I mean,
When calling . I want to increase lets say my "count" variable by 1 and then call the method or do something else, doesn't really matter.
There is no code yet, this is a principle question. Could not find it in the MOQ Documentation on GitHub.
Hope I was clear and you can help me with that.
Thank you!
You can't 'modify' the method logic per se, but you can replace it entirely.
When you create a mock of an interface, you aren't instantiating a specific concrete type of that interface. Instead, you are allowing your mocking framework to create a 'mock' version of that interface; an object which, by default, has no functionality but requires no work to instantiate.
The easiest way to do this is to use Moq's Setup functionality, which is explained well here:
https://github.com/Moq/moq4/wiki/Quickstart

Why would you need to emit IL code? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I work in a code base that is quite large and today I found a project that was emitting IL code inside a normal class.
The project containing the IL code being emitted was a implementation of a Service Locator MSDN Desctiption.
What are the advantages of doing this and why would this be done as apposed to using the C# language?
Typically this is done to circumvent the overhead of using reflection, using information only available at runtime.
You would then use reflection, which can be slow depending on what you do, to build a new piece of code that works directly with the data given to it, without using reflection.
Advantages:
Performance
Disadvantages:
Hard to debug
Hard to get right
Hard to read code afterwards
Steep learning curve
So you need to ensure it's really worth the price before embarking on this.
Note that this is a general answer. In the specific case you came across, there is no way to answer why this was done nor which particular advantages (or disadvantages) you would have without actually seeing the code.
There are many uses for this.
One of the more often used scenario is for changing/injecting code on the fly:
.NET CLR Injection: Modify IL Code during Run-time
A good tutorial that help me to understand a good use for it is:
Dynamic... But Fast: The Tale of Three Monkeys, A Wolf and the DynamicMethod and ILGenerator Classes
Good luck

How come there's no C# equivalent of python's doctest feature? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
Seems like it would be a good way to introduce some people to unit testing.
Well for one thing, the documentation for doctest talks about "interactive Python sessions". There's no equivalent of that in C#... so how would the output be represented? How would you perform all the necessary setup?
I dare say such a thing would be possible, but personally I think that at least for C#, it's clearer to have unit tests as unit tests, where you have all the benefits of the fact that you're writing code rather than comments. The code can be checked for syntactic correctness at compile-time, you have IntelliSense, syntax highlighting, debugger support etc.
If you're writing code, why not represent that as code? Admittedly it's reasonably common to include sample code in XML documentation, but that's rarely in the form of tests - and without an equivalent of an "interactive session" it would require an artificial construct to represent the output in a testable form.
I'm not saying this is a bad feature in Python - just that it's one which I don't believe maps over to C# particularly well. Languages have their own styles, and not every feature in language X will make sense in language Y.

What is COM+? What is equivalent for COM+ in .Net? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
What is COM+? What is equivalent for COM+ in .Net?
COM+ was Microsoft's offering in the battle for the middle tier that raged in the late nineties. A set of extensions built on top of COM with typical middleware duties like componentizing modules across machines and getting them to work together in a transaction-safe way. CORBA was another one, now also largely forgotten.
The only thing it really accomplished was to make Java a significant force.
ServicedComponent http://msdn.microsoft.com/en-us/library/7c05y13x(VS.71).aspx
Right here on wikipedia. Has a section on .Net
Component Object Model
There is no equivalent in .Net as you can still use COM+ in .Net but there are better ways of achieving the same thing.
COM Interop used to be a rather dangerous, if not overly-hyped feature.
Why dangerous? It used to collect and dispose of live com pointers, thus pulling the rug right out from under you. Oh my, it was so much fun. It could be fixed by now I would hope.

Categories