/// <summary> /// Tries to parse a resource name in string form into a new <see cref="TopicNameOneof"/> instance. /// </summary> /// <remarks> /// To parse successfully the resource name must be one of the following: /// <list type="bullet"> /// <item><description>TopicName: A resource of type 'topic'.</description></item> /// <item><description>DeletedTopicNameFixed: A resource of type 'deleted_topic'.</description></item> /// </list> /// Or an <see cref="UnknownResourceName"/> if <paramref name="allowUnknown"/> is <c>true</c>. /// </remarks> /// <param name="name">The resource name in string form. Must not be <c>null</c>.</param> /// <param name="allowUnknown">If true, will successfully parse an unknown resource name /// into an <see cref="UnknownResourceName"/>.</param> /// <param name="result">When this method returns, the parsed <see cref="TopicNameOneof"/>, /// or <c>null</c> if parsing fails.</param> /// <returns><c>true</c> if the name was parsed succssfully; <c>false</c> otherwise.</returns> public static bool TryParse(string name, bool allowUnknown, out TopicNameOneof result) { GaxPreconditions.CheckNotNull(name, nameof(name)); TopicName topicName; if (TopicName.TryParse(name, out topicName)) { result = new TopicNameOneof(OneofType.TopicName, topicName); return(true); } DeletedTopicNameFixed deletedTopicNameFixed; if (DeletedTopicNameFixed.TryParse(name, out deletedTopicNameFixed)) { result = new TopicNameOneof(OneofType.DeletedTopicNameFixed, deletedTopicNameFixed); return(true); } if (allowUnknown) { UnknownResourceName unknownResourceName; if (UnknownResourceName.TryParse(name, out unknownResourceName)) { result = new TopicNameOneof(OneofType.Unknown, unknownResourceName); return(true); } } result = null; return(false); }
/// <summary> /// Construct a new instance of <see cref="TopicNameOneof"/> from the provided <see cref="DeletedTopicNameFixed"/> /// </summary> /// <param name="deletedTopicNameFixed">The <see cref="DeletedTopicNameFixed"/> to be contained within /// the returned <see cref="TopicNameOneof"/>. Must not be <c>null</c>.</param> /// <returns>A new <see cref="TopicNameOneof"/>, containing <paramref name="deletedTopicNameFixed"/>.</returns> public static TopicNameOneof From(DeletedTopicNameFixed deletedTopicNameFixed) => new TopicNameOneof(OneofType.DeletedTopicNameFixed, deletedTopicNameFixed);