Remove legacy .NET attributes (#4190)

Remove legacy .NET attributes
This commit is contained in:
Mikhail Shilkov 2020-03-27 10:51:42 +01:00 committed by GitHub
parent 3eb3a0dec4
commit 6e15c83e1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 18 additions and 128 deletions

View file

@ -20,6 +20,9 @@ CHANGELOG
- Add support for enabling Policy Packs with configuration.
[#3756](https://github.com/pulumi/pulumi/pull/4127)
- Remove obsolete .NET serialization attributes.
[#4190](https://github.com/pulumi/pulumi/pull/4190)
## 1.13.0 (2020-03-18)
- Add support for plugin acquisition for Go programs
[#4060](https://github.com/pulumi/pulumi/pull/4060)

View file

@ -172,15 +172,6 @@ Pulumi.ResourceTransformationResult
Pulumi.ResourceTransformationResult.Args.get -> Pulumi.ResourceArgs
Pulumi.ResourceTransformationResult.Options.get -> Pulumi.ResourceOptions
Pulumi.ResourceTransformationResult.ResourceTransformationResult(Pulumi.ResourceArgs args, Pulumi.ResourceOptions options) -> void
Pulumi.Serialization.InputAttribute
Pulumi.Serialization.InputAttribute.InputAttribute(string name, bool required = false, bool json = false) -> void
Pulumi.Serialization.OutputAttribute
Pulumi.Serialization.OutputAttribute.Name.get -> string
Pulumi.Serialization.OutputAttribute.OutputAttribute(string name = null) -> void
Pulumi.Serialization.OutputConstructorAttribute
Pulumi.Serialization.OutputConstructorAttribute.OutputConstructorAttribute() -> void
Pulumi.Serialization.OutputTypeAttribute
Pulumi.Serialization.OutputTypeAttribute.OutputTypeAttribute() -> void
Pulumi.Stack
Pulumi.Stack.Stack(Pulumi.StackOptions options = null) -> void
Pulumi.StackOptions

View file

@ -23,22 +23,14 @@ namespace Pulumi
{
var fieldQuery =
from field in this.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)
let attr1 = field.GetCustomAttribute<Pulumi.InputAttribute>()
#pragma warning disable 618
let attr2 = field.GetCustomAttribute<Pulumi.Serialization.InputAttribute>()
#pragma warning restore 618
where attr1 != null || attr2 != null
let attr = attr1 ?? new Pulumi.InputAttribute(attr2.Name, attr2.IsRequired, attr2.Json)
let attr = field.GetCustomAttribute<InputAttribute>()
where attr != null
select (attr, memberName: field.Name, memberType: field.FieldType, getValue: (Func<object, object?>)field.GetValue);
var propQuery =
from prop in this.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)
let attr1 = prop.GetCustomAttribute<Pulumi.InputAttribute>()
#pragma warning disable 618
let attr2 = prop.GetCustomAttribute<Pulumi.Serialization.InputAttribute>()
#pragma warning restore 618
where attr1 != null || attr2 != null
let attr = attr1 ?? new Pulumi.InputAttribute(attr2.Name, attr2.IsRequired, attr2.Json)
let attr = prop.GetCustomAttribute<InputAttribute>()
where attr != null
select (attr, memberName: prop.Name, memberType: prop.PropertyType, getValue: (Func<object, object?>)prop.GetValue);
var all = fieldQuery.Concat(propQuery).ToList();

View file

@ -1,81 +0,0 @@
// Copyright 2016-2019, Pulumi Corporation
using System;
using Google.Protobuf.WellKnownTypes;
namespace Pulumi.Serialization
{
/// <summary>
/// Attribute used by a Pulumi Cloud Provider Package to mark Resource output properties.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
[Obsolete("Use Pulumi.OutputAttribute instead")]
public sealed class OutputAttribute : Attribute
{
public string? Name { get; }
public OutputAttribute(string? name = null)
{
Name = name;
}
}
/// <summary>
/// Attribute used by a Pulumi Cloud Provider Package to mark Resource input fields and
/// properties.
/// <para/>
/// Note: for simple inputs (i.e. <see cref="Input{T}"/> this should just be placed on the
/// property itself. i.e. <c>[Input] Input&lt;string&gt; Acl</c>.
///
/// For collection inputs (i.e. <see cref="InputList{T}"/> this should be placed on the
/// backing field for the property. i.e.
///
/// <code>
/// [Input] private InputList&lt;string&gt; _acls;
/// public InputList&lt;string&gt; Acls
/// {
/// get => _acls ?? (_acls = new InputList&lt;string&gt;());
/// set => _acls = value;
/// }
/// </code>
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
[Obsolete("Use Pulumi.InputAttribute instead")]
public sealed class InputAttribute : Attribute
{
internal string Name { get; }
internal bool IsRequired { get; }
internal bool Json { get; }
public InputAttribute(string name, bool required = false, bool json = false)
{
Name = name;
IsRequired = required;
Json = json;
}
}
/// <summary>
/// Attribute used by a Pulumi Cloud Provider Package to mark complex types used for a Resource
/// output property. A complex type must have a single constructor in it marked with the
/// <see cref="OutputConstructorAttribute"/> attribute.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
[Obsolete("Use Pulumi.OutputTypeAttribute instead")]
public sealed class OutputTypeAttribute : Attribute
{
}
/// <summary>
/// Attribute used by a Pulumi Cloud Provider Package to marks the constructor for a complex
/// property type so that it can be instantiated by the Pulumi runtime.
///
/// The constructor should contain parameters that map to the resultant <see
/// cref="Struct.Fields"/> returned by the engine.
/// </summary>
[AttributeUsage(AttributeTargets.Constructor)]
[Obsolete("Use Pulumi.OutputConstructorAttribute instead")]
public sealed class OutputConstructorAttribute : Attribute
{
}
}

View file

@ -113,10 +113,7 @@ namespace Pulumi.Serialization
$"Unexpected generic target type {targetType.FullName} when deserializing {context}");
}
if (targetType.GetCustomAttribute<Pulumi.OutputTypeAttribute>() == null
#pragma warning disable 618
&& targetType.GetCustomAttribute<Pulumi.Serialization.OutputTypeAttribute>() == null)
#pragma warning restore 618
if (targetType.GetCustomAttribute<Pulumi.OutputTypeAttribute>() == null)
return (null, new InvalidOperationException(
$"Unexpected target type {targetType.FullName} when deserializing {context}"));
@ -377,24 +374,21 @@ $@"{context} contains invalid type {targetType.FullName}:
}
}
var propertyTypeAttribute = (Attribute?)targetType.GetCustomAttribute<Pulumi.OutputTypeAttribute>()
#pragma warning disable 618
?? targetType.GetCustomAttribute<Pulumi.Serialization.OutputTypeAttribute>();
#pragma warning restore 618
var propertyTypeAttribute = (Attribute?)targetType.GetCustomAttribute<OutputTypeAttribute>();
if (propertyTypeAttribute == null)
{
throw new InvalidOperationException(
$@"{context} contains invalid type {targetType.FullName}. Allowed types are:
String, Boolean, Int32, Double,
Nullable<...>, ImmutableArray<...> and ImmutableDictionary<string, ...> or
a class explicitly marked with the [{nameof(Pulumi.OutputTypeAttribute)}].");
a class explicitly marked with the [{nameof(OutputTypeAttribute)}].");
}
var constructor = GetPropertyConstructor(targetType);
if (constructor == null)
{
throw new InvalidOperationException(
$@"{targetType.FullName} had [{nameof(Pulumi.OutputTypeAttribute)}], but did not contain constructor marked with [{nameof(Pulumi.OutputConstructorAttribute)}].");
$@"{targetType.FullName} had [{nameof(OutputTypeAttribute)}], but did not contain constructor marked with [{nameof(OutputConstructorAttribute)}].");
}
foreach (var param in constructor.GetParameters())
@ -405,9 +399,6 @@ $@"{targetType.FullName} had [{nameof(Pulumi.OutputTypeAttribute)}], but did not
private static ConstructorInfo GetPropertyConstructor(System.Type outputTypeArg)
=> outputTypeArg.GetConstructors(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).FirstOrDefault(
c => c.GetCustomAttributes<Pulumi.OutputConstructorAttribute>() != null
#pragma warning disable 618
|| c.GetCustomAttributes<Pulumi.Serialization.OutputConstructorAttribute>() != null);
#pragma warning restore 618
c => c.GetCustomAttributes<OutputConstructorAttribute>() != null);
}
}

