diff --git a/src/NJsonSchema.CodeGeneration.CSharp/Models/ClassTemplateModel.cs b/src/NJsonSchema.CodeGeneration.CSharp/Models/ClassTemplateModel.cs
index 1bd6fd6be..0880ffd6b 100644
--- a/src/NJsonSchema.CodeGeneration.CSharp/Models/ClassTemplateModel.cs
+++ b/src/NJsonSchema.CodeGeneration.CSharp/Models/ClassTemplateModel.cs
@@ -39,6 +39,7 @@ public ClassTemplateModel(string typeName, CSharpGeneratorSettings settings,
.Select(property => new PropertyModel(this, property, _resolver, _settings))
.ToArray();
+ Id = _schema.Id;
if (schema.InheritedSchema != null)
{
BaseClass = new ClassTemplateModel(BaseClassName, settings, resolver, schema.InheritedSchema, rootObject);
@@ -50,6 +51,11 @@ public ClassTemplateModel(string typeName, CSharpGeneratorSettings settings,
}
}
+ ///
+ /// Id for the class instance
+ ///
+ public string Id { get; set; }
+
/// Gets or sets the class name.
public override string ClassName { get; }
diff --git a/src/NJsonSchema.CodeGeneration.CSharp/Models/PropertyModel.cs b/src/NJsonSchema.CodeGeneration.CSharp/Models/PropertyModel.cs
index 57eb54bc3..add98a3d6 100644
--- a/src/NJsonSchema.CodeGeneration.CSharp/Models/PropertyModel.cs
+++ b/src/NJsonSchema.CodeGeneration.CSharp/Models/PropertyModel.cs
@@ -33,8 +33,17 @@ public PropertyModel(
_property = property;
_settings = settings;
_resolver = typeResolver;
+
+ Id = property.Id;
+ if (property.Reference != null && string.IsNullOrEmpty(Id))
+ Id = property.Reference.Id;
}
+ ///
+ /// Id for the property
+ ///
+ public string Id { get; }
+
/// Gets the name of the property.
public string Name => _property.Name;