Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding reference constructors attributes #20611

Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;

namespace Azure.ResourceManager.Core
{
/// <summary>
/// An attribute class indicating the constructor to use for initialization.
/// </summary>
[AttributeUsage(AttributeTargets.Constructor)]
public class InitializationConstructor : Attribute
{
/// <summary>
/// Instatiate a new InitializationConstructor attribute.
/// </summary>
public InitializationConstructor()
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ namespace Azure.ResourceManager.Core
/// A class representing the base resource used by all azure resources.
/// </summary>
[ReferenceType(typeof(TenantResourceIdentifier))]
public class Resource<TIdentifier> : IEquatable<Resource<TIdentifier>>, IEquatable<string>,
public abstract class Resource<TIdentifier> : IEquatable<Resource<TIdentifier>>, IEquatable<string>,
IComparable<Resource<TIdentifier>>, IComparable<string> where TIdentifier : TenantResourceIdentifier
{
/// <summary>
/// Initializes an empty instance of <see cref="Resource{TIdentifier}"/>.
/// </summary>
public Resource() { }
[InitializationConstructor]
protected Resource() { }

/// <summary>
/// Initializes a new instance of <see cref="Resource{TIdentifier}"/> for deserialization.
/// </summary>
/// <param name="id"> The id of the resource. </param>
/// <param name="name"> The name of the resource. </param>
/// <param name="type"> The <see cref="ResourceType"/> of the resource. </param>
[SerializationConstructor]
protected Resource(TIdentifier id, string name, ResourceType type)
{
Id = id;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;

namespace Azure.ResourceManager.Core
{
/// <summary>
/// An attribute class indicating the constructor to use for serialization.
/// </summary>
[AttributeUsage(AttributeTargets.Constructor)]
public class SerializationConstructor : Attribute
{
/// <summary>
/// Instatiate a new SerializationConstructor attribute.
/// </summary>
public SerializationConstructor()
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ public partial class SubResource
/// <summary>
/// Initializes an empty instance of <see cref="SubResource"/>.
/// </summary>
public SubResource() { }
[InitializationConstructor]
protected SubResource() { }

/// <summary> Initializes a new instance of SubResource. </summary>
/// <param name="id"> ARM resource Id. </param>
[SerializationConstructor]
protected internal SubResource(string id)
{
Id = id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ namespace Azure.ResourceManager.Core
/// Generic representation of a tracked resource. All tracked resources should extend this class
/// </summary>
[ReferenceType(typeof(TenantResourceIdentifier))]
public partial class TrackedResource<TIdentifier> : Resource<TIdentifier>
public abstract partial class TrackedResource<TIdentifier> : Resource<TIdentifier>
where TIdentifier : TenantResourceIdentifier
{
/// <summary>
/// Initializes an empty instance of <see cref="TrackedResource{TIdentifier}"/>.
/// </summary>
public TrackedResource(LocationData location)
[InitializationConstructor]
protected TrackedResource(LocationData location)
{
Location = location;
}
Expand All @@ -29,6 +30,7 @@ public TrackedResource(LocationData location)
/// <param name="type"> The <see cref="ResourceType"/> of the resource. </param>
/// <param name="tags"> The tags for the resource. </param>
/// <param name="location"> The location of the resource. </param>
[SerializationConstructor]
protected TrackedResource(TIdentifier id, string name, ResourceType type, IDictionary<string, string> tags, LocationData location)
: base(id, name, type)
{
Expand Down