How do I create a pointcut to intercept all methods in a class with PostSharp? - postsharp

I've tried using AttributeTargetTypes, but it just won't work. What am I missing?

The easiest way to apply an aspect to all methods of a class is to annotate this class with the aspect custom attribute. AttributeTargetTypes, when the custom attribute is applied on assembly-level, should work also, at least if the type is a part of the current assembly.

Related

Swift - what should the default values of properties be in the parent class?

Not sure if I worded this question correctly, but here's my issue: I have a base class and a subclass, and my base class should never be instantiated on its own (in other languages it would be abstract). I know abstract classes aren't a thing in Swift. I have some computed read-only properties that change what they return in each subclass; they are more or less customized constants. Firstly, are overridden computed properties the best way to handle this kind of thing? Secondly, if these variables need to get initialized, i.e. can't be nil, what should they be initialized to in the parent class? Is there a way to otherwise indicate that the parent class shouldn't be initialized on its own?
You probably should use protocol instead of base class in your case. All common implementation can be done in protocol extensions and you won't need to provide default values for constants - just specify required get methods in the protocol.

inheriting from MATLAB graphics objects

I need to create subclass of the Patch object's class in MATLAB 2014b but MATLAB does not allow me to do so:
Class 'matlab.graphics.primitive.Patch' is Sealed and may not be used as a superclass.
Is there a hack around this?
No - you can't subclass a class that is Sealed, and matlab.graphics.primitive.Patch is a built-in class, so you can't make a (hack) edit to unseal it.
The best you can do is to use an Adapter pattern - create your own class, storing a Patch as a private (and maybe hidden) property, and then wrap all its properties and ones of your own, implementing set and get methods that pass through the value to/from the underlying Patch. Do something similar for any methods of Patch that you need. You may also need to listen to property change events on the Patch and respond to them appropriately.
Then you can add your own methods as well, and/or modify the existing method and property behavior as required.
No. If the class is sealed, it shall not be derived from. There are probably good reasons why it has been chosen to be sealed; other classes may assume a particular implementation which you can override if you were to inherit from the class.

Intersystems caché - programmatically create new class

Is it possible to write ObjectScript method, which will create new class in namespace and compile it? I mean programmatically create new class and store it. If so, can I edit this class using ObjectScript later(and recompile)?
Reason: I have class structure defined in string variable and I need to add new class to namespace according this string.
Nothing is impossible. Everything in Caché can be created programmatically. And, Classes is not a execution. There are at least two ways to do it:
simple SQL Query CREATE TABLE, will create a class.
and as you already mentioned ObjectScript Code, which can do this.
All of definition of any classes defined in other classes. Which you can find in package %Dictionary.
The class itself defined in %Dictionary.ClassDefinition. Which have some properties, for defining any parts of classes. So, this is a simple code which create some class, with one property.
set clsDef=##class(%Dictionary.ClassDefinition).%New()
set clsDef.Name="package.classname"
set clsDef.Super="%Persistent"
set propDef=##class(%Dictionary.PropertyDefinition).%New()
set propDef.Name="SomeProperty"
set propDef.Type="%String"
do clsDef.Properties.Insert(propDef)
do clsDef.%Save()
And in latest versions, there is one more way for create/change class. If you have text of class as you can see it in Studio. Then, you can load it in Caché, with class %Compiler.UDL.TextServices
Yes, it is. You likely want to make use of %Dictionary.ClassDefinition and the related %Dictionary.*Definition classes (especially %Dictionary.PropertyDefinition, %Dictionary.MethodDefinition and %Dictionary.IndexDefinition) to create and/or modify your class. Provided your string contains some reasonable representation of the data, you should be able to create the class this way.
The actual class documentation is available at http://docs.intersystems.com/cache20141/csp/documatic/%25CSP.Documatic.cls?CLASSNAME=%25Dictionary.ClassDefinition
You can then compile the class by calling $system.OBJ.Compile("YourPackage.YourClass","ck").
(Note: If your string contains the exported XML definition of the class, you could also write the XML representation to a stream and then call $system.OBJ.LoadStream() to import the XML definition. I would only recommend this if you have an exported class definition to start with.)

Remoting references by wrapping them in a MarshalByRefObject? Will it work?

I'm trying to implement a plugin system using MAF. The objects I want to pass currently aren't serializable though, and even though I'm sure I could make them serializable I don't think it would be very performant.
Two questions:
1) In order for MAF to pass the actual references across, does an object simply need to inherit from MarshalByRefObject or is there more to it than that?
2) Could I wrap my class in an object that inherits from MarshalByRefObject to get the reference across?
EDIT: Obviously the problem itself has little to do with MAF, but I just wanted to include some context in case someone could point me in an altogether direction to go.
1) Yes, it just needs to inherit from MarshalByRefObject, but any public types inside the class also need to be serializable or inherit from MarshalByRefObject as well.
2) No, this just pushes the problem back since the class still needs to be serializable or inherit from MarshalByRefObject.

Adding a method to a class that is from a referenced library (JUNG)

I want to add a method to the Graph class of the JUNG library using Eclipse. How would I do this?
I have the JUNG working correctly as a reference library by following this answer: https://stackoverflow.com/a/5618076/1949665
1) You have access to the source:
Simply add your method
2) You could extend the class and add the method in our extending class
3) Write a Util class with a static method implementing your method than simply uses the original class.
Your comment above implies that you want to be able to find cliques in a graph. (I didn't see the original question before you edited it.)
If so, it doesn't need to be a method on Graph itself, it just needs to accept a Graph as an argument. Graph is a type like List or Map, it should not have a method for every kind of algorithm you might want to use on a graph.