public override void OnGetValue(LocationInterceptionArgs args)
 {
     if (!_valueSet)
     {
         _valueSet = true;
         if (IsGuid)
         {
             //Console.WriteLine("Initializing Guid"); 
             if (args.Location.LocationType == typeof(string))
                 args.SetNewValue(Guid.NewGuid().ToString());
             else if (args.Location.LocationType == typeof(Guid))
                 args.SetNewValue(Guid.NewGuid());
         }
         else if (_defaultValue != null)
         {
             args.SetNewValue(_defaultValue);
             //Console.WriteLine("Initialized {0} to |{1}|", args.LocationName, args.GetCurrentValue()); 
         }
         else if (args.Location.PropertyInfo.GetType().IsClass)
         {
             var t = args.Location.PropertyInfo.PropertyType;
             if (t.GetConstructor(Type.EmptyTypes) != null)
             {
                 //Console.WriteLine("Initializing {0}", args.LocationName);
                 args.SetNewValue(Activator.CreateInstance(t));
             }
             else throw new InvalidOperationException(string.Format("The property {0} (type {1}) has no default constructor and must either be provided with a default value or have the [Initialize] attribute removed", args.LocationFullName, t));
         }
     }
     //Console.WriteLine("Before get called.  Current value is |{0}|", args.GetCurrentValue());
     args.ProceedGetValue();
     //Console.WriteLine("After get called.  Current value is |{0}|", args.Value);
 }
        void LazyLoadValueFromDatabase(LocationInterceptionArgs args, LazyEntity lazyEntity)
        {
            lock (_writeLock) {
                args.ProceedGetValue();

                if (AlreadyLoaded)
                {
                    return;
                }

                if (IsValueAlreadySpecified(args))
                {
                    AlreadyLoaded = true;
                    return;
                }

                if (lazyEntity.Read == null)
                {
                    AlreadyLoaded = true; //?if Read callback is null - it means that entity was created by the client code, and not was getted from db, so it's not persisted at all.
                    return;
                }

                var value = GetValueFor(args, lazyEntity, lazyEntity.Read);
                args.SetNewValue(value);
                AlreadyLoaded = true;
                args.ProceedGetValue();
            }
        }
        public override void OnGetValue(LocationInterceptionArgs args)
        {
            if (this.isFetched)
            {
                args.ProceedGetValue();
                return;
            }
            else
            {
                this.isFetched = true;

                var stringValue = ConfigurationManager.AppSettings[this.settingName];

                if (!string.IsNullOrEmpty(stringValue))
                {
                    var value = Convert.ChangeType(stringValue, args.Location.LocationType);
                    args.SetNewValue(value);
                    args.Value = value;
                }
                else
                {
                    args.ProceedGetValue();
                }
            }
        }
Пример #4
0
        public override void OnGetValue(LocationInterceptionArgs args)
        {
            if (this.isFetched)
            {
                args.ProceedGetValue();
                return;
            }
            else
            {
                this.isFetched = true;

                Console.WriteLine("Reading from registry");
                string stringValue = Registry.GetValue(this.keyName, this.valueName, null) as string;
                if (stringValue != null )
                {
                    object value = Convert.ChangeType(stringValue, args.Location.LocationType);
                    args.SetNewValue(value);
                    args.Value = value;
                }
                else
                {
                    args.ProceedGetValue();
                }
            }
        }
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     if (args.GetCurrentValue() == null)
     {
         args.SetNewValue(_value);
     }
     args.ProceedGetValue();
 }
Пример #6
0
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     args.ProceedGetValue();
     if (args.Value != null)
     {
         return;
     }
     args.SetNewValue(Activator.CreateInstance(type));
     args.ProceedGetValue();
 }
