Skip to main content

AnalyticsTools

A static class in Root.Township, Alta.Analytics.

Obsolete reflection serializer that turned records into the old DynamoDB-style JSON for Analytics.SendRecord. Builds and caches one serializer per type.

Fields​

4 private and internal fields
MemberWhat it is
private static readonly Type CompilerGeneratedFieldTypeThe CompilerGeneratedAttribute type, used to skip backing fields.
private static Logger loggerNLog logger for this class.
private static Dictionary<Type, AnalyticsTools.SerializeDelegate> serializationHandlersCache of built serializers by type.
private static StringBuilder stringBuilderShared builder reused by every Serialize call, so it is not thread safe.

Methods​

MemberWhat it is
static string Serialize(object target, AnalyticsOptions options = 0)Serializes an object to the old analytics JSON body, using the cached serializer for its type.
9 private and internal methods
MemberWhat it is
private static AnalyticsTools.SerializeDelegate CreateSerializationFunction(AnalyticsOptions options, List<AnalyticsTools.SerializeDelegate> serializationSteps)Builds the delegate that runs every field step and then adds timestamp, user ID and game time as the options say.
private static AnalyticsTools.SerializeDelegate CreateSerializationHandler(AnalyticsOptions options, Type targetType, Type serializeAttributeType)Builds and caches the serializer for a type, reading AnalyticsRecordForAll for its options.
private static AnalyticsTools.SerializeDelegate CreateSerializationStep(FieldInfo field, AnalyticsTools.FieldHandler howToSerializeThis, string fieldName)Builds the step that reads one field or property and writes it.
private static AnalyticsTools.SerializeDelegate CreateSerializationStep(PropertyInfo property, AnalyticsTools.FieldHandler howToSerializeThis, string fieldName)Builds the step that reads one field or property and writes it.
private static bool GetListFieldType(Type firstElementType, out string typeName)Gives the type code for a list (NS for numbers, SS for strings) or logs an error for other types.
private static void HandleEnumerableField(object fieldValue, StringBuilder logger)Writes a list field as a typed array.
private static void HandleField(object fieldValue, string fieldName, Type fieldType, StringBuilder logger)Writes one value with a type code: N for numbers, S for strings, vectors and Unity objects, BOOL for bools.
private static void SerializeFields(Type targetType, Type serializeAttributeType, bool isAddingAllFields, List<AnalyticsTools.SerializeDelegate> serializationSteps)Adds steps for the type's fields: all of them with AnalyticsRecordForAll, otherwise only marked ones.
private static void SerializeProperties(Type targetType, Type serializeAttributeType, bool isAddingAllFields, List<AnalyticsTools.SerializeDelegate> serializationSteps)Adds steps for the type's properties: all of them with AnalyticsRecordForAll, otherwise only marked ones.