private static TypeModel CreateForAssemblyImpl(Assembly assembly, CompilerOptions options) { if (assembly == null) { throw new ArgumentNullException(nameof(assembly)); } lock (assembly) { var found = (TypeModel)s_assemblyModels[assembly]; if (found != null) { return(found); } RuntimeTypeModel model = null; foreach (var type in assembly.GetTypes()) { if (type.IsGenericTypeDefinition) { continue; } if (!IsFullyPublic(type)) { continue; } if (!type.IsDefined(typeof(ProtoContractAttribute), true)) { continue; } if (options != null && !options.OnIncludeType(type)) { continue; } (model ?? (model = RuntimeTypeModel.Create())).Add(type, true); } if (model == null) { throw new InvalidOperationException($"No types marked [ProtoContract] found in assembly '{assembly.GetName().Name}'"); } var compiled = model.Compile(options); s_assemblyModels[assembly] = compiled; return(compiled); } }