This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Serializable] | |
| [MulticastAttributeUsage(MulticastTargets.Method, TargetMemberAttributes = MulticastAttributes.Public)] | |
| public class ServiceErrorInterceptor : MethodInterceptionAspect | |
| { | |
| public override bool CompileTimeValidate(MethodBase method) | |
| { | |
| if (!typeof (ServiceBase).IsAssignableFrom(method.DeclaringType)) | |
| { | |
| var declaringType = method.DeclaringType; | |
| var declaringTypeName = "Unknown"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public override void OnInvoke(MethodInterceptionArgs args) | |
| { | |
| try | |
| { | |
| args.Proceed(); | |
| } | |
| catch (SqlException ex) | |
| { | |
| var obj = (ServiceBase) args.Instance; | |
| if (ex.Message.Contains("The DELETE statement conflicted with the REFERENCE constraint")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void ErrorReturn(MethodInterceptionArgs args) | |
| { | |
| try | |
| { | |
| var methodInfo = args.Method as MethodInfo; | |
| if (methodInfo == null) | |
| return; | |
| if (methodInfo.ReturnType == typeof(string)) // if it's string, just return a null | |
| args.ReturnValue = null; | |
| else if (typeof(IEnumerable).IsAssignableFrom(methodInfo.ReturnType)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void OnInvoke(MethodInterceptionArgs args) | |
| { | |
| try | |
| { | |
| args.Proceed(); | |
| } | |
| catch (Exception ex) | |
| { | |
| // ... snip ... | |
| ErrorReturn(args); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public ActionResult MyAction() | |
| { | |
| var listResults = _service.GetAllResults(); // an exception here gets logged, but execution continues | |
| var model = new MyViewModel(); | |
| model.NumResults = listResults.Count; // listResults is null, NullReferenceExcpetion here | |
| return View(model); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var sb = new System.Text.StringBuilder(468); | |
| sb.AppendLine(@"One of my favorite VS extensions is SmartPaster. Often when I'm pasting something into Visual Studio, I'm pasting it into C# source code. It could be a long directory name, a JSON string, or some sort of template that's going into a StringBuilder. Doing this with plain copy/paste can be tedious."); | |
| sb.AppendLine(@""); | |
| sb.AppendLine(@"Instead, just install SmartPaster. You'll get a new right-click menu option: ""Paste As"", which lets you paste text as a literal string, a comment, or as a StringBuilder."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class IoC { | |
| public static IContainer Initialize() { | |
| ObjectFactory.Initialize(x => | |
| { | |
| x.Scan(scan => | |
| { | |
| scan.TheCallingAssembly(); | |
| scan.WithDefaultConventions(); | |
| }); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This is StructureMap 2.x | |
| using StructureMap; | |
| public static class IoC { | |
| public static IContainer Initialize() { | |
| ObjectFactory.Initialize(x => | |
| { | |
| // ... snip ... | |
| x.For<IDbConnection>().HttpContextScoped().Use(GetConnection); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // each entity uses this as a base | |
| // different entities have different types of keys (guids, string, ints typically) | |
| public class EntityBase<T> : IEntity<T> | |
| { | |
| public T Id { get; set; } | |
| } | |
| public class SomeEntity : EntityBase<int> | |
| { | |
| public string Foo { get;set;} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "../../../packages/FluentMigrator.1.1.2.1/tools/Migrate.exe" /conn "Data Source=(local);Initial Catalog=mydatabasename;uid=;pwd=;Trusted_Connection=yes;" /provider sqlserver2008 /assembly "myproject.migrations.dll" /verbose=true --task rollback --steps=%1 |