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


C# MyEntity.Where方法代码示例

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


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

示例1: Command_Delete

        protected void Command_Delete( ChatEvent chatEvent )
        {
            ulong remoteUserId = chatEvent.RemoteUserId;
            List<string> commandParts = CommandParser.GetCommandParts( chatEvent.Message );
            int paramCount = commandParts.Count - 1;
            MyEntity[] entities = new MyEntity[0];
            SandboxGameAssemblyWrapper.Instance.GameAction(() => entities = MyEntities.GetEntities().ToArray());
            var toRemove = new HashSet<MyEntity>();

            //All entities
            if ( paramCount > 1 && commandParts[ 1 ].ToLower( ).Equals( "all" ) )
            {
                //All cube grids that have no beacon or only a beacon with no name
                if ( commandParts[ 2 ].ToLower( ).Equals( "nobeacon" ) )
                {
                    int removeCount = 0;
                    Parallel.ForEach(MyCubeGridGroups.Static.Logical.Groups, group =>
                                                                             {
                                                                                 bool found = false;
                                                                                 foreach (var node in group.Nodes)
                                                                                 {
                                                                                     var grid = node.NodeData;

                                                                                     if (grid.MarkedForClose || grid.Closed)
                                                                                         continue;

                                                                                     if (grid.CubeBlocks.OfType<MyBeacon>().Any())
                                                                                     {
                                                                                         found = true;
                                                                                         break;
                                                                                     }
                                                                                 }

                                                                                 if (!found)
                                                                                     return;

                                                                                 removeCount++;
                                                                                 foreach (var closeNode in group.Nodes)
                                                                                 {
                                                                                     SandboxGameAssemblyWrapper.Instance.BeginGameAction(()=>closeNode.NodeData.Close(), null, null);
                                                                                 }
                                                                             });

                    SendPrivateChatMessage(remoteUserId, $"{removeCount} cube grids have been removed");
                }
                //All cube grids that have no power
                else if ( commandParts[ 2 ].ToLower( ).Equals( "nopower" ) )
                {
                    //List<CubeGridEntity> entities = SectorObjectManager.Instance.GetTypedInternalData<CubeGridEntity>( );
                    //List<CubeGridEntity> entitiesToDispose = entities.Where( entity => entity.TotalPower <= 0 ).ToList( );

                    //foreach ( CubeGridEntity entity in entitiesToDispose )
                    //{
                    //	entity.Dispose( );
                    //}

                    //SendPrivateChatMessage( remoteUserId, string.Format( "{0} cube grids have been removed", entitiesToDispose.Count ) );
                    SendPrivateChatMessage( remoteUserId, "Unpowered grids removal temporarily unavailable in this version." );
                }
                else if ( commandParts[ 2 ].ToLower( ).Equals( "floatingobjects" ) )	//All floating objects
                {
                    int count = 0;
                    foreach (var floating in entities.Where(e => e is MyFloatingObject))
                    {
                        count++;
                        SandboxGameAssemblyWrapper.Instance.BeginGameAction(() => floating.Close(), null, null);
                    }
                    SendPrivateChatMessage(remoteUserId, $"Removed {count} floating objects");

                }
                else
                {
                    string entityName = commandParts[ 2 ];
                    if ( commandParts.Count > 3 )
                    {
                        for ( int i = 3; i < commandParts.Count; i++ )
                        {
                            entityName += " " + commandParts[ i ];
                        }
                    }

                    int matchingEntitiesCount = 0;
                    foreach ( var entity in entities )
                    {
                        if (entity.MarkedForClose || entity.Closed)
                            continue;

                        bool isMatch = Regex.IsMatch( entity.Name, entityName, RegexOptions.IgnoreCase );
                        if ( !isMatch )
                            continue;

                        SandboxGameAssemblyWrapper.Instance.BeginGameAction(() => entity.Close(), null, null);

                        matchingEntitiesCount++;
                    }

                    SendPrivateChatMessage( remoteUserId, $"{matchingEntitiesCount} objects have been removed");
                }
            }

//.........这里部分代码省略.........
开发者ID:rexxar-tc,项目名称:SEServerExtender,代码行数:101,代码来源:ChatManager.cs


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