예제 #1
0
        /// <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);
        }
예제 #2
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);
            }
        }
예제 #3
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);
            }
        }