Ejemplo n.º 1
0
 /// <summary>
 /// Class headers are written at top of class
 /// They consist in specific headers writen by interface implementors
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="table"></param>
 /// <param name="context"></param>
 private void WriteClassHeader(CodeWriter writer, Table table, GenerationContext context)
 {
     foreach (IImplementation implementation in context.Implementations())
     {
         implementation.WriteClassHeader(writer, table, context);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes property setter, for FK properties
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="property"></param>
        /// <param name="relatedAssociations"></param>
        /// <param name="context"></param>
        private void WriteClassPropertyAccessorSet(CodeWriter writer, Column property, IEnumerable <Association> relatedAssociations, GenerationContext context)
        {
            // if new value if different from old one
            using (writer.WriteIf(writer.GetDifferentExpression(writer.GetPropertySetValueExpression(),
                                                                writer.GetVariableExpression(property.Storage))))
            {
                // if the property is used as a FK, we ensure that it hasn't been already loaded or assigned
                foreach (var relatedAssociation in relatedAssociations)
                {
                    // first thing to check: ensure the association backend isn't already affected.
                    // if it is the case, then the property must not be manually set

                    // R# considers the following as an error, but the csc doesn't
                    //var memberName = ReflectionUtility.GetMemberInfo<DbLinq.Data.Linq.EntityRef<object>>(e => e.HasLoadedOrAssignedValue).Name;
                    var memberName = "HasLoadedOrAssignedValue";
                    using (writer.WriteIf(writer.GetMemberExpression(relatedAssociation.Storage, memberName)))
                    {
                        writer.WriteLine(writer.GetThrowStatement(writer.GetNewExpression(
                                                                      writer.GetMethodCallExpression(
                                                                          writer.GetLiteralFullType(
                                                                              typeof(
                                                                                  System.Data.Linq.
                                                                                  ForeignKeyReferenceAlreadyHasValueException
                                                                                  )))
                                                                      )));
                    }
                }
                // the before and after are used by extensions related to interfaces
                // for example INotifyPropertyChanged
                // here the code before the change
                foreach (IImplementation implementation in context.Implementations())
                {
                    implementation.WritePropertyBeforeSet(writer, property, context);
                }
                // property assignment
                writer.WriteLine(
                    writer.GetStatement(
                        writer.GetAssignmentExpression(writer.GetVariableExpression(property.Storage),
                                                       writer.GetPropertySetValueExpression())));
                // here the code after change
                foreach (IImplementation implementation in context.Implementations())
                {
                    implementation.WritePropertyAfterSet(writer, property, context);
                }
            }
        }
Ejemplo n.º 3
0
        private void WriteUsings(CodeWriter writer, GenerationContext context)
        {
            writer.WriteUsingNamespace("System");
            writer.WriteUsingNamespace("System.Data");
            writer.WriteUsingNamespace("System.Data.Linq.Mapping");
            writer.WriteUsingNamespace("System.Diagnostics");
            writer.WriteUsingNamespace("System.Reflection");

#if MONO_STRICT
            writer.WriteUsingNamespace("System.Data.Linq");
#else
            writer.WriteLine("#if MONO_STRICT");
            writer.WriteUsingNamespace("System.Data.Linq");
            writer.WriteLine("#else   // MONO_STRICT");
            writer.WriteUsingNamespace("DbLinq.Data.Linq");
            writer.WriteUsingNamespace("DbLinq.Vendor");
            writer.WriteLine("#endif  // MONO_STRICT");
#endif

            //            writer.WriteUsingNamespace("System");
            //            writer.WriteUsingNamespace("System.Collections.Generic");
            //            writer.WriteUsingNamespace("System.ComponentModel");
            //            writer.WriteUsingNamespace("System.Data");
            //            writer.WriteUsingNamespace("System.Data.Linq.Mapping");
            //            writer.WriteUsingNamespace("System.Diagnostics");
            //            writer.WriteUsingNamespace("System.Linq");
            //            writer.WriteUsingNamespace("System.Reflection");
            //            writer.WriteUsingNamespace("System.Text");
            //#if MONO_STRICT
            //            writer.WriteUsingNamespace("System.Data.Linq");
            //#else
            //            writer.WriteUsingNamespace("DbLinq.Data.Linq");
            //            writer.WriteUsingNamespace("DbLinq.Data.Linq.Mapping");
            //#endif

            // now, we write usings required by implemented interfaces
            foreach (var implementation in context.Implementations())
            {
                implementation.WriteHeader(writer, context);
            }

            // write namespaces for members attributes
            foreach (var memberExposedAttribute in context.Parameters.MemberExposedAttributes)
            {
                WriteUsingNamespace(writer, GetNamespace(memberExposedAttribute));
            }

            // write namespaces for clases attributes
            foreach (var entityExposedAttribute in context.Parameters.EntityExposedAttributes)
            {
                WriteUsingNamespace(writer, GetNamespace(entityExposedAttribute));
            }

            writer.WriteLine();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Writes property setter, for FK properties
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="property"></param>
        /// <param name="relatedAssociations"></param>
        /// <param name="context"></param>
        private void WriteClassPropertyAccessorSet(CodeWriter writer, Column property, IEnumerable<Association> relatedAssociations, GenerationContext context)
        {
            // if new value if different from old one
            using (writer.WriteIf(writer.GetDifferentExpression(writer.GetPropertySetValueExpression(),
                                                                writer.GetVariableExpression(property.Storage))))
            {
                // if the property is used as a FK, we ensure that it hasn't been already loaded or assigned
                foreach (var relatedAssociation in relatedAssociations)
                {
                    // first thing to check: ensure the association backend isn't already affected.
                    // if it is the case, then the property must not be manually set

                    // R# considers the following as an error, but the csc doesn't
                    //var memberName = ReflectionUtility.GetMemberInfo<DbLinq.Data.Linq.EntityRef<object>>(e => e.HasLoadedOrAssignedValue).Name;
                    var memberName = "HasLoadedOrAssignedValue";
                    using (writer.WriteIf(writer.GetMemberExpression(relatedAssociation.Storage, memberName)))
                    {
                        writer.WriteLine(writer.GetThrowStatement(writer.GetNewExpression(
                                                                      writer.GetMethodCallExpression(
                                                                          writer.GetLiteralFullType(
                                                                              typeof(
                                                                                  System.Data.Linq.
                                                                                  ForeignKeyReferenceAlreadyHasValueException
                                                                                  )))
                                                                      )));
                    }
                }
                // the before and after are used by extensions related to interfaces
                // for example INotifyPropertyChanged
                // here the code before the change
                foreach (IImplementation implementation in context.Implementations())
                    implementation.WritePropertyBeforeSet(writer, property, context);
                // property assignment
                writer.WriteLine(
                    writer.GetStatement(
                        writer.GetAssignmentExpression(writer.GetVariableExpression(property.Storage),
                                                       writer.GetPropertySetValueExpression())));
                // here the code after change
                foreach (IImplementation implementation in context.Implementations())
                    implementation.WritePropertyAfterSet(writer, property, context);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Class headers are written at top of class
 /// They consist in specific headers writen by interface implementors
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="table"></param>
 /// <param name="context"></param>
 private void WriteClassHeader(CodeWriter writer, Table table, GenerationContext context)
 {
     foreach (IImplementation implementation in context.Implementations())
         implementation.WriteClassHeader(writer, table, context);
 }