Source code for ReFreSH.MobileSuit.Core.SuitShell
from abc import ABC, abstractmethod
from enum import IntEnum
from typing import Callable, Any, List
from ..Decorators import DecoratorUtils
from ...CSharp import *
from .SuitContext import SuitContext
[docs]
class MemberType(IntEnum):
"""
Type of member
"""
MethodWithInfo = 0
"""
A Method with customized information
"""
MethodWithoutInfo = -1
"""
A Method without customized information
"""
FieldWithInfo = 1
"""
A Field/Property with customized information
"""
FieldWithoutInfo = -2
"""
A Field/Property without customized information
"""
[docs]
class SuitShell(ABC):
"""
A SuitObject's member.
"""
def __init__(self, member, instance_factory: Callable[[SuitContext], Any], absoluteName=None):
self.AbsoluteName = null_collapse(absoluteName, member.__name__)
"""
Absolute name of this member.
"""
self.Aliases = DecoratorUtils.get_alias(member)
"""
Aliases of this member.
"""
self.FriendlyNames = [name.lower() for name in ([self.AbsoluteName] + self.Aliases)]
"""
Absolute name, and aliases.
"""
self.Type: MemberType = MemberType.MethodWithoutInfo
"""
Type of the member
"""
self._instanceFactory = instance_factory
self._info = ''
@property
def Information(self) -> str:
"""
Information of this member, customized or generated by Mobile Suit.
"""
return self._info
[docs]
def GetInstance(self, context: SuitContext) -> Any:
"""
Instance which contains this member.
"""
return self._instanceFactory(context)
[docs]
@abstractmethod
async def Execute(self, context: SuitContext):
"""
Execute this object.
:param context: The arguments for execution.
:returns: The result of executing this object
"""
raise NotImplementedError
[docs]
@abstractmethod
def MayExecute(self, request: List[str]) -> bool:
"""
Detect whether this IExecutable may execute the command.
"""
raise NotImplementedError