242cf50726
* first pass of making Rhino work: more structs, nested types and some generic work * ignoring more types to compile * initial rhino check in. tabs on revit * more fixes? * rerun rhino * more generic fixes * more rhino fixes * add interfaces to structs and explicit interfaces * fix indexers and add exceptions * Compiles! * add more collections and better interface implementations * add static properties on structs * add static methods to structs * Deal with out values and System.Drawing * fmt * fix up Revit to have old properties/methods * rerun revit to be updated
52 lines
1.6 KiB
C#
52 lines
1.6 KiB
C#
using System.Text;
|
|
|
|
namespace Speckle.Shared;
|
|
|
|
public partial class Generator
|
|
{
|
|
private List<GeneratedConstructor> WriteConstructors(StringBuilder sb, Type clazz)
|
|
{
|
|
var generatedConstructor = new List<GeneratedConstructor>();
|
|
if (IsExcluded(clazz.Name, string.Empty))
|
|
{
|
|
return generatedConstructor;
|
|
}
|
|
var constructors = clazz.GetConstructors().ToList();
|
|
var emptyConstructor = constructors.FirstOrDefault(x => !x.GetParameters().Any());
|
|
if (emptyConstructor is not null)
|
|
{
|
|
constructors.Remove(emptyConstructor);
|
|
}
|
|
|
|
var constructorSb = new StringBuilder();
|
|
constructorSb.Append($"\tpublic {FormNameOnly(clazz)}(");
|
|
WriteMethodBody(constructorSb, [], clazz.BaseType, GeneratedType.Empty, false);
|
|
sb.Append(constructorSb);
|
|
generatedConstructor.Add(new GeneratedConstructor([]));
|
|
foreach (var constructor in constructors)
|
|
{
|
|
try
|
|
{
|
|
constructorSb = new StringBuilder();
|
|
constructorSb.Append($"\tpublic {FormNameOnly(clazz)}(");
|
|
var parameters = constructor.GetParameters();
|
|
WriteMethodBody(constructorSb, parameters, clazz.BaseType, GeneratedType.Class, false);
|
|
sb.Append(constructorSb);
|
|
generatedConstructor.Add(
|
|
new GeneratedConstructor(parameters.Select(x => new GeneratedParameter(x.ParameterType, x.Name)).ToList())
|
|
);
|
|
}
|
|
catch (FileLoadException)
|
|
{
|
|
Console.WriteLine($"Did not write a constructor on {clazz.FullName}");
|
|
}
|
|
catch (ApplicationException)
|
|
{
|
|
Console.WriteLine($"Did not write constructor on {clazz.FullName}");
|
|
}
|
|
}
|
|
|
|
return generatedConstructor;
|
|
}
|
|
}
|