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


C# CodeWriter.WriteRegion方法代码示例

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


在下文中一共展示了CodeWriter.WriteRegion方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: 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

示例5: WriteClassChildrenAttachment

 /// <summary>
 /// Writes attach/detach method
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="table"></param>
 /// <param name="schema"></param>
 /// <param name="context"></param>
 protected virtual void WriteClassChildrenAttachment(CodeWriter writer, Table table, Database schema, GenerationContext context)
 {
     var children = GetClassChildren(table).ToList();
     if (children.Count > 0)
     {
         using (writer.WriteRegion("Attachement handlers"))
         {
             foreach (var child in children)
             {
                 // the reverse child is the association seen from the child
                 // we're going to use it...
                 var reverseChild = schema.GetReverseAssociation(child);
                 // ... to get the parent name
                 var memberName = reverseChild.Member;
                 var entityParameter = new ParameterDefinition { Name = "entity", LiteralType = child.Type };
                 // the Attach event handler sets the child entity parent to "this"
                 using (writer.WriteMethod(SpecificationDefinition.Private, GetChildAttachMethodName(child),
                                           null, entityParameter))
                 {
                     writer.WriteLine(
                         writer.GetStatement(
                             writer.GetAssignmentExpression(
                                 writer.GetMemberExpression(entityParameter.Name, memberName),
                                 writer.GetThisExpression())));
                 }
                 writer.WriteLine();
                 // the Detach event handler sets the child entity parent to null
                 using (writer.WriteMethod(SpecificationDefinition.Private, GetChildDetachMethodName(child),
                                           null, entityParameter))
                 {
                     writer.WriteLine(
                         writer.GetStatement(
                             writer.GetAssignmentExpression(
                                 writer.GetMemberExpression(entityParameter.Name, memberName),
                                 writer.GetNullExpression())));
                 }
                 writer.WriteLine();
             }
         }
     }
 }
开发者ID:Bewolf2,项目名称:GenesisMono,代码行数:48,代码来源:CodeGenerator.Class.cs

示例6: WriteClassParents

 protected virtual void WriteClassParents(CodeWriter writer, Table table, Database schema, GenerationContext context)
 {
     var parents = GetClassParents(table).ToList();
     if (parents.Count > 0)
     {
         using (writer.WriteRegion("Parents"))
         {
             foreach (var parent in parents)
             {
                 bool hasDuplicates = (from p in parents where p.Member == parent.Member select p).Count() > 1;
                 WriteClassParent(writer, parent, hasDuplicates, schema, context);
             }
         }
     }
 }
开发者ID:Bewolf2,项目名称:GenesisMono,代码行数:15,代码来源:CodeGenerator.Class.cs

示例7: WriteClassChildren

 protected virtual void WriteClassChildren(CodeWriter writer, Table table, Database schema, GenerationContext context)
 {
     var children = GetClassChildren(table).ToList();
     if (children.Count > 0)
     {
         using (writer.WriteRegion("Children"))
         {
             foreach (var child in children)
             {
                 bool hasDuplicates = (from c in children where c.Member == child.Member select c).Count() > 1;
                 WriteClassChild(writer, child, hasDuplicates, schema, context);
             }
         }
     }
 }
开发者ID:Bewolf2,项目名称:GenesisMono,代码行数:15,代码来源:CodeGenerator.Class.cs

示例8: WriteClassProperty

 /// <summary>
 /// Writes class property
 /// </summary>
 /// <param name="writer"></param>
 /// <param name="property"></param>
 /// <param name="relatedAssociations">non null if property is a FK</param>
 /// <param name="context"></param>
 protected virtual void WriteClassProperty(CodeWriter writer, Column property, IEnumerable<Association> relatedAssociations, GenerationContext context)
 {
     using (writer.WriteRegion(string.Format("{0} {1}", GetTypeOrExtendedType(writer, property), property.Member)))
     {
         WriteClassPropertyBackingField(writer, property, context);
         WriteClassPropertyAccessors(writer, property, relatedAssociations, context);
     }
 }
开发者ID:Bewolf2,项目名称:GenesisMono,代码行数:15,代码来源:CodeGenerator.Class.cs

示例9: WriteClassExtensibilityDeclarations

 protected virtual void WriteClassExtensibilityDeclarations(CodeWriter writer, Table table, GenerationContext context)
 {
     using (writer.WriteRegion("Extensibility Method Definitions"))
     {
         writer.WriteLine("partial void OnCreated();");
         foreach (var c in table.Type.Columns)
         {
             writer.WriteLine("partial void On{0}Changed();", c.Member);
             writer.WriteLine("partial void On{0}Changing({1} value);", c.Member, GetTypeOrExtendedType(writer, c));
         }
     }
 }
开发者ID:Bewolf2,项目名称:GenesisMono,代码行数:12,代码来源:CodeGenerator.Class.cs

示例10: WriteDataContextExtensibilityDeclarations

 protected virtual void WriteDataContextExtensibilityDeclarations(CodeWriter writer, Database schema, GenerationContext context)
 {
     using (writer.WriteRegion("Extensibility Method Definitions"))
     {
         writer.WriteLine("partial void OnCreated();");
     }
 }
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:CodeGenerator.Context.Ctor.cs


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