当前位置: 首页>>代码示例>>C#>>正文


C# CodeWriter.GetMethodCallExpression方法代码示例

本文整理汇总了C#中CodeWriter.GetMethodCallExpression方法的典型用法代码示例。如果您正苦于以下问题:C# CodeWriter.GetMethodCallExpression方法的具体用法?C# CodeWriter.GetMethodCallExpression怎么用?C# CodeWriter.GetMethodCallExpression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CodeWriter的用法示例。


在下文中一共展示了CodeWriter.GetMethodCallExpression方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteClassHeader

        public override void WriteClassHeader(CodeWriter writer, DbLinq.Schema.Dbml.Table table, GenerationContext context)
        {
            using (writer.WriteRegion(string.Format("{0} handling", typeof(INotifyPropertyChanging).Name)))
            {
                const string eventName = "PropertyChanging"; // do not change, part of INotifyPropertyChanging
                const string emptyArgs = "emptyChangingEventArgs";

                // event
                writer.WriteEvent(SpecificationDefinition.Public, eventName, typeof(PropertyChangingEventHandler).Name);
                writer.WriteLine();
                // empty event arg
                writer.WriteField(SpecificationDefinition.Private | SpecificationDefinition.Static,
                                  writer.GetAssignmentExpression(emptyArgs, writer.GetNewExpression(
                                                                                writer.GetMethodCallExpression(typeof(PropertyChangingEventArgs).Name, "\"\""))),
                                  typeof(PropertyChangingEventArgs).Name);
                // method
                using (writer.WriteMethod(SpecificationDefinition.Protected | SpecificationDefinition.Virtual,
                                          sendPropertyChangingMethod, null))
                {
                    using (writer.WriteIf(writer.GetDifferentExpression(eventName, writer.GetNullExpression())))
                    {
                        writer.WriteLine(writer.GetStatement(writer.GetMethodCallExpression(eventName,
                                                                                            writer.GetThisExpression(), emptyArgs)));
                    }
                }
            }
        }
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:27,代码来源:INotifyPropertyChangingImplementation.cs

示例2: WriteDataContextCtors

 protected virtual void WriteDataContextCtors(CodeWriter writer, Database schema, Type contextBaseType, GenerationContext context)
 {
     // ctor taking a connections tring
     WriteDataContextCtor(writer, schema, contextBaseType,
            new[] { new ParameterDefinition { Name = "connectionString", Type = typeof(string) } },
            new[] { "connectionString" },
            new[] { typeof(string) },
            context);
     // the two constructors below have the same prototype, so they are mutually exclusive
     // the base class requires a IVendor
     if (!WriteDataContextCtor(writer, schema, contextBaseType,
                          new[] { new ParameterDefinition { Name = "connection", Type = typeof(IDbConnection) } },
                          new[] { "connection", writer.GetNewExpression(writer.GetMethodCallExpression(writer.GetLiteralFullType(context.SchemaLoader.Vendor.GetType()))) },
                          new[] { typeof(IDbConnection), typeof(IVendor) },
                          context))
     {
         // OR the base class requires no IVendor
         WriteDataContextCtor(writer, schema, contextBaseType,
                              new[] { new ParameterDefinition { Name = "connection", Type = typeof(IDbConnection) } },
                              new[] { "connection" },
                              new[] { typeof(IDbConnection) },
                              context);
     }
     // ctor(string, MappingSource)
     WriteDataContextCtor(writer, schema, contextBaseType,
            new[] {
                new ParameterDefinition { Name = "connection", Type = typeof(string) },
                new ParameterDefinition { Name = "mappingSource", Type = typeof(MappingSource) },
            },
            new[] { "connection", "mappingSource" },
            new[] { typeof(string), typeof (MappingSource) },
            context);
     // ctor(IDbConnection, MappingSource)
     WriteDataContextCtor(writer, schema, contextBaseType,
             new[] {
                 new ParameterDefinition { Name = "connection", Type = typeof(IDbConnection) },
                 new ParameterDefinition { Name = "mappingSource", Type = typeof(MappingSource) },
             },
             new[] { "connection", "mappingSource" },
             new[] { typeof(IDbConnection), typeof(MappingSource) },
             context);
     // just in case you'd like to specify another vendor than the one who helped generating this file
     WriteDataContextCtor(writer, schema, contextBaseType,
             new[] {
                 new ParameterDefinition { Name = "connection", Type = typeof(IDbConnection) },
                 new ParameterDefinition { Name = "vendor", Type = typeof(IVendor) },
             },
             new[] { "connection", "vendor" },
             new[] { typeof(IDbConnection), typeof(IVendor) },
             context);
     WriteDataContextCtor(writer, schema, contextBaseType,
             new[] {
                 new ParameterDefinition { Name = "connection", Type = typeof(IDbConnection) },
                 new ParameterDefinition { Name = "mappingSource", Type = typeof(MappingSource) },
                 new ParameterDefinition { Name = "vendor", Type = typeof(IVendor) },
             },
             new[] { "connection", "mappingSource", "vendor" },
             new[] { typeof(IDbConnection), typeof(MappingSource), typeof(IVendor) },
             context);
 }
