sdk/dotnet/src/Microsoft.Datasync.Client/Serialization/DatasyncContractResolver.cs
/// <summary>
/// Returns a table name for a type, accounting for table renaming via the
/// <see cref="DataTableAttribute"/> and the <see cref="JsonContainerAttribute"/>.
/// </summary>
/// <param name="type">The type for which to return the table name.</param>
/// <returns>The table name.</returns>
Returns a table name for a type, accounting for table renaming via the
and the .
Returns a table name for a type accounting for table renaming via the and the .
public string ResolveTableName(Type type)
        {
            Arguments.IsNotNull(type, nameof(type));
            string name = null;
            lock (tableNameCache)
            {
                if (!tableNameCache.TryGetValue(type, out name))
                {
                    name = type.Name.ToLowerInvariant();
                    if (type.HasAttribute<JsonContainerAttribute>(out JsonContainerAttribute jsonattr))
                    {
                        if (!string.IsNullOrWhiteSpace(jsonattr.Title))
                        {
                            name = jsonattr.Title;
                        }
                    }
                    if (type.HasAttribute<DataTableAttribute>(out DataTableAttribute dtattr))
                    {
                        if (!string.IsNullOrWhiteSpace(dtattr.Name))
                        {
                            name = dtattr.Name;
                        }
                    }
                    tableNameCache[type] = name;
                    CreateContract(type);  
                }
            }
            return name;
        }
public string ResolveTableName ( Type type ) { Arguments . IsNotNull ( type , nameof ( type ) ) ; string name = null ; lock ( tableNameCache ) { if ( ! tableNameCache . TryGetValue ( type , out name ) ) { name = type . Name . ToLowerInvariant ( ) ; if ( type . HasAttribute < JsonContainerAttribute > ( out JsonContainerAttribute jsonattr ) ) { if ( ! string . IsNullOrWhiteSpace ( jsonattr . Title ) ) { name = jsonattr . Title ; } } if ( type . HasAttribute < DataTableAttribute > ( out DataTableAttribute dtattr ) ) { if ( ! string . IsNullOrWhiteSpace ( dtattr . Name ) ) { name = dtattr . Name ; } } tableNameCache [ type ] = name ; CreateContract ( type ) ; } } return name ; }
Returns a table name for a type, accounting for table renaming via the
and the .
Returns a table name for a type accounting for table renaming via the and the .
// Default is the name of the type, but lower-case. // Build a JsonContract now to catch any contract errors early
The table name.
The table name .
type
Type
The type for which to return the table name.
The type for which to return the table name .