View file

@ -63,12 +63,9 @@ namespace Pulumi.Serialization
var type = resource.GetResourceType();
var query = from property in resource.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)
let attr1 = property.GetCustomAttribute<Pulumi.OutputAttribute>()
#pragma warning disable 618
let attr2 = property.GetCustomAttribute<Pulumi.Serialization.OutputAttribute>()
#pragma warning restore 618
where attr1 != null || attr2 != null
select (property, attrName: attr1?.Name ?? attr2?.Name);
let attr = property.GetCustomAttribute<OutputAttribute>()
where attr != null
select (property, attrName: attr?.Name);
var result = ImmutableDictionary.CreateBuilder<string, IOutputCompletionSource>();
foreach (var (prop, attrName) in query.ToList())

View file

@ -81,12 +81,9 @@ namespace Pulumi
internal void RegisterPropertyOutputs()
{
var outputs = (from property in this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
let attr1 = property.GetCustomAttribute<Pulumi.OutputAttribute>()
#pragma warning disable 618
let attr2 = property.GetCustomAttribute<Pulumi.Serialization.OutputAttribute>()
#pragma warning restore 618
where attr1 != null || attr2 != null
let name = attr1?.Name ?? attr2?.Name ?? property.Name
let attr = property.GetCustomAttribute<OutputAttribute>()
where attr != null
let name = attr?.Name ?? property.Name
select new KeyValuePair<string, object?>(name, property.GetValue(this))).ToList();
// Check that none of the values are null: catch unassigned outputs