开发者ID:nlhepler,项目名称:mono,代码行数:60,代码来源:CodeGenerator.Context.Ctor.cs

示例3: WriteClassHeader

        public override void WriteClassHeader(CodeWriter writer, DbLinq.Schema.Dbml.Table table, GenerationContext context)
        {
            using (writer.WriteRegion(string.Format("{0} handling", typeof(INotifyPropertyChanged).Name)))
            {
                const string eventName = "PropertyChanged"; // do not change, part of INotifyPropertyChanged
                const string propertyNameName = "propertyName";

                // event
                writer.WriteEvent(SpecificationDefinition.Public, eventName, typeof(PropertyChangedEventHandler).Name);
                writer.WriteLine();
                // method
                using (writer.WriteMethod(SpecificationDefinition.Protected | SpecificationDefinition.Virtual,
                                          sendPropertyChangedMethod, null, new ParameterDefinition { Name = propertyNameName, Type = typeof(string) }))
                {
                    using (writer.WriteIf(writer.GetDifferentExpression(eventName, writer.GetNullExpression())))
                    {
                        writer.WriteLine(writer.GetStatement(writer.GetMethodCallExpression(eventName,
                                                                                            writer.GetThisExpression(),
                                                                                            writer.GetNewExpression(writer.GetMethodCallExpression(typeof(PropertyChangedEventArgs).Name,
                                                                                                                                                   propertyNameName)))));
                    }
                }
            }
        }
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:24,代码来源:INotifyPropertyChangedImplementation.cs

示例4: WriteDataContextCtor

 protected virtual bool WriteDataContextCtor(CodeWriter writer, Database schema, Type contextBaseType,
     ParameterDefinition[] parameters, string[] baseCallParameterNames, Type[] baseCallParameterTypes,
     GenerationContext context)
 {
     // if we have a contextBaseType, then check that we can do it
     if (contextBaseType != null)
     {
         var ctor = contextBaseType.GetConstructor(baseCallParameterTypes);
         if (ctor == null)
             return false;
     }
     using (writer.WriteCtor(SpecificationDefinition.Public, schema.Class, parameters, baseCallParameterNames))
     {
         writer.WriteLine(writer.GetStatement(writer.GetMethodCallExpression("OnCreated")));
     }
     writer.WriteLine();
     return true;
 }
开发者ID:nlhepler,项目名称:mono,代码行数:18,代码来源:CodeGenerator.Context.Ctor.cs

