Naming Conventions For Partial Class Files

I use . separation – for example EmployeeController.SomeSpecialBehaviour.cs. I also link it into the project tree via “dependentUpon” or whatever it is in the csproj, so that it nests under the file (in solution explorer) neatly. You have to do that by hand (edit the csproj) or with an addin, though; for example: <Compile Include=”Subfolder/Program.cs” … Read more

Can’t access Parent’s Members while dealing with Macro Annotations

Trees that go into macro annotation arguments are purposefully untyped. However running c.typeCheck(q”(??? : <tree that represents the parent>)”).tpe will provide the missing information. Don’t forget to duplicate that tree before typechecking, because c.typeCheck mutates the tree in place, which might be undesireable. In case when both parent and child are declared in the same … Read more

How can I add my attributes to Code-Generated Linq2Sql classes properties?

You can take advantage of the new Metadata functionality in the System.ComponentModel.DataAnnotations which will allow us to separate the MetaData from the existing domain model. For example: [MetadataType (typeof (BookingMetadata))] public partial class Booking { // This is your custom partial class } public class BookingMetadata { [Required] [StringLength(15)] public object ClientName { get; set; … Read more

How to emit and execute Java bytecode at runtime?

Here is a working “hello world” made with ObjectWeb ASM (a library which I recommend): package hello; import java.lang.reflect.Method; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; public class HelloWorldASM implements Opcodes { public static byte[] compile(String name) { ClassWriter cw = new ClassWriter(0); MethodVisitor mv; cw.visit(V1_6, ACC_PUBLIC + ACC_SUPER, “hello/HelloWorld”, null, “java/lang/Object”, null); cw.visitSource(“HelloWorld.java”, … Read more

Can I define properties in partial classes, then mark them with attributes in another partial class?

Here is the solution I have been using for such cases. It is useful when you have auto-generated classes that you want to decorate with attributes. Let’s say this is the auto-generated class: public partial class UserProfile { public int UserId { get; set; } public string UserName { get; set; } public string Firstname … Read more