agones.dev/agones@v1.53.0/sdks/unity/model/GameServer.cs (about) 1 // Copyright 2019 Google LLC 2 // All Rights Reserved. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 using System; 17 using System.Collections.Generic; 18 using System.Text; 19 20 namespace Agones.Model 21 { 22 /// <summary> 23 /// A GameServer Custom Resource Definition object We will only export those resources that make the most sense. Can always expand to more as needed. 24 /// </summary> 25 public class GameServer : IEquatable<GameServer> 26 { 27 /// <summary> 28 /// Initializes a new instance of the <see cref="GameServer" /> class. 29 /// </summary> 30 public GameServer(IReadOnlyDictionary<string, object> data) 31 { 32 if (data == null) return; 33 34 this.ObjectMeta = new GameServerObjectMeta((Dictionary<string, object>) data["object_meta"]); 35 this.Spec = new GameServerSpec((Dictionary<string, object>) data["spec"]); 36 // Seems possible that the status field could be null, especially for local SDK tooling, 37 // so don't know an exception here if the conversion fails. 38 this.Status = new GameServerStatus(data["status"] as Dictionary<string, object>); 39 } 40 41 /// <summary> 42 /// Gets or Sets ObjectMeta 43 /// </summary> 44 public GameServerObjectMeta ObjectMeta { get; set; } 45 46 /// <summary> 47 /// Gets or Sets Spec 48 /// </summary> 49 public GameServerSpec Spec { get; set; } 50 51 /// <summary> 52 /// Gets or Sets Status 53 /// </summary> 54 public GameServerStatus Status { get; set; } 55 56 /// <summary> 57 /// Returns the string presentation of the object 58 /// </summary> 59 /// <returns>String presentation of the object</returns> 60 public override string ToString() 61 { 62 var sb = new StringBuilder(); 63 sb.Append("class GameServer {\n"); 64 sb.Append(" ObjectMeta: ").Append(ObjectMeta).Append("\n"); 65 sb.Append(" Spec: ").Append(Spec).Append("\n"); 66 sb.Append(" Status: ").Append(Status).Append("\n"); 67 sb.Append("}\n"); 68 return sb.ToString(); 69 } 70 71 /// <summary> 72 /// Returns true if objects are equal 73 /// </summary> 74 /// <param name="input">Object to be compared</param> 75 /// <returns>Boolean</returns> 76 public override bool Equals(object input) 77 { 78 return this.Equals(input as GameServer); 79 } 80 81 /// <summary> 82 /// Returns true if GameServer instances are equal 83 /// </summary> 84 /// <param name="input">Instance of GameServer to be compared</param> 85 /// <returns>Boolean</returns> 86 public bool Equals(GameServer input) 87 { 88 if (input == null) 89 return false; 90 91 return 92 ( 93 this.ObjectMeta == input.ObjectMeta || 94 (this.ObjectMeta != null && 95 this.ObjectMeta.Equals(input.ObjectMeta)) 96 ) && 97 ( 98 this.Spec == input.Spec || 99 (this.Spec != null && 100 this.Spec.Equals(input.Spec)) 101 ) && 102 ( 103 this.Status == input.Status || 104 (this.Status != null && 105 this.Status.Equals(input.Status)) 106 ); 107 } 108 109 /// <summary> 110 /// Gets the hash code 111 /// </summary> 112 /// <returns>Hash code</returns> 113 public override int GetHashCode() 114 { 115 unchecked // Overflow is fine, just wrap 116 { 117 int hashCode = 41; 118 if (this.ObjectMeta != null) 119 hashCode = hashCode * 59 + this.ObjectMeta.GetHashCode(); 120 if (this.Spec != null) 121 hashCode = hashCode * 59 + this.Spec.GetHashCode(); 122 if (this.Status != null) 123 hashCode = hashCode * 59 + this.Status.GetHashCode(); 124 return hashCode; 125 } 126 } 127 } 128 }