Struct Property
Struct of this type store a property value and its current type.
Namespace: UnityEngine.GameFoundation
Syntax
[Serializable]
public struct Property : IEquatable<Property>, IEqualityComparer<Property>, IComparable<Property>, IDictionaryConvertible
Remarks
All fields should be declared in this script to avoid the compilation warning CS0282 (see https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs0282).
Properties
type
Stored value's type.
Declaration
public PropertyType type { get; }
Property Value
Type | Description |
---|---|
PropertyType |
Methods
AsAsset<TAsset>()
Explicitly casts this Property into
an asset of the given TAsset
.
Declaration
public TAsset AsAsset<TAsset>()
where TAsset : Object
Returns
Type | Description |
---|---|
TAsset | The asset reference. |
Type Parameters
Name | Description |
---|---|
TAsset | The type of the returned asset. |
Exceptions
Type | Condition |
---|---|
InvalidCastException | Thrown if the stored type isn't compatible with the requested type. |
AsBool()
Explicitly casts this Property into a bool. Handle convertible types properly.
Declaration
public bool AsBool()
Returns
Type | Description |
---|---|
Boolean | The Boolean value. |
Exceptions
Type | Condition |
---|---|
InvalidCastException | Thrown if the stored type isn't compatible with the requested type. |
AsDouble()
Explicitly casts this Property into a double. Handle convertible types properly.
Declaration
public double AsDouble()
Returns
Type | Description |
---|---|
Double | The Double value. |
Exceptions
Type | Condition |
---|---|
InvalidCastException | Thrown if the stored type isn't compatible with the requested type. |
AsFloat()
Explicitly casts this Property into a float. Handle convertible types properly.
Declaration
public float AsFloat()
Returns
Type | Description |
---|---|
Single | The Single value. |
Exceptions
Type | Condition |
---|---|
InvalidCastException | Thrown if the stored type isn't compatible with the requested type. |
AsInt()
Explicitly casts this Property into an integer. Handle convertible types properly.
Declaration
public int AsInt()
Returns
Type | Description |
---|---|
Int32 | The Int32 value. |
Exceptions
Type | Condition |
---|---|
InvalidCastException | Thrown if the stored type isn't compatible with the requested type. |
OverflowException | Thrown if the stored value is outside int boundaries. |
AsLong()
Explicitly casts this Property into a long. Handle convertible types properly.
Declaration
public long AsLong()
Returns
Type | Description |
---|---|
Int64 | The Int64 value. |
Exceptions
Type | Condition |
---|---|
InvalidCastException | Thrown if the stored type isn't compatible with the requested type. |
OverflowException | Thrown if the stored value is outside long boundaries. |
AsString()
Explicitly casts this Property into a string. Handle convertible types properly.
Declaration
public string AsString()
Returns
Type | Description |
---|---|
String | The String value. |
Exceptions
Type | Condition |
---|---|
NotSupportedException | Thrown if the stored type isn't supported. |
CompareTo(Property)
Declaration
public int CompareTo(Property other)
Parameters
Type | Name | Description |
---|---|---|
Property | other |
Returns
Type | Description |
---|---|
Int32 |
CreateAssetProperty(String)
Create a Property of type ResourcesAsset
using the given path
.
Note that the given path
isn't verified.
Declaration
public static Property CreateAssetProperty(string path)
Parameters
Type | Name | Description |
---|---|---|
String | path | A path to an asset from the Resources folder. |
Returns
Type | Description |
---|---|
Property | Return the created property. |
Equals(Object)
Tells whether this Property instance equals obj
.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | The other object to compare this instance with. |
Returns
Type | Description |
---|---|
Boolean |
|
Overrides
Equals(Property)
Declaration
public bool Equals(Property other)
Parameters
Type | Name | Description |
---|---|---|
Property | other |
Returns
Type | Description |
---|---|
Boolean |
Equals(Property, Property)
Declaration
public bool Equals(Property x, Property y)
Parameters
Type | Name | Description |
---|---|---|
Property | x | |
Property | y |
Returns
Type | Description |
---|---|
Boolean |
FillFromDictionary(Dictionary<String, Object>)
Reset this object and fill it with the given data.
Declaration
public void FillFromDictionary(Dictionary<string, object> rawDictionary)
Parameters
Type | Name | Description |
---|---|---|
Dictionary<String, Object> | rawDictionary | A dictionary containing JSON data. Note: Expect integer values (enum included) to be stored as Int64 and floating values to be stored as Double. |
Implements
Remarks
Avoid to use reflection here or this will strongly impact GameFoundation's Json deserialization performances.
GetHashCode()
Gets the hash code of this Property instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | The hash code of this Property instance. |
Overrides
GetHashCode(Property)
Declaration
public int GetHashCode(Property obj)
Parameters
Type | Name | Description |
---|---|---|
Property | obj |
Returns
Type | Description |
---|---|
Int32 |
ToDictionary()
Converts this object to a JSON ready dictionary.
Declaration
public Dictionary<string, object> ToDictionary()
Returns
Type | Description |
---|---|
Dictionary<String, Object> | Returns a dictionary containing this object's data. |
Implements
Remarks
Avoid to use reflection here or this will strongly impact GameFoundation's Json serialization performances.
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String |
Overrides
TryParse(String, String, out Property)
Create a new Property instance by parsing the given
rawPropertyType
and rawValue
.
Declaration
public static bool TryParse(string rawPropertyType, string rawValue, out Property property)
Parameters
Type | Name | Description |
---|---|---|
String | rawPropertyType | Property type to parse. |
String | rawValue | Property value to parse. |
Property | property | Created Property if the parsing was successful. |
Returns
Type | Description |
---|---|
Boolean | Return true if the given strings could be parsed into a valid Property; return false otherwise. |
Operators
Addition(Property, Property)
Add the two given operands into a new Property.
Declaration
public static Property operator +(Property a, Property b)
Parameters
Type | Name | Description |
---|---|---|
Property | a | Left operand. |
Property | b | Right operand. |
Returns
Type | Description |
---|---|
Property | A new Property resulting from the addition of both operands. |
Exceptions
Type | Condition |
---|---|
NotSupportedException | Thrown if one of the operands' type isn't supported. |
Equality(Property, Property)
Compare the two given operands for equality.
Declaration
public static bool operator ==(Property a, Property b)
Parameters
Type | Name | Description |
---|---|---|
Property | a | Left operand. |
Property | b | Right operand. |
Returns
Type | Description |
---|---|
Boolean | True if both operands have the same property type and value. |
Exceptions
Type | Condition |
---|---|
NotSupportedException | Thrown if the stored type isn't supported. |
GreaterThan(Property, Property)
Compare the two given operands if they are numbers.
Declaration
public static bool operator>(Property a, Property b)
Parameters
Type | Name | Description |
---|---|---|
Property | a | Left operand. |
Property | b | Right operand. |
Returns
Type | Description |
---|---|
Boolean | True if |
Exceptions
Type | Condition |
---|---|
NotSupportedException | Thrown if one of the operands' type isn't supported. |
GreaterThanOrEqual(Property, Property)
Compare the two given operands if they are numbers.
Declaration
public static bool operator >=(Property a, Property b)
Parameters
Type | Name | Description |
---|---|---|
Property | a | Left operand. |
Property | b | Right operand. |
Returns
Type | Description |
---|---|
Boolean | True if |
Exceptions
Type | Condition |
---|---|
NotSupportedException | Thrown if one of the operands' type isn't supported. |
Implicit(Boolean to Property)
Construct a Property from the given value
.
Declaration
public static implicit operator Property(bool value)
Parameters
Type | Name | Description |
---|---|---|
Boolean | value | The value to cast into Property. |
Returns
Type | Description |
---|---|
Property | The |
Implicit(Double to Property)
Construct a Property from the given value
.
Declaration
public static implicit operator Property(double value)
Parameters
Type | Name | Description |
---|---|---|
Double | value | The value to cast into Property. |
Returns
Type | Description |
---|---|
Property | The |
Implicit(Int32 to Property)
Construct a Property from the given value
.
Declaration
public static implicit operator Property(int value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | value | The value to cast into Property. |
Returns
Type | Description |
---|---|
Property | The |
Implicit(Int64 to Property)
Construct a Property from the given value
.
Declaration
public static implicit operator Property(long value)
Parameters
Type | Name | Description |
---|---|---|
Int64 | value | The value to cast into Property. |
Returns
Type | Description |
---|---|
Property | The |
Implicit(Single to Property)
Construct a Property from the given value
.
Declaration
public static implicit operator Property(float value)
Parameters
Type | Name | Description |
---|---|---|
Single | value | The value to cast into Property. |
Returns
Type | Description |
---|---|
Property | The |
Implicit(String to Property)
Construct a Property from the given value
.
Declaration
public static implicit operator Property(string value)
Parameters
Type | Name | Description |
---|---|---|
String | value | The value to cast into Property. |
Returns
Type | Description |
---|---|
Property | The |
Implicit(Property to Boolean)
Declaration
public static implicit operator bool (Property value)
Parameters
Type | Name | Description |
---|---|---|
Property | value | The value to cast. |
Returns
Type | Description |
---|---|
Boolean | The Boolean value of the property. |
Implicit(Property to Double)
Declaration
public static implicit operator double (Property value)
Parameters
Type | Name | Description |
---|---|---|
Property | value | The value to cast. |
Returns
Type | Description |
---|---|
Double | The Double value of the property. |
Implicit(Property to Int32)
Declaration
public static implicit operator int (Property value)
Parameters
Type | Name | Description |
---|---|---|
Property | value | The value to cast. |
Returns
Type | Description |
---|---|
Int32 | The Int32 value of the property. |
Implicit(Property to Int64)
Declaration
public static implicit operator long (Property value)
Parameters
Type | Name | Description |
---|---|---|
Property | value | The value to cast. |
Returns
Type | Description |
---|---|
Int64 | The Int64 value of the property. |
Implicit(Property to Single)
Declaration
public static implicit operator float (Property value)
Parameters
Type | Name | Description |
---|---|---|
Property | value | The value to cast. |
Returns
Type | Description |
---|---|
Single | The Single value of the property. |
Implicit(Property to String)
Declaration
public static implicit operator string (Property value)
Parameters
Type | Name | Description |
---|---|---|
Property | value | The value to cast. |
Returns
Type | Description |
---|---|
String | The String value. |
Inequality(Property, Property)
Compare the two given operands for inequality.
Declaration
public static bool operator !=(Property a, Property b)
Parameters
Type | Name | Description |
---|---|---|
Property | a | Left operand. |
Property | b | Right operand. |
Returns
Type | Description |
---|---|
Boolean | True if both operands have different property type or value. |
Exceptions
Type | Condition |
---|---|
NotSupportedException | Thrown if the stored type isn't supported. |
LessThan(Property, Property)
Compare the two given operands if they are numbers.
Declaration
public static bool operator <(Property a, Property b)
Parameters
Type | Name | Description |
---|---|---|
Property | a | Left operand. |
Property | b | Right operand. |
Returns
Type | Description |
---|---|
Boolean | True if |
Exceptions
Type | Condition |
---|---|
NotSupportedException | Thrown if one of the operands' type isn't supported. |
LessThanOrEqual(Property, Property)
Compare the two given operands if they are numbers.
Declaration
public static bool operator <=(Property a, Property b)
Parameters
Type | Name | Description |
---|---|---|
Property | a | Left operand. |
Property | b | Right operand. |
Returns
Type | Description |
---|---|
Boolean | True if |
Exceptions
Type | Condition |
---|---|
NotSupportedException | Thrown if one of the operands' type isn't supported. |
Subtraction(Property, Property)
Subtract the two given operands into a new Property.
Declaration
public static Property operator -(Property a, Property b)
Parameters
Type | Name | Description |
---|---|---|
Property | a | Left operand. |
Property | b | Right operand. |
Returns
Type | Description |
---|---|
Property | A new Property resulting from the subtraction of both operands. |
Exceptions
Type | Condition |
---|---|
NotSupportedException | Thrown if one of the operands' type isn't supported. |