Пример #1
0
        /// <summary>
        /// Add a property to a <see cref="FunctionBody"/>
        /// </summary>
        /// <param name="functionBody"><see cref="FunctionBody"/> to add to</param>
        /// <param name="name">Name of the property to add</param>
        /// <param name="callback"><see cref="Action{PropertyAssignment}"/> that gets called for working with the <see cref="PropertyAssignment"/></param>
        /// <returns>Chained <see cref="FunctionBody"/> to keep building on</returns>
        public static FunctionBody Property(this FunctionBody functionBody, string name, Action <PropertyAssignment> callback)
        {
            var propertyAssignment = new PropertyAssignment(name);

            functionBody.AddChild(propertyAssignment);
            callback(propertyAssignment);
            return(functionBody);
        }
Пример #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);
            }
        }