private RealmObject.Metadata CreateRealmObjectMetadata(Schema.ObjectSchema schema) { var table = this.GetTable(schema); Weaving.IRealmObjectHelper helper; if (schema.Type != null && !Config.Dynamic) { var wovenAtt = schema.Type.GetCustomAttribute <WovenAttribute>(); if (wovenAtt == null) { throw new RealmException($"Fody not properly installed. {schema.Type.FullName} is a RealmObject but has not been woven."); } helper = (Weaving.IRealmObjectHelper)Activator.CreateInstance(wovenAtt.HelperType); } else { helper = Dynamic.DynamicRealmObjectHelper.Instance; } // build up column index in a loop so can spot and cache primary key index on the way var initColumnMap = new Dictionary <string, IntPtr>(); int initPrimaryKeyIndex = -1; foreach (var prop in schema) { var colIndex = NativeTable.GetColumnIndex(table, prop.Name); initColumnMap.Add(prop.Name, colIndex); if (prop.IsPrimaryKey) { initPrimaryKeyIndex = (int)colIndex; } } return(new RealmObject.Metadata { Table = table, Helper = helper, ColumnIndices = initColumnMap, PrimaryKeyColumnIndex = initPrimaryKeyIndex, Schema = schema }); }