示例5: WriteClassEqualsAndHash

        protected virtual void WriteClassEqualsAndHash(CodeWriter writer, Table table, GenerationContext context)
        {
            List<DbLinq.Schema.Dbml.Column> primaryKeys = table.Type.Columns.Where(c => c.IsPrimaryKey).ToList();
            if (primaryKeys.Count == 0)
            {
                writer.WriteLine("#warning L189 table {0} has no primary key. Multiple C# objects will refer to the same row.",
                                 table.Name);
                return;
            }

            using (writer.WriteRegion(string.Format("GetHashCode(), Equals() - uses column {0} to look up objects in liveObjectMap",
                                                    string.Join(", ", primaryKeys.Select(pk => pk.Member).ToList().ToArray()))))
            {
                // GetHashCode
                using (writer.WriteMethod(SpecificationDefinition.Public | SpecificationDefinition.Override,
                                          "GetHashCode", typeof(int)))
                {
                    string hashCode = null;

                    foreach (var primaryKey in primaryKeys)
                    {
                        var member = writer.GetVariableExpression(primaryKey.Storage);
                        string primaryKeyHashCode = writer.GetMethodCallExpression(writer.GetMemberExpression(member, "GetHashCode"));
                        if (primaryKey.CanBeNull
                        || GetType(primaryKey.Type, false).IsClass) // this patch to ensure that even if DB does not allow nulls,
                        // our in-memory object won't generate a fault
                        {
                            var isNullExpression = writer.GetEqualExpression(member, writer.GetNullExpression());
                            var nullExpression = writer.GetLiteralValue(0);
                            primaryKeyHashCode = "(" + writer.GetTernaryExpression(isNullExpression, nullExpression, primaryKeyHashCode) + ")";
                        }
                        if (string.IsNullOrEmpty(hashCode))
                            hashCode = primaryKeyHashCode;
                        else
                            hashCode = writer.GetXOrExpression(hashCode, primaryKeyHashCode);
                    }
                    writer.WriteLine(writer.GetReturnStatement(hashCode));
                }
                writer.WriteLine();

                // Equals
                string otherAsObject = "o";
                using (writer.WriteMethod(SpecificationDefinition.Public | SpecificationDefinition.Override,
                                          "Equals", typeof(bool), new ParameterDefinition { Type = typeof(object), Name = otherAsObject }))
                {
                    string other = "other";
                    writer.WriteLine(writer.GetStatement(writer.GetAssignmentExpression(
                                                             writer.GetDeclarationExpression(other, table.Type.Name),
                                                             writer.GetCastExpression(otherAsObject, table.Type.Name,
                                                                                      false))));
                    using (writer.WriteIf(writer.GetEqualExpression(other, writer.GetNullExpression())))
                    {
                        writer.WriteLine(writer.GetReturnStatement(writer.GetLiteralValue(false)));
                    }
                    string andExpression = null;
                    foreach (var primaryKey in primaryKeys)
                    {
                        var member = writer.GetVariableExpression(primaryKey.Storage);
                        string primaryKeyTest = writer.GetMethodCallExpression(
                                writer.GetMemberExpression(
                                    writer.GetMemberExpression(
                                        writer.GetGenericName("System.Collections.Generic.EqualityComparer", primaryKey.Type),
                                        "Default"),
                                    "Equals"),
                                member,
                                writer.GetMemberExpression(other, member));
                        if (string.IsNullOrEmpty(andExpression))
                            andExpression = primaryKeyTest;
                        else
                            andExpression = writer.GetAndExpression(andExpression, primaryKeyTest);
                    }
                    writer.WriteLine(writer.GetReturnStatement(andExpression));
                }
            }
        }
开发者ID:Bewolf2,项目名称:GenesisMono,代码行数:75,代码来源:CodeGenerator.Class.cs

