Ejemplo n.º 1
0
 /// <summary>
 /// Removes attribute from the list
 /// </summary>
 /// <param name="aAttr">
 /// Attribute to be removed <see cref="Attribute"/>
 /// </param>
 public void RemoveRuntimeAttribute(IRuntimeAttribute aAttr)
 {
     if ((aAttr == null) || (runtimeAttributes == null))
     {
         return;
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RuntimeType"/> class.
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <param name="type">The type.</param>
 /// <param name="defaultTypeInstantiation">
 /// Parameter defaults to true for automatic type instantiation enabled. If value is false
 /// and type is resolved to default value for reference type, exception will be thrown
 /// </param>
 /// <exception cref="ArgumentNullException">attribute</exception>
 public RuntimeType(ITypeActivator typeActivator, IRuntimeAttribute attribute, Type type, bool defaultTypeInstantiation)
 {
     Activator     = typeActivator ?? throw new ArgumentNullException(nameof(typeActivator));
     Type          = (type ?? throw new ArgumentNullException(nameof(type))).ToString();
     ActivatorType = type ?? throw new ArgumentNullException(nameof(type));
     Attribute     = attribute ?? throw new ArgumentNullException(nameof(attribute));
     UseDefaultTypeInstantiation = defaultTypeInstantiation;
     UpdateTypeId();
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Gets or sets the <see cref="System.Object"/> with the specified attribute.
 /// </summary>
 /// <value>The <see cref="System.Object"/>.</value>
 /// <param name="attribute">The attribute.</param>
 /// <param name="typeFullName">Full name of the type.</param>
 /// <returns></returns>
 object this[IRuntimeAttribute attribute, string typeFullName]
 {
     get
     {
         var runtimeAttribute = attribute.GetReferenceAttribute(typeFullName);
         if (!_values.ContainsKey(runtimeAttribute))
         {
             return(GetDefaultValue());
         }
         return(_values[attribute]);
     }
     set => _values[attribute.GetReferenceAttribute(typeFullName)] = value;
Ejemplo n.º 4
0
        /// <summary>
        /// Creates the instance with type inferenced evaluated arguments.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="attribute">The attribute.</param>
        /// <returns></returns>
        public object CreateInstance(IRuntimeType instance, IRuntimeType type, IRuntimeAttribute attribute)
        {
            var obj          = instance.GetValue(type.Attribute, type.Id) ?? Activator.CreateInstance(instance.ActivatorType);
            var runtimeTypes = instance.RuntimeTypes.ToArray();

            for (int i = 0; i < runtimeTypes.Length; i++)
            {
                var runtimeType  = runtimeTypes[i];
                var value        = runtimeType.Evaluate(type, attribute, i);
                var propertyInfo = PropertyCache.GetPropertyInfo(runtimeType);
                propertyInfo.SetValue(obj, value);
            }
            return(obj);
        }
Ejemplo n.º 5
0
 public TypeObject(ITypeActivator runtimeTypeActivator, IRuntimeAttribute runtimeAttribute, Type runtimeType, IEnumerable <string> typeParameters, bool defaultTypeInstantiation)
 {
     RuntimeAttribute = runtimeAttribute;
     TypeParameters   = typeParameters;
     RuntimeType      = new RuntimeType(runtimeTypeActivator, runtimeAttribute, runtimeType, defaultTypeInstantiation);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Method called on attribute change
 /// </summary>
 /// <param name="aAttr">
 /// A <see cref="IRuntimeAttribute"/>
 /// </param>
 public virtual void OnRuntimeAttributeChange(IRuntimeAttribute aAttr)
 {
 }
		/// <summary>
		/// Removes attribute from the list
		/// </summary>
		/// <param name="aAttr">
		/// Attribute to be removed <see cref="Attribute"/>
		/// </param>
		public void RemoveRuntimeAttribute (IRuntimeAttribute aAttr)
		{
			if ((aAttr == null) || (runtimeAttributes == null))
				return;
		}
		/// <summary>
		/// Method called on attribute change
		/// </summary>
		/// <param name="aAttr">
		/// A <see cref="IRuntimeAttribute"/>
		/// </param>
		public virtual void OnRuntimeAttributeChange (IRuntimeAttribute aAttr)
		{
		}
Ejemplo n.º 9
0
 /// <summary>
 /// Creates the instance with type inferenced evaluated arguments.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="attribute">The attribute.</param>
 /// <returns></returns>
 public object CreateInstance(IRuntimeType instance, IRuntimeType type, IRuntimeAttribute attribute) => Activator.CreateInstance(instance.ActivatorType, instance.RuntimeTypes.Evaluate(type, attribute));
Ejemplo n.º 10
0
 /// <summary>
 /// Evaluates arguments
 /// </summary>
 /// <param name="runtimeTypes">Runtime types</param>
 /// <param name="runtimeType">Runtime type</param>
 /// <param name="runtimeAttribute">Runtime attribute</param>
 /// <returns>Returns runtime types evalated values</returns>
 public static object[] Evaluate(this IEnumerable <IRuntimeType> runtimeTypes, IRuntimeType runtimeType, IRuntimeAttribute runtimeAttribute) =>
 runtimeTypes.Select((p, i) => p.Evaluate(runtimeType, runtimeAttribute, i)).ToArray();
Ejemplo n.º 11
0
 /// <summary>
 /// Gets runtime type values
 /// </summary>
 /// <param name="runtimeTypes">Types</param>
 /// <param name="runtimeAttribute">Attribute</param>
 /// <param name="typeId">Id</param>
 /// <returns>Returns runtime types values</returns>
 public static object[] Values(this IEnumerable <IRuntimeType> runtimeTypes, IRuntimeAttribute runtimeAttribute, string typeId) =>
 runtimeTypes.Select((p) => p.GetValue(runtimeAttribute, typeId)).ToArray();