Show / Hide Table of Contents

Class Utilities

A utility class which contains helper methods and extension methods.

Inheritance
object
Utilities
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Google.Apis.Util
Assembly: Google.Apis.Core.dll
Syntax
public static class Utilities

Methods

CheckArgument<T1, T2>(bool, string, string, T1, T2)

Checks that given argument-based condition is met, throwing an ArgumentException otherwise.

Declaration
public static void CheckArgument<T1, T2>(bool condition, string paramName, string format, T1 arg0, T2 arg1)
Parameters
Type Name Description
bool condition

The (already evaluated) condition to check.

string paramName

The name of the parameter whose value is being tested.

string format

The format string to use to create the exception message if the condition is not met.

T1 arg0

The first argument to the format string.

T2 arg1

The second argument to the format string.

Type Parameters
Name Description
T1
T2

CheckEnumValue<T>(T, string)

Checks that the given value is in fact defined in the enum used as the type argument of the method.

Declaration
public static T CheckEnumValue<T>(T value, string paramName) where T : struct
Parameters
Type Name Description
T value

The value to check.

string paramName

The name of the parameter whose value is being tested.

Returns
Type Description
T

value if it was a defined value

Type Parameters
Name Description
T

The enum type to check the value within.

ConvertToString(object)

Tries to convert the specified object to a string. Uses custom type converters if available. Returns null for a null object.

Declaration
public static string ConvertToString(object o)
Parameters
Type Name Description
object o
Returns
Type Description
string

DeserializeForGoogleFormat(string)

Deserializes the given raw value to an object using Instance, as if it were a JSON string value.

Declaration
public static object DeserializeForGoogleFormat(string rawValue)
Parameters
Type Name Description
string rawValue

The string value to deserialize. May be null, in which case null is returned.

Returns
Type Description
object

The deserialized value.

GetCustomAttribute<T>(MemberInfo)

A Google.Apis utility method for returning the first matching custom attribute (or null) of the specified member.

Declaration
public static T GetCustomAttribute<T>(this MemberInfo info) where T : Attribute
Parameters
Type Name Description
MemberInfo info
Returns
Type Description
T
Type Parameters
Name Description
T

GetDateTimeFromString(string)

Parses the input string and returns DateTime if the input is a valid representation of a date. Otherwise it returns null.

Declaration
public static DateTime? GetDateTimeFromString(string raw)
Parameters
Type Name Description
string raw
Returns
Type Description
DateTime?

GetDateTimeOffsetFromString(string)

Parses the input string and returns DateTimeOffset if the input is of the format "yyyy-MM-ddTHH:mm:ss.FFFZ" or "yyyy-MM-ddTHH:mm:ssZ". If the input is null, this method returns null. Otherwise, FormatException is thrown.

Declaration
public static DateTimeOffset? GetDateTimeOffsetFromString(string raw)
Parameters
Type Name Description
string raw
Returns
Type Description
DateTimeOffset?

GetEnumStringValue(Enum)

Returns the defined string value of an Enum. Use for test purposes or in other Google.Apis projects.

Declaration
public static string GetEnumStringValue(Enum value)
Parameters
Type Name Description
Enum value
Returns
Type Description
string

GetLibraryVersion()

Returns the version of the core library.

Declaration
public static string GetLibraryVersion()
Returns
Type Description
string

GetStringFromDateTime(DateTime?)

Returns a string (by RFC3339) form the input DateTime instance.

Declaration
public static string GetStringFromDateTime(DateTime? date)
Parameters
Type Name Description
DateTime? date
Returns
Type Description
string

GetStringFromDateTimeOffset(DateTimeOffset?)

Returns a string from the input DateTimeOffset instance, or null if date is null. The string is always in the format "yyyy-MM-ddTHH:mm:ss.fffZ" or "yyyy-MM-ddTHH:mm:ssZ" - always UTC, always either second or millisecond precision, and always using the invariant culture.

Declaration
public static string GetStringFromDateTimeOffset(DateTimeOffset? date)
Parameters
Type Name Description
DateTimeOffset? date
Returns
Type Description
string

SerializeForGoogleFormat(object)

Serializes the given value using Instance.

Declaration
public static string SerializeForGoogleFormat(object value)
Parameters
Type Name Description
object value

The value to serialize. May be null, in which case null is returned.

Returns
Type Description
string

The string representation of the object.

Exceptions
Type Condition
ArgumentException

The value does not serialize to a JSON string.

ThrowIfNullOrEmpty(string, string)

A Google.Apis utility method for throwing an ArgumentNullException if the string is null or empty.

Declaration
public static string ThrowIfNullOrEmpty(this string str, string paramName)
Parameters
Type Name Description
string str
string paramName
Returns
Type Description
string

The original string.

ThrowIfNull<T>(T, string)

A Google.Apis utility method for throwing an ArgumentNullException if the object is null.

Declaration
public static T ThrowIfNull<T>(this T obj, string paramName)
Parameters
Type Name Description
T obj
string paramName
Returns
Type Description
T
Type Parameters
Name Description
T
In this article
Back to top Generated by DocFX