示例6: WriteClassCtor

 /// <summary>
 /// Writes class ctor.
 /// EntitySet initializations
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="table"></param>
 /// <param name="schema"></param>
 /// <param name="context"></param>
 protected virtual void WriteClassCtor(CodeWriter writer, Table table, Database schema, GenerationContext context)
 {
     using (writer.WriteRegion("ctor"))
     using (writer.WriteCtor(SpecificationDefinition.Public, table.Type.Name, new ParameterDefinition[0], null))
     {
         // children are EntitySet
         foreach (var child in GetClassChildren(table))
         {
             // if the association has a storage, we use it. Otherwise, we use the property name
             var entitySetMember = child.Storage ?? child.Member;
             writer.WriteLine(writer.GetStatement(
                 writer.GetAssignmentExpression(
                     entitySetMember,
                     writer.GetNewExpression(writer.GetMethodCallExpression(
                         writer.GetGenericName(TypeExtensions.GetShortName(typeof(EntitySet<>)), child.Type),
                         GetChildAttachMethodName(child),
                         GetChildDetachMethodName(child)
                     ))
                 )
                 ));
         }
         // the parents are the entities referenced by a FK. So a "parent" is an EntityRef
         foreach (var parent in GetClassParents(table))
         {
             var entityRefMember = parent.Storage;
             writer.WriteLine(writer.GetStatement(
                 writer.GetAssignmentExpression(
                     entityRefMember,
                     writer.GetNewExpression(writer.GetMethodCallExpression(
                     writer.GetGenericName(TypeExtensions.GetShortName(typeof(EntityRef<>)), parent.Type)
                     ))
                 )
             ));
         }
         writer.WriteLine(writer.GetStatement(writer.GetMethodCallExpression("OnCreated")));
     }
 }
开发者ID:Bewolf2,项目名称:GenesisMono,代码行数:45,代码来源:CodeGenerator.Class.cs

