/// <summary> /// Generates the serializers using specified assembly file. /// </summary> /// <param name="sourceAssembly">The source assembly.</param> /// <param name="includingPattern">The including regex pattern. Omitting indicates all public concrete types are included.</param> /// <param name="excludingPattern">The excluding regex pattern. Omitting indicates all public concrete types are included.</param> /// <returns>File pathes to the generated source codes.</returns> /// <remarks> /// Specifying both of <paramref name="includingPattern"/> and <paramref name="excludingPattern"/> indicates AND condition. /// </remarks> public IEnumerable <string> GenerateSerializers( Assembly sourceAssembly, string includingPattern, string excludingPattern, bool admitNonPublicTypes ) { if (sourceAssembly == null) { throw new ArgumentNullException("sourceAssembly"); } if (!String.IsNullOrEmpty(includingPattern)) { includingPattern = includingPattern.Trim(); } if (!String.IsNullOrEmpty(excludingPattern)) { excludingPattern = excludingPattern.Trim(); } var includingRegex = String.IsNullOrEmpty(includingPattern) ? null : new Regex(includingPattern, RegexOptions.Compiled | RegexOptions.ExplicitCapture); var excludingRegex = String.IsNullOrEmpty(excludingPattern) ? null : new Regex(excludingPattern, RegexOptions.Compiled | RegexOptions.ExplicitCapture); return (SerializerGenerator.GenerateCode( this._configuration, sourceAssembly.GetTypes() .Where( type => (admitNonPublicTypes || type.IsPublic) && !type.IsAbstract && !type.IsInterface && (includingRegex == null || includingRegex.IsMatch(type.FullName)) && (excludingRegex == null || !excludingRegex.IsMatch(type.FullName)) ).ToArray() )); }
public void Generate() { var applicationLibraryAssembly = typeof(ProtocolMessage).Assembly; SerializerGenerator.GenerateCode( new SerializerCodeGenerationConfiguration { Namespace = "IO.Ably.CustomSerialisers", OutputDirectory = "../../../IO.Ably/CustomSerialisers/GeneratedSerializers", EnumSerializationMethod = EnumSerializationMethod.ByName, // You can tweak it to use ByUnderlyingValue as you like. IsRecursive = true, // Set depenendent serializers are also generated. PreferReflectionBasedSerializer = false, // Set true if you want to use reflection based collection serializer, false if you want to get generated collection serializers. SerializationMethod = SerializationMethod.Map // You tweak it to generate 'map' based serializers. }, applicationLibraryAssembly.GetTypes().Where(type => type == typeof(TokenRequest) //type == typeof(Message) || type == typeof(ProtocolMessage) || type == typeof(PresenceMessage) || //type == typeof(PaginatedResult<Stats>) || type == typeof(TokenDetails) || type == typeof(Stats) ///* ...you can filter types to be serialized by their namespace, custom attributes, etc... */ ) ); }