Пример #7
0
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     base.OnGetValue(args);
     if (args.Value == null)
     {
         var obj = ((Node)args.Instance).GetNode(Path ?? args.LocationName);
         args.SetNewValue(obj);
         args.Value = obj;
     }
 }
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     args.ProceedGetValue(); // this actually fetches the field and populates the args.Value
     if (args.Value == null)
     {
         var activity = args.Instance as Activity;
         if (activity == null) throw new ArgumentException("LazyViewAttribute can only be used within Activities");
         args.SetNewValue(activity.FindViewById(_viewId));
         args.ProceedGetValue();
     }
 }
        /// <summary>
        /// Called on 'get' of the field or property, when it is the first 'get', and there was no 'set' before this get,
        /// we will return 'our' value
        /// </summary>
        public override void OnGetValue(LocationInterceptionArgs args)
        {
            if (_isInitialized)
            {
                args.ProceedGetValue();
                return;
            }

            args.SetNewValue(Value);            // store the value using the property its setter
            args.ProceedGetValue();             // then proceed the 'get' as usual
        }
Пример #10
0
        /// <inheritdoc />
        public sealed override void OnSetValue(LocationInterceptionArgs args)
        {
            var newValue = args.Value;
            var oldValue = args.GetCurrentValue();

            if (Equals(newValue, oldValue))
            {
                return;
            }
            args.SetNewValue(newValue);
            ReactiveManager.WasChanged(new CompositeReactiveObject(args.Instance, property));
        }
Пример #11
0
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     if (!_fetchedFromRegistry)
     {
         var value = Registry.GetValue(KeyName, ValueName, DefaultValue);
         args.SetNewValue(value);
         args.Value = value;
     }
     else
     {
         args.ProceedGetValue();
     }
 }
Пример #12
0
 public override void OnGetValue(LocationInterceptionArgs args)
 {
     args.ProceedGetValue(); // this actually fetches the field and populates the args.Value
     if (args.Value == null)
     {
         var activity = args.Instance as Activity;
         if (activity == null)
         {
             throw new ArgumentException("LazyViewAttribute can only be used within Activities");
         }
         args.SetNewValue(activity.FindViewById(_viewId));
         args.ProceedGetValue();
     }
 }
		public override void OnGetValue( LocationInterceptionArgs args )
		{
			var instance = args.Instance ?? args.Location.PropertyInfo.DeclaringType;
			var apply = Apply( instance, args.Location.PropertyInfo );
			if ( apply )
			{
				var parameter = new DefaultValueParameter( instance, args.Location.PropertyInfo );
				var value = source( parameter );
				args.SetNewValue( args.Value = value );
			}
			else
			{
				base.OnGetValue( args );
			}
		}
Пример #14
0
        public override void OnGetValue(LocationInterceptionArgs args)
        {
            var form = (UserForm)args.Instance;  // this form is only used here to write to a listbox for demonstration

            args.ProceedGetValue();
            if (args.Value == null)
            {
                form.LogListBox.Items.Add("Instantiating UserService");
                args.SetNewValue(Activator.CreateInstance(_type));
                args.ProceedGetValue();
            }
            else
            {
                form.LogListBox.Items.Add("Using a UserService that has already been created");
            }
        }
