public void Intercept(IInvocation invocation) { if (invocation.Method.Name.StartsWith("set_") || invocation.Method.Name.StartsWith("get_")) { var propertyName = invocation.Method.Name.Split(new char[] { '_' }, 2)[1]; if (MaskedProperties.Contains(propertyName)) { invocation.ReturnValue = invocation.Method.ReturnType.IsValueType ? Activator.CreateInstance(invocation.Method.ReturnType) : null; return; } if (invocation.Method.Name.StartsWith("get_") && ReplaceProperties.ContainsKey(propertyName)) { invocation.ReturnValue = ReplaceProperties[propertyName]; return; } } invocation.Proceed(); }
public void Intercept(IInvocation invocation) { if (invocation.Method.Name.StartsWith("set_") || invocation.Method.Name.StartsWith("get_")) { var propertyName = invocation.Method.Name.Split(new char[] { '_' }, 2)[1]; if (MaskedProperties.Contains(propertyName)) { invocation.ReturnValue = invocation.Method.ReturnType.IsValueType ? FormatterServices.GetUninitializedObject(invocation.Method.ReturnType) : null; return; } if (invocation.Method.Name.StartsWith("get_") && ReplaceProperties.ContainsKey(propertyName)) { invocation.ReturnValue = ReplaceProperties[propertyName]; return; } } invocation.Proceed(); }