/// <summary> /// /// </summary> /// <param name="targetElement"></param> /// <returns></returns> public IEnumerable <AspectInstance> ProvideAspects(object targetElement) { var t = (Type)targetElement; var props = t.GetFields(BindingFlags.SetField | BindingFlags.Instance | BindingFlags.NonPublic); if (props.Length == 0) { yield return(null); } var objectConstruction = new ObjectConstruction(typeof(DataContractAttribute)); var ns = Zieschang.Net.Projects.PostsharpAspects.Utilities.Utilities.GetContractNamespace(t); objectConstruction.NamedArguments.Add("Namespace", ns); var introduceDataContractAttribute = new CustomAttributeIntroductionAspect(objectConstruction); var introduceDataMemberAttribute = new CustomAttributeIntroductionAspect(new ObjectConstruction(typeof(DataMemberAttribute))); yield return(new AspectInstance(t, introduceDataContractAttribute)); foreach (var prop in props) { if (!prop.IsDefined(typeof(NoDataMemberAttribute), true)) { yield return(new AspectInstance(prop, introduceDataMemberAttribute)); } } }
/// <summary> /// Initializes a new instance of the <see cref="AbstractService"/> class. /// </summary> /// <param name="glassContext">The glass context.</param> /// <exception cref="System.NullReferenceException">Context is null</exception> protected AbstractService(Context glassContext) { GlassContext = glassContext; if (GlassContext == null) { throw new NullReferenceException("Context is null"); } var objectConstructionTasks = glassContext.DependencyResolver.ObjectConstructionFactory.GetItems(); _objectConstruction = new ObjectConstruction(objectConstructionTasks); var configurationResolverTasks = glassContext.DependencyResolver.ConfigurationResolverFactory.GetItems(); _configurationResolver = new ConfigurationResolver(configurationResolverTasks); var objectSavingTasks = glassContext.DependencyResolver.ObjectSavingFactory.GetItems(); _objectSaving = new ObjectSaving(objectSavingTasks); Profiler = NullProfiler.Instance; Initiate(glassContext.DependencyResolver); }
public IEnumerable <AspectInstance> ProvideAspects(object targetElement) { var constructorInfo = typeof(System.Runtime.CompilerServices.ExtensionAttribute).GetConstructor(Type.EmptyTypes); var objectConstruction = new ObjectConstruction(constructorInfo); var aspectInstance = new CustomAttributeIntroductionAspect(objectConstruction); yield return(new AspectInstance(targetElement, aspectInstance)); }
public IEnumerable <AspectInstance> ProvideAspects(object targetElement) { MethodBase targetMethod = (MethodBase)targetElement; ObjectConstruction contract = new ObjectConstruction(typeof(RequiredAttribute)); foreach (var parameterInfo in targetMethod.GetParameters()) { yield return(new AspectInstance(parameterInfo, contract)); } }
public IEnumerable <AspectInstance> ProvideImplementationAspects(object targetElement, ObjectConstruction aspectConstruction) { var type = targetElement as Type; if (type == null) { return(new AspectInstance[0]); } var list = new List <AspectInstance>(); // Implement interface list.Add(new AspectInstance(targetElement, new ObjectConstruction( "BFsharp.AOP.AddNotifyPropertyChangedAttribute, BFsharp.AOP.WP7"), new AspectConfiguration())); // Dependencies var dependencies = AspectHelper.AnalyzeDependenciesWP7(type); if (dependencies.Count > 0) { // Silverlight aspects do not support complex constructor parameters var x = from d in dependencies select d.Key + ":" + string.Join(",", d.Value.ToArray()); var param = string.Join(";", x.ToArray()); //var array = new string[]{"ab", "bc"}; var oc = new ObjectConstruction("BFsharp.AOP.DependentNotifyPropertyChangedAspect, BFsharp.AOP.WP7", param); list.Add(new AspectInstance(targetElement, oc, new AspectConfiguration())); } var dontNotifyAttributeName = "BFsharp.AOP.DontNotifyAttribute, BFsharp.AOP.WP7, Version=1.0.0.0"; var dontNotifyAttribute = Type.GetType(dontNotifyAttributeName); // Add setters const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly; foreach (var property in from p in ((Type)targetElement).GetProperties(bindingFlags) where p.CanWrite && !p.IsDefined(dontNotifyAttribute, true) select p) { var getter = property.GetGetMethod(true); if (getter.IsPublic) { list.Add(new AspectInstance(property, new ObjectConstruction( "BFsharp.AOP.AddSetterNotifyPropertyChangedAttribute, BFsharp.AOP.WP7"), new AspectConfiguration())); } } return(list); }
public void WhenHasInternalConstructor_WithParam_ThenReturnInstance() { var parameters = new Dictionary <Type, object> { { typeof(int), 10 } }; var result = ObjectConstruction.ConstructNonPublic <TestClassInternalWithParamConstructor>(parameters); Assert.That(result.Value, Is.EqualTo(10)); }
public void WhenNoMatchingContructorFound_ThenThrowException() { var parameters = new Dictionary <Type, object> { { typeof(string), "Hello World" } }; var ex = Assert.Throws <InvalidOperationException>(() => ObjectConstruction.ConstructNonPublic <TestClassPrivateConstructor>(parameters)); Assert.That(ex.Message, Is.EqualTo("No matching constructor could be found.")); }
protected IEnumerable <AspectInstance> GetDisplayAttributes(IEnumerable <PropertyInfo> properties) { return(properties. Where(property => property.GetCustomAttribute <DisplayAttribute>() == null). Select(property => { var attribute = new ObjectConstruction(typeof(DisplayAttribute).GetConstructor(Type.EmptyTypes)); attribute.NamedArguments["Name"] = property.Name; attribute.NamedArguments["ResourceType"] = _resourceType; return new AspectInstance(property, new CustomAttributeIntroductionAspect(attribute)); })); }
protected IEnumerable <AspectInstance> GetValidationAttributes(IEnumerable <PropertyInfo> properties) { return(properties. SelectMany(property => property.GetCustomAttributes <ValidationAttribute>(). Where(attribute => !string.IsNullOrEmpty(attribute.ErrorMessageResourceName) && attribute.ErrorMessageResourceType == null). Select(validationAttribute => { var constructor = validationAttribute.GetType().GetConstructor(Type.EmptyTypes); var attribute = new ObjectConstruction(constructor); attribute.NamedArguments["ErrorMessageResourceName"] = validationAttribute.ErrorMessageResourceName; attribute.NamedArguments["ErrorMessageResourceType"] = _resourceType; return new AspectInstance(property, new CustomAttributeIntroductionAspect(attribute)); }) )); }
public AbstractService(Context glassContext) { GlassContext = glassContext; if (GlassContext == null) throw new NullReferenceException("Context is null"); var objectConstructionTasks = glassContext.DependencyResolver.ResolveAll<IObjectConstructionTask>(); _objectConstruction = new ObjectConstruction(objectConstructionTasks); var configurationResolverTasks = glassContext.DependencyResolver.ResolveAll<IConfigurationResolverTask>(); _configurationResolver = new ConfigurationResolver(configurationResolverTasks); var objectSavingTasks = glassContext.DependencyResolver.ResolveAll<IObjectSavingTask>(); _objectSaving = new ObjectSaving(objectSavingTasks); Profiler = new NullProfiler(); }
/// <summary> /// /// </summary> /// <param name="targetElement"></param> /// <returns></returns> public IEnumerable<AspectInstance> ProvideAspects(object targetElement) { var t = (Type)targetElement; var props = t.GetFields(BindingFlags.SetField | BindingFlags.Instance | BindingFlags.NonPublic); if (props.Length == 0) yield return null; var objectConstruction = new ObjectConstruction(typeof(DataContractAttribute)); var ns =Zieschang.Net.Projects.PostsharpAspects.Utilities.Utilities.GetContractNamespace(t); objectConstruction.NamedArguments.Add("Namespace", ns); var introduceDataContractAttribute = new CustomAttributeIntroductionAspect(objectConstruction); var introduceDataMemberAttribute = new CustomAttributeIntroductionAspect(new ObjectConstruction(typeof(DataMemberAttribute))); yield return new AspectInstance(t, introduceDataContractAttribute); foreach (var prop in props) { if (!prop.IsDefined(typeof(NoDataMemberAttribute), true)) yield return new AspectInstance(prop, introduceDataMemberAttribute); } }
protected virtual void Dispose(bool disposing) { if (disposing) { if (_configurationResolver != null) { _configurationResolver.Dispose(); } if (_objectConstruction != null) { _objectConstruction.Dispose(); } if (_objectSaving != null) { _objectSaving.Dispose(); } _configurationResolver = null; _objectConstruction = null; _objectSaving = null; } }
/// <summary> /// Initializes a new instance of the <see cref="AbstractService"/> class. /// </summary> /// <param name="glassContext">The glass context.</param> /// <exception cref="System.NullReferenceException">Context is null</exception> protected AbstractService(Context glassContext) { GlassContext = glassContext; if (GlassContext == null) { throw new NullReferenceException("Context is null"); } var objectConstructionTasks = glassContext.DependencyResolver.ResolveAll <IObjectConstructionTask>(); _objectConstruction = new ObjectConstruction(objectConstructionTasks); var configurationResolverTasks = glassContext.DependencyResolver.ResolveAll <IConfigurationResolverTask>(); _configurationResolver = new ConfigurationResolver(configurationResolverTasks); var objectSavingTasks = glassContext.DependencyResolver.ResolveAll <IObjectSavingTask>(); _objectSaving = new ObjectSaving(objectSavingTasks); Profiler = new NullProfiler(); }
public IEnumerable <AspectInstance> ProvideImplementationAspects(object targetElement, ObjectConstruction aspectConstruction) { yield return(new AspectInstance(targetElement, new ObjectConstruction( "BusinessFramework.AOP.NotifyPropertyChangedAttribute, BusinessFramework.AOP.SL"), new AspectConfiguration())); yield return(new AspectInstance(targetElement, new ObjectConstruction( "BusinessFramework.AOP.ImplementExtensionsAttribute, BusinessFramework.AOP.SL"), new AspectConfiguration())); yield return(new AspectInstance(targetElement, new ObjectConstruction( "BusinessFramework.AOP.DataErrorAttribute, BusinessFramework.AOP.SL"), new AspectConfiguration())); yield return(new AspectInstance(targetElement, new ObjectConstruction( "BusinessFramework.AOP.SL.NotifyDataErrorInfoAttribute, BusinessFramework.AOP.SL"), new AspectConfiguration())); }
public void WhenParamTypesIsNull_ThenThrowException() { Assert.Throws <ArgumentNullException>(() => ObjectConstruction.ConstructNonPublic <TestClassPrivateConstructor>(null)); }
public void WhenHasInternalConstructor_ThenReturnInstance() { var result = ObjectConstruction.ConstructNonPublic <TestClassInternalConstructor>(); Assert.That(result.One, Is.EqualTo(1)); }
private static AspectInstance GetProtoInclude(Type baseType, Type targetType, int tag) { var ctor = new ObjectConstruction(typeof(ProtoIncludeAttribute).GetConstructor(new Type[] { typeof(int), typeof(Type) }), new object[] { tag, targetType }); return(new AspectInstance(baseType, new CustomAttributeIntroductionAspect(ctor))); }
private static AspectInstance GetProtoContract(Type targetType) { var ctor = new ObjectConstruction(typeof(ProtoContractAttribute).GetConstructor(Type.EmptyTypes)); return(new AspectInstance(targetType, new CustomAttributeIntroductionAspect(ctor))); }
private static AspectInstance GetProtoMember(PropertyInfo targetType, int tag) { var ctor = new ObjectConstruction(typeof(ProtoMemberAttribute).GetConstructor(new Type[] { typeof(int) }), new object[] { tag }); return(new AspectInstance(targetType, new CustomAttributeIntroductionAspect(ctor))); }
public ConstructAspectInstanceFactory(ObjectConstruction construction) { this.construction = construction; }
public IEnumerable <AspectInstance> ProvideAspects(object targetElement) { var requiredConstruction = new ObjectConstruction(typeof(PostSharp.Patterns.Contracts.RequiredAttribute)); yield return(new AspectInstance(targetElement, requiredConstruction, null)); }
/// <summary> /// Initializes a new instance of the <see cref="AbstractService"/> class. /// </summary> /// <param name="glassContext">The glass context.</param> /// <exception cref="System.NullReferenceException">Context is null</exception> protected AbstractService(Context glassContext) { GlassContext = glassContext; if (GlassContext == null) throw new NullReferenceException("Context is null"); var objectConstructionTasks = glassContext.DependencyResolver.ObjectConstructionFactory.GetItems(); _objectConstruction = new ObjectConstruction(objectConstructionTasks); var configurationResolverTasks = glassContext.DependencyResolver.ConfigurationResolverFactory.GetItems(); _configurationResolver = new ConfigurationResolver(configurationResolverTasks); var objectSavingTasks = glassContext.DependencyResolver.ObjectSavingFactory.GetItems(); _objectSaving = new ObjectSaving(objectSavingTasks); Profiler = new NullProfiler(); Initiate(glassContext.DependencyResolver); }