示例7: WriteClassParent

        protected virtual void WriteClassParent(CodeWriter writer, Association parent, bool hasDuplicates, Database schema, GenerationContext context)
        {
            // the following is apparently useless
            DbLinq.Schema.Dbml.Table targetTable = schema.Tables.FirstOrDefault(t => t.Type.Name == parent.Type);
            if (targetTable == null)
            {
                //Logger.Write(Level.Error, "ERROR L191 target table type not found: " + parent.Type + "  (processing " + parent.Name + ")");
                return;
            }

            string member = parent.Member;
            string storageField = parent.Storage;
            // TODO: remove this
            if (member == parent.ThisKey)
            {
                member = parent.ThisKey + targetTable.Type.Name; //repeat name to prevent collision (same as Linq)
                storageField = "_x_" + parent.Member;
            }

            writer.WriteField(SpecificationDefinition.Private, storageField,
                              writer.GetGenericName(TypeExtensions.GetShortName(typeof(EntityRef<>)),
                                                    targetTable.Type.Name));

            var storageAttribute = NewAttributeDefinition<AssociationAttribute>();
			storageAttribute["Storage"] = storageField;
			storageAttribute["OtherKey"] = parent.OtherKey;
            storageAttribute["ThisKey"] = parent.ThisKey;
            storageAttribute["Name"] = parent.Name;
            storageAttribute["IsForeignKey"] = parent.IsForeignKey;

            SpecificationDefinition specifications;
            if (parent.AccessModifierSpecified)
                specifications = GetSpecificationDefinition(parent.AccessModifier);
            else
                specifications = SpecificationDefinition.Public;
            if (parent.ModifierSpecified)
                specifications |= GetSpecificationDefinition(parent.Modifier);

            var propertyName = hasDuplicates
                                   ? member + "_" + string.Join("", parent.TheseKeys.ToArray())
                                   : member;

            using (writer.WriteAttribute(storageAttribute))
            using (writer.WriteAttribute(NewAttributeDefinition<DebuggerNonUserCodeAttribute>()))
            using (writer.WriteProperty(specifications, propertyName, targetTable.Type.Name))
            {
                string storage = writer.GetMemberExpression(storageField, "Entity");
                using (writer.WritePropertyGet())
                {
                    writer.WriteLine(writer.GetReturnStatement(storage));
                }
                using (writer.WritePropertySet())
                {
                    // algorithm is:
                    // 1.1. must be different than previous value
                    // 1.2. or HasLoadedOrAssignedValue is false (but why?)
                    // 2. implementations before change
                    // 3. if previous value not null
                    // 3.1. place parent in temp variable
                    // 3.2. set [Storage].Entity to null
                    // 3.3. remove it from parent list
                    // 4. assign value to [Storage].Entity
                    // 5. if value is not null
                    // 5.1. add it to parent list
                    // 5.2. set FK members with entity keys
                    // 6. else
                    // 6.1. set FK members to defaults (null or 0)
                    // 7. implementationas after change

                    //writer.WriteLine(writer.GetStatement(writer.GetAssignmentExpression(storage, writer.GetPropertySetValueExpression())));
                    var entityMember = writer.GetMemberExpression(parent.Storage, "Entity");
                    // 1.1
                    using (writer.WriteIf(writer.GetDifferentExpression(writer.GetPropertySetValueExpression(),
                                                                        entityMember)))
                    {
                        var otherAssociation = schema.GetReverseAssociation(parent);
                        // 2. code before the change
                        // TODO change interface to require a member instead of a column
                        //foreach (IImplementation implementation in context.Implementations())
                        //    implementation.WritePropertyBeforeSet(writer, ???, context);
                        // 3.
                        using (writer.WriteIf(writer.GetDifferentExpression(entityMember, writer.GetNullExpression())))
                        {
                            var previousEntityRefName = "previous" + parent.Type;
                            // 3.1.
                            writer.WriteLine(writer.GetStatement(
                                writer.GetVariableDeclarationInitialization(parent.Type, previousEntityRefName, entityMember)
                                ));
                            // 3.2.
                            writer.WriteLine(writer.GetStatement(
                                writer.GetAssignmentExpression(entityMember, writer.GetNullExpression())
                                ));
                            // 3.3.
                            writer.WriteLine(writer.GetStatement(
                                writer.GetMethodCallExpression(
                                    writer.GetMemberExpression(writer.GetMemberExpression(previousEntityRefName, otherAssociation.Member), "Remove"),
                                    writer.GetThisExpression())
                                ));
                        }
                        // 4.
//.........这里部分代码省略.........
开发者ID:Bewolf2,项目名称:GenesisMono,代码行数:101,代码来源:CodeGenerator.Class.cs

示例8: WriteClassPropertyAccessorSet

        /// <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);
            }
        }
开发者ID:Bewolf2,项目名称:GenesisMono,代码行数:49,代码来源:CodeGenerator.Class.cs

示例9: WritePropertyBeforeSet

 public override void WritePropertyBeforeSet(CodeWriter writer, DbLinq.Schema.Dbml.Column property, GenerationContext context)
 {
     writer.WriteLine(writer.GetStatement(writer.GetMethodCallExpression("On" + property.Member + "Changing", "value")));
     writer.WriteLine(writer.GetStatement(writer.GetMethodCallExpression(sendPropertyChangingMethod)));
 }
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:5,代码来源:INotifyPropertyChangingImplementation.cs

示例10: WritePropertyAfterSet

 public override void WritePropertyAfterSet(CodeWriter writer, DbLinq.Schema.Dbml.Column property, GenerationContext context)
 {
     writer.WriteLine(writer.GetStatement(writer.GetMethodCallExpression(sendPropertyChangedMethod,
                                                                         writer.GetLiteralValue(property.Member))));
     writer.WriteLine(writer.GetStatement(writer.GetMethodCallExpression("On" + property.Member + "Changed")));
 }
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:6,代码来源:INotifyPropertyChangedImplementation.cs

示例11: WriteProcedureBodyOutParameter

 protected virtual void WriteProcedureBodyOutParameter(CodeWriter writer, DbLinq.Schema.Dbml.Parameter parameter, string result, int parameterIndex, GenerationContext context)
 {
     string p = writer.GetMethodCallExpression(writer.GetMemberExpression(result, "GetParameterValue"), parameterIndex.ToString());
     string cp = writer.GetCastExpression(p, parameter.Type, true);
     writer.WriteLine(writer.GetStatement(writer.GetAssignmentExpression(parameter.Name, cp)));
 }
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:6,代码来源:CodeGenerator.Procedure.cs


注:本文中的CodeWriter.GetMethodCallExpression方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。