/// <summary>
        /// Assign a key within an <see cref="ObjectLiteral"/>
        /// </summary>
        /// <param name="objectLiteral"><see cref="ObjectLiteral"/> to assign to</param>
        /// <param name="name">Name of key</param>
        /// <returns><see cref="KeyAssignment"/> to build</returns>
        public static KeyAssignment Assign(this ObjectLiteral objectLiteral, string name)
        {
            var keyAssignment = new KeyAssignment(name);

            objectLiteral.AddChild(keyAssignment);
            return(keyAssignment);
        }
        /// <summary>
        /// Assign an object literal
        /// </summary>
        /// <param name="assignment"><see cref="Assignment"/> to assign to</param>
        /// <param name="callback"><see cref="Action{ObjectLiteral}"/> that gets called to build the object literal</param>
        /// <returns>The <see cref="Assignment"/> to build on</returns>
        public static Assignment WithObjectLiteral(this Assignment assignment, Action <ObjectLiteral> callback = null)
        {
            var objectLiteral = new ObjectLiteral();

            if (callback != null)
            {
                callback(objectLiteral);
            }
            assignment.Value = objectLiteral;
            return(assignment);
        }
Exemple #3
0
        static void AddObservablePropertiesFromType(Container parent, IEnumerable <PropertyInfo> properties, Action <Assignment> assignmentVisitor, ObservableVisitor observableVisitor)
        {
            foreach (var property in properties)
            {
                var propertyName = property.Name.ToCamelCase();

                Assignment assignment;
                if (parent is FunctionBody)
                {
                    assignment = new PropertyAssignment(propertyName);
                }
                else
                {
                    assignment = new KeyAssignment(propertyName);
                }

                if (property.IsDictionary())
                {
                    assignment.WithObjectLiteral();
                }
                else if (property.IsEnumerable())
                {
                    assignment.WithObservableArray();
                }
                else if (property.IsObservable())
                {
                    assignment.WithObservable(observableVisitor);
                }
                else
                {
                    var objectLiteral = new ObjectLiteral();
                    assignment.Value = objectLiteral;
                    AddObservablePropertiesFromType(objectLiteral, property.PropertyType.GetTypeInfo().GetProperties(), assignmentVisitor, observableVisitor);
                }

                if (assignmentVisitor != null)
                {
                    assignmentVisitor(assignment);
                }

                parent.AddChild(assignment);
            }
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of <see cref="Namespace"/>
 /// </summary>
 /// <param name="name">Name of the namespace</param>
 public Namespace(string name)
 {
     Name           = name;
     Content        = new ObjectLiteral();
     Content.Parent = this;
 }
Exemple #5
0
        static void AddPropertiesFromType(Container parent, IEnumerable <PropertyInfo> properties, Action <Assignment> assignmentVisitor)
        {
            foreach (var property in properties)
            {
                var propertyName = property.Name.ToCamelCase();

                Assignment assignment;
                if (parent is FunctionBody)
                {
                    assignment = new PropertyAssignment(propertyName);
                }
                else
                {
                    assignment = new KeyAssignment(propertyName);
                }

                if (property.IsDictionary())
                {
                    assignment.WithObjectLiteral();
                }
                else if (property.IsEnumerable())
                {
                    assignment.WithEmptyArray();
                }
                else if (property.PropertyType.IsConcept())
                {
                    assignment.WithDefaultValue(property.PropertyType.GetConceptValueType());
                }
                else if (property.PropertyType.IsNullable())
                {
                    assignment.WithNullValue();
                }
                else if (property.IsDateTime())
                {
                    assignment.WithDate();
                }
                else if (property.IsBoolean())
                {
                    assignment.WithBoolean();
                }
                else if (property.IsEnum())
                {
                    assignment.WithDefaultEnumValue(property.PropertyType);
                }
                else if (property.PropertyType.IsNumericType())
                {
                    assignment.WithDefaultNumericValue(property.PropertyType);
                }
                else if (property.HasPrimitiveDefaultValue())
                {
                    assignment.WithDefaultValue(property.PropertyType);
                }
                else
                {
                    var objectLiteral = new ObjectLiteral();
                    assignment.Value = objectLiteral;
                    AddPropertiesFromType(objectLiteral, property.PropertyType.GetTypeInfo().GetProperties(), assignmentVisitor);
                }

                if (assignmentVisitor != null)
                {
                    assignmentVisitor(assignment);
                }

                parent.AddChild(assignment);
            }
        }