Пример #15
0
        /// <inheritdoc/>
        public sealed override void OnSetValue(LocationInterceptionArgs args)
        {
            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (this == null)             //This is because of the case in TestPropertyAccessDuringConstructionReflection
            {
                args.ProceedSetValue();
                return;
            }

            var newValue = args.Value;
            var oldValue = args.GetCurrentValue();

            if (Equals(newValue, oldValue))
            {
                return;
            }
            args.SetNewValue(newValue);
            ReactiveManager.WasChanged(this);
        }
        public override void OnSetValue(LocationInterceptionArgs args)
        {
            args.SetNewValue(args.Value);
            var instance = (INotifyPropertyChangedImplementor)args.Instance;

            instance.RaisePropertyChanged(args.LocationName);
            foreach (var dependentProperty in _DependentProperties)
            {
                if (typeof(IMPCommand).IsAssignableFrom(dependentProperty.PropertyType))
                {
                    (args.Instance.GetType().GetProperty(dependentProperty.PropertyName)
                     .GetValue(args.Instance) as IMPCommand).ChangeCanExecute();
                }
                else
                {
                    instance.RaisePropertyChanged(dependentProperty.PropertyName);
                }
            }
            args.ProceedSetValue();
        }
        void InitializeCollectionPropertyWithEmptyCollection(LocationInterceptionArgs args)
        {
            lock (_writeLock) {
                args.ProceedGetValue();

                if (AlreadyLoaded)
                {
                    return;
                }

                if (args.Value != null)
                {
                    return;
                }

                var targetCollection = Activator.CreateInstance(TargetCollectionType);
                args.SetNewValue(targetCollection);
                args.ProceedGetValue();
            }
        }
        public override sealed void OnGetValue(LocationInterceptionArgs args)
        {
            args.ProceedGetValue();
            if (args.Value == null)     // lazy loading
            {
                var context = args.Instance as Context;
                if(context == null) throw new Exception("The IoC Aspect can only be used on a field within an Activity (or Context) object");

                ResolveContextDependency((Context)args.Instance);

                var dependencyType = args.Location.LocationType;
                var instantiation = ServiceLocator.Get(dependencyType);

                if (instantiation != null)
                {
                    args.SetNewValue(instantiation);
                }
                args.ProceedGetValue();
            }
        }
Пример #19
0
        public override void OnGetValue(LocationInterceptionArgs args)
        {
            var form = (ProductForm)args.Instance; // this form is only used here to write to a listbox for demonstration

            args.ProceedGetValue(); // this actually fetches the field and populates the args.Value
            if (args.Value == null)
            {
                form.LogListBox.Items.Add("Instantiating ProductService");
                var locationType = args.Location.LocationType;
                var instantiation = ObjectFactory.GetInstance(locationType);

                if (instantiation != null)
                {
                    args.SetNewValue(instantiation);
                }
                args.ProceedGetValue();
            }
            else
            {
                form.LogListBox.Items.Add("Using a ProductService that has already been instantiated");
            }
        }
        public override void OnGetValue(LocationInterceptionArgs args)
        {
            if (isFetched)
            {
                args.ProceedGetValue();
            }
            else
            {
                isFetched = true;

                var stringValue = Registry.GetValue(keyFullName, valueName, null) as string;
                if (stringValue != null)
                {
                    var value = Convert.ChangeType(stringValue, args.Location.LocationType);
                    args.SetNewValue(value);
                    args.Value = value;
                }
                else
                {
                    args.ProceedGetValue();
                }
            }
        }
        public sealed override void OnGetValue(LocationInterceptionArgs args)
        {
            args.ProceedGetValue();
            if (args.Value == null)     // lazy loading
            {
                var context = args.Instance as Context;
                if (context == null)
                {
                    throw new Exception("The IoC Aspect can only be used on a field within an Activity (or Context) object");
                }

                ResolveContextDependency((Context)args.Instance);

                var dependencyType = args.Location.LocationType;
                var instantiation  = ServiceLocator.Get(dependencyType);

                if (instantiation != null)
                {
                    args.SetNewValue(instantiation);
                }
                args.ProceedGetValue();
            }
        }
        public override void OnGetValue(LocationInterceptionArgs args)
        {
            var eb = ((IEntityBase)args.Instance);

            args.SetNewValue(eb.Extensions.GetTypeSafe <string>());
        }
 /// <summary>
 /// </summary>
 /// <param name="args"></param>
 public override void OnSetValue(LocationInterceptionArgs args)
 {
     args.SetNewValue(string.Intern((string)args.Value));
 }
        /// <summary>
        /// Called on 'get' of the field or property, when it is the first 'get', and there was no 'set' before this get,
        /// we will return 'our' value
        /// </summary>
        public override void OnGetValue(LocationInterceptionArgs args)
        {
            if (_isInitialized)
            {
                args.ProceedGetValue();
                return;
            }

            args.SetNewValue(Value); // store the value using the property its setter
            args.ProceedGetValue(); // then proceed the 'get' as usual
        }