diff --git a/Source/Editor/Scripting/ScriptType.Custom.cs b/Source/Editor/Scripting/ScriptType.Custom.cs new file mode 100644 index 000000000..1239bd155 --- /dev/null +++ b/Source/Editor/Scripting/ScriptType.Custom.cs @@ -0,0 +1,318 @@ +// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. + +using System; +using System.Collections.Generic; +using System.Reflection; +using FlaxEditor.Content; + +namespace FlaxEditor.Scripting +{ + /// + /// Interface for custom scripting languages type object with metadata. + /// + public interface IScriptType + { + /// + /// Gets a type name (eg. name of the class or enum without leading namespace). + /// + string Name { get; } + + /// + /// Gets a full namespace of the type. + /// + string Namespace { get; } + + /// + /// Gets a full name of the type including leading namespace and any nested types names. Uniquely identifies the type and can be used to find it via . + /// + string TypeName { get; } + + /// + /// Gets a value indicating whether the type is declared public. + /// + bool IsPublic { get; } + + /// + /// Gets a value indicating whether the type is abstract and must be overridden. + /// + bool IsAbstract { get; } + + /// + /// Gets a value indicating whether the type is declared sealed and cannot be overridden. + /// + bool IsSealed { get; } + + /// + /// Gets a value indicating whether the type represents an enumeration. + /// + bool IsEnum { get; } + + /// + /// Gets a value indicating whether the type is a class or a delegate; that is, not a value type or interface. + /// + bool IsClass { get; } + + /// + /// Gets a value indicating whether the type is an interface. + /// + bool IsInterface { get; } + + /// + /// Gets a value indicating whether the type is an array. + /// + bool IsArray { get; } + + /// + /// Gets a value indicating whether the type is a value type (basic type, enumeration or a structure). + /// + bool IsValueType { get; } + + /// + /// Gets a value indicating whether the type is generic type and is used as a template. + /// + bool IsGenericType { get; } + + /// + /// Gets a value indicating whether the type is a reference and value is represented by the valid pointer to the data. + /// + bool IsReference { get; } + + /// + /// Gets a value indicating whether the type is a pointer and value is represented by the pointer to the data. + /// + bool IsPointer { get; } + + /// + /// Gets a value indicating whether the type is static. + /// + bool IsStatic { get; } + + /// + /// Gets a value indicating whether can create default instance of this type via method. + /// + bool CanCreateInstance { get; } + + /// + /// Gets the type from which the current type directly inherits. + /// + ScriptType BaseType { get; } + + /// + /// Gets the editor content item that corresponds to this script type. Can be null. + /// + ContentItem ContentItem { get; } + + /// + /// Creates the instance of the object of this type (or throws exception in case of error). + /// + /// The created instance of the object. + object CreateInstance(); + + /// + /// Determines whether the current type implements the specified interface type. Checks this type, its base classes and implemented interfaces base interfaces too. + /// + /// The type of the interface to check. + /// True if this type implements the given interface, otherwise false. + bool ImplementInterface(ScriptType c); + + /// + /// Determines whether the specified attribute was defined for this type. + /// + /// The attribute type. + /// true to search this member's inheritance chain to find the attributes; otherwise, false. + /// true if the specified type has attribute; otherwise, false. + bool HasAttribute(Type attributeType, bool inherit); + + /// + /// When overridden in a derived class, returns an array of all custom attributes applied to this member. + /// + /// true to search this member's inheritance chain to find the attributes; otherwise, false. + /// An array that contains all the custom attributes applied to this member, or an array with zero elements if no attributes are defined. + object[] GetAttributes(bool inherit); + + /// + /// Searches for the specified members of the specified member type, using the specified binding constraints. + /// + /// The string containing the name of the members to get. + /// The value to search for. + /// A bitmask comprised of one or more that specify how the search is conducted.-or- Zero, to return an empty array. + /// An array of member objects representing the public members with the specified name, if found; otherwise, an empty array. + ScriptMemberInfo[] GetMembers(string name, MemberTypes type, BindingFlags bindingAttr); + + /// + /// When overridden in a derived class, searches for the members defined for the current type using the specified binding constraints. + /// + /// A bitmask comprised of one or more that specify how the search is conducted.-or- Zero (), to return an empty array. + /// An array of member objects representing all members defined for the current type that match the specified binding constraints.-or- An empty array of type member, if no members are defined for the current type, or if none of the defined members match the binding constraints. + ScriptMemberInfo[] GetMembers(BindingFlags bindingAttr); + + /// + /// When overridden in a derived class, searches for the fields defined for the current type using the specified binding constraints. + /// + /// A bitmask comprised of one or more that specify how the search is conducted.-or- Zero (), to return an empty array. + /// An array of member objects representing all fields defined for the current type that match the specified binding constraints.-or- An empty array of type member, if no fields are defined for the current type, or if none of the defined fields match the binding constraints. + ScriptMemberInfo[] GetFields(BindingFlags bindingAttr); + + /// + /// When overridden in a derived class, searches for the properties defined for the current type using the specified binding constraints. + /// + /// A bitmask comprised of one or more that specify how the search is conducted.-or- Zero (), to return an empty array. + /// An array of member objects representing all properties defined for the current type that match the specified binding constraints.-or- An empty array of type member, if no properties are defined for the current type, or if none of the defined properties match the binding constraints. + ScriptMemberInfo[] GetProperties(BindingFlags bindingAttr); + + /// + /// When overridden in a derived class, searches for the methods defined for the current type using the specified binding constraints. + /// + /// A bitmask comprised of one or more that specify how the search is conducted.-or- Zero (), to return an empty array. + /// An array of member objects representing all methods defined for the current type that match the specified binding constraints.-or- An empty array of type member, if no methods are defined for the current type, or if none of the defined methods match the binding constraints. + ScriptMemberInfo[] GetMethods(BindingFlags bindingAttr); + } + + /// + /// Interface for custom scripting languages type object with metadata. + /// + public interface IScriptMemberInfo + { + /// + /// Gets a member name (eg. name of the field or method without leading class name nor namespace prefixes). + /// + string Name { get; } + + /// + /// Gets a metadata token for sorting so it may not be the actual token. + /// + int MetadataToken { get; } + + /// + /// Gets a value indicating whether the type is declared public. + /// + bool IsPublic { get; } + + /// + /// Gets a value indicating whether the type is declared in static scope. + /// + bool IsStatic { get; } + + /// + /// Gets a value indicating whether this method is declared as virtual (can be overriden). + /// + bool IsVirtual { get; } + + /// + /// Gets a value indicating whether this method is declared as abstract (has to be overriden). + /// + bool IsAbstract { get; } + + /// + /// Gets a value indicating whether this method is declared as generic (needs to be inflated with type arguments). + /// + bool IsGeneric { get; } + + /// + /// Gets a value indicating whether this member is a field. + /// + bool IsField { get; } + + /// + /// Gets a value indicating whether this member is a property. + /// + bool IsProperty { get; } + + /// + /// Gets a value indicating whether this member is a method. + /// + bool IsMethod { get; } + + /// + /// Gets a value indicating whether this member is an event. + /// + bool IsEvent { get; } + + /// + /// Gets a value indicating whether this member value can be gathered (via getter method or directly from the field). + /// + bool HasGet { get; } + + /// + /// Gets a value indicating whether this member value can be set (via setter method or directly to the field). + /// + bool HasSet { get; } + + /// + /// Gets the method parameters count (valid for methods only). + /// + int ParametersCount { get; } + + /// + /// Gets the type that declares this member. + /// + ScriptType DeclaringType { get; } + + /// + /// Gets the type of the value (field type, property type or method return value). + /// + ScriptType ValueType { get; } + + /// + /// Determines whether the specified attribute was defined for this member. + /// + /// The attribute type. + /// true to search this member's inheritance chain to find the attributes; otherwise, false. + /// true if the specified member has attribute; otherwise, false. + bool HasAttribute(Type attributeType, bool inherit); + + /// + /// When overridden in a derived class, returns an array of all custom attributes applied to this member. + /// + /// true to search this member's inheritance chain to find the attributes; otherwise, false. + /// An array that contains all the custom attributes applied to this member, or an array with zero elements if no attributes are defined. + object[] GetAttributes(bool inherit); + + /// + /// Gets the method parameters metadata (or event delegate signature parameters). + /// + ScriptMemberInfo.Parameter[] GetParameters(); + + /// + /// Returns the member value of a specified object. + /// + /// The object whose member value will be returned. + /// The member value of the specified object. + object GetValue(object obj); + + /// + /// Sets the member value of a specified object. + /// + /// The object whose member value will be modified. + /// The new member value. + void SetValue(object obj, object value); + } + + /// + /// Interface for custom scripting languages types information containers that can inject types metadata into Editor. + /// + public interface IScriptTypesContainer + { + /// + /// Tries to get the object type from the given full typename. Searches in-build Flax Engine/Editor assemblies and game assemblies. + /// + /// The full name of the type. + /// The type or null if failed. + ScriptType GetType(string typeName); + + /// + /// Gets all the types within all the loaded assemblies. + /// + /// The result collection. Elements will be added to it. Clear it before usage. + /// Additional callback used to check if the given type is valid. Returns true if add type, otherwise false. + void GetTypes(List result, Func checkFunc); + + /// + /// Gets all the derived types from the given base type (excluding that type) within all the loaded assemblies. + /// + /// The base type. + /// The result collection. Elements will be added to it. Clear it before usage. + /// Additional callback used to check if the given type is valid. Returns true if add type, otherwise false. + void GetDerivedTypes(ScriptType baseType, List result, Func checkFunc); + } +} diff --git a/Source/Editor/Scripting/ScriptType.cs b/Source/Editor/Scripting/ScriptType.cs index 41f7540ed..402612c88 100644 --- a/Source/Editor/Scripting/ScriptType.cs +++ b/Source/Editor/Scripting/ScriptType.cs @@ -1370,313 +1370,4 @@ namespace FlaxEditor.Scripting return ScriptMemberInfo.Null; } } - - /// - /// Interface for custom scripting languages type object with metadata. - /// - public interface IScriptType - { - /// - /// Gets a type name (eg. name of the class or enum without leading namespace). - /// - string Name { get; } - - /// - /// Gets a full namespace of the type. - /// - string Namespace { get; } - - /// - /// Gets a full name of the type including leading namespace and any nested types names. Uniquely identifies the type and can be used to find it via . - /// - string TypeName { get; } - - /// - /// Gets a value indicating whether the type is declared public. - /// - bool IsPublic { get; } - - /// - /// Gets a value indicating whether the type is abstract and must be overridden. - /// - bool IsAbstract { get; } - - /// - /// Gets a value indicating whether the type is declared sealed and cannot be overridden. - /// - bool IsSealed { get; } - - /// - /// Gets a value indicating whether the type represents an enumeration. - /// - bool IsEnum { get; } - - /// - /// Gets a value indicating whether the type is a class or a delegate; that is, not a value type or interface. - /// - bool IsClass { get; } - - /// - /// Gets a value indicating whether the type is an interface. - /// - bool IsInterface { get; } - - /// - /// Gets a value indicating whether the type is an array. - /// - bool IsArray { get; } - - /// - /// Gets a value indicating whether the type is a value type (basic type, enumeration or a structure). - /// - bool IsValueType { get; } - - /// - /// Gets a value indicating whether the type is generic type and is used as a template. - /// - bool IsGenericType { get; } - - /// - /// Gets a value indicating whether the type is a reference and value is represented by the valid pointer to the data. - /// - bool IsReference { get; } - - /// - /// Gets a value indicating whether the type is a pointer and value is represented by the pointer to the data. - /// - bool IsPointer { get; } - - /// - /// Gets a value indicating whether the type is static. - /// - bool IsStatic { get; } - - /// - /// Gets a value indicating whether can create default instance of this type via method. - /// - bool CanCreateInstance { get; } - - /// - /// Gets the type from which the current type directly inherits. - /// - ScriptType BaseType { get; } - - /// - /// Gets the editor content item that corresponds to this script type. Can be null. - /// - ContentItem ContentItem { get; } - - /// - /// Creates the instance of the object of this type (or throws exception in case of error). - /// - /// The created instance of the object. - object CreateInstance(); - - /// - /// Determines whether the current type implements the specified interface type. Checks this type, its base classes and implemented interfaces base interfaces too. - /// - /// The type of the interface to check. - /// True if this type implements the given interface, otherwise false. - bool ImplementInterface(ScriptType c); - - /// - /// Determines whether the specified attribute was defined for this type. - /// - /// The attribute type. - /// true to search this member's inheritance chain to find the attributes; otherwise, false. - /// true if the specified type has attribute; otherwise, false. - bool HasAttribute(Type attributeType, bool inherit); - - /// - /// When overridden in a derived class, returns an array of all custom attributes applied to this member. - /// - /// true to search this member's inheritance chain to find the attributes; otherwise, false. - /// An array that contains all the custom attributes applied to this member, or an array with zero elements if no attributes are defined. - object[] GetAttributes(bool inherit); - - /// - /// Searches for the specified members of the specified member type, using the specified binding constraints. - /// - /// The string containing the name of the members to get. - /// The value to search for. - /// A bitmask comprised of one or more that specify how the search is conducted.-or- Zero, to return an empty array. - /// An array of member objects representing the public members with the specified name, if found; otherwise, an empty array. - ScriptMemberInfo[] GetMembers(string name, MemberTypes type, BindingFlags bindingAttr); - - /// - /// When overridden in a derived class, searches for the members defined for the current type using the specified binding constraints. - /// - /// A bitmask comprised of one or more that specify how the search is conducted.-or- Zero (), to return an empty array. - /// An array of member objects representing all members defined for the current type that match the specified binding constraints.-or- An empty array of type member, if no members are defined for the current type, or if none of the defined members match the binding constraints. - ScriptMemberInfo[] GetMembers(BindingFlags bindingAttr); - - /// - /// When overridden in a derived class, searches for the fields defined for the current type using the specified binding constraints. - /// - /// A bitmask comprised of one or more that specify how the search is conducted.-or- Zero (), to return an empty array. - /// An array of member objects representing all fields defined for the current type that match the specified binding constraints.-or- An empty array of type member, if no fields are defined for the current type, or if none of the defined fields match the binding constraints. - ScriptMemberInfo[] GetFields(BindingFlags bindingAttr); - - /// - /// When overridden in a derived class, searches for the properties defined for the current type using the specified binding constraints. - /// - /// A bitmask comprised of one or more that specify how the search is conducted.-or- Zero (), to return an empty array. - /// An array of member objects representing all properties defined for the current type that match the specified binding constraints.-or- An empty array of type member, if no properties are defined for the current type, or if none of the defined properties match the binding constraints. - ScriptMemberInfo[] GetProperties(BindingFlags bindingAttr); - - /// - /// When overridden in a derived class, searches for the methods defined for the current type using the specified binding constraints. - /// - /// A bitmask comprised of one or more that specify how the search is conducted.-or- Zero (), to return an empty array. - /// An array of member objects representing all methods defined for the current type that match the specified binding constraints.-or- An empty array of type member, if no methods are defined for the current type, or if none of the defined methods match the binding constraints. - ScriptMemberInfo[] GetMethods(BindingFlags bindingAttr); - } - - /// - /// Interface for custom scripting languages type object with metadata. - /// - public interface IScriptMemberInfo - { - /// - /// Gets a member name (eg. name of the field or method without leading class name nor namespace prefixes). - /// - string Name { get; } - - /// - /// Gets a metadata token for sorting so it may not be the actual token. - /// - int MetadataToken { get; } - - /// - /// Gets a value indicating whether the type is declared public. - /// - bool IsPublic { get; } - - /// - /// Gets a value indicating whether the type is declared in static scope. - /// - bool IsStatic { get; } - - /// - /// Gets a value indicating whether this method is declared as virtual (can be overriden). - /// - bool IsVirtual { get; } - - /// - /// Gets a value indicating whether this method is declared as abstract (has to be overriden). - /// - bool IsAbstract { get; } - - /// - /// Gets a value indicating whether this method is declared as generic (needs to be inflated with type arguments). - /// - bool IsGeneric { get; } - - /// - /// Gets a value indicating whether this member is a field. - /// - bool IsField { get; } - - /// - /// Gets a value indicating whether this member is a property. - /// - bool IsProperty { get; } - - /// - /// Gets a value indicating whether this member is a method. - /// - bool IsMethod { get; } - - /// - /// Gets a value indicating whether this member is an event. - /// - bool IsEvent { get; } - - /// - /// Gets a value indicating whether this member value can be gathered (via getter method or directly from the field). - /// - bool HasGet { get; } - - /// - /// Gets a value indicating whether this member value can be set (via setter method or directly to the field). - /// - bool HasSet { get; } - - /// - /// Gets the method parameters count (valid for methods only). - /// - int ParametersCount { get; } - - /// - /// Gets the type that declares this member. - /// - ScriptType DeclaringType { get; } - - /// - /// Gets the type of the value (field type, property type or method return value). - /// - ScriptType ValueType { get; } - - /// - /// Determines whether the specified attribute was defined for this member. - /// - /// The attribute type. - /// true to search this member's inheritance chain to find the attributes; otherwise, false. - /// true if the specified member has attribute; otherwise, false. - bool HasAttribute(Type attributeType, bool inherit); - - /// - /// When overridden in a derived class, returns an array of all custom attributes applied to this member. - /// - /// true to search this member's inheritance chain to find the attributes; otherwise, false. - /// An array that contains all the custom attributes applied to this member, or an array with zero elements if no attributes are defined. - object[] GetAttributes(bool inherit); - - /// - /// Gets the method parameters metadata (or event delegate signature parameters). - /// - ScriptMemberInfo.Parameter[] GetParameters(); - - /// - /// Returns the member value of a specified object. - /// - /// The object whose member value will be returned. - /// The member value of the specified object. - object GetValue(object obj); - - /// - /// Sets the member value of a specified object. - /// - /// The object whose member value will be modified. - /// The new member value. - void SetValue(object obj, object value); - } - - /// - /// Interface for custom scripting languages types information containers that can inject types metadata into Editor. - /// - public interface IScriptTypesContainer - { - /// - /// Tries to get the object type from the given full typename. Searches in-build Flax Engine/Editor assemblies and game assemblies. - /// - /// The full name of the type. - /// The type or null if failed. - ScriptType GetType(string typeName); - - /// - /// Gets all the types within all the loaded assemblies. - /// - /// The result collection. Elements will be added to it. Clear it before usage. - /// Additional callback used to check if the given type is valid. Returns true if add type, otherwise false. - void GetTypes(List result, Func checkFunc); - - /// - /// Gets all the derived types from the given base type (excluding that type) within all the loaded assemblies. - /// - /// The base type. - /// The result collection. Elements will be added to it. Clear it before usage. - /// Additional callback used to check if the given type is valid. Returns true if add type, otherwise false. - void GetDerivedTypes(ScriptType baseType, List result, Func checkFunc); - } }