Skip to content

Commit

Permalink
localize obsolete messages in protogeo (#13580) (#13601)
Browse files Browse the repository at this point in the history
* move resx lookup to base class so libG can use it

* add new constructor for when we only know type name, but cant reference actual type

* can apply to different function types

* comments
  • Loading branch information
mjkkirschner authored Dec 5, 2022
1 parent 81e356c commit 8dcf850
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 30 deletions.
16 changes: 2 additions & 14 deletions src/DynamoCore/Graph/Nodes/Attributes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -210,20 +210,8 @@ public NodeObsoleteAttribute(string message)
{
}

public NodeObsoleteAttribute(string descriptionResourceID, Type resourceType)
public NodeObsoleteAttribute(string descriptionResourceID, Type resourceType):base(descriptionResourceID, resourceType)
{
if (resourceType == null)
throw new ArgumentNullException("resourceType");

var prop = resourceType.GetProperty(descriptionResourceID, BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic);
if (prop != null && prop.PropertyType == typeof(String))
{
Message = (string)prop.GetValue(null, null);
}
else
{
Message = descriptionResourceID;
}
}
}

Expand Down
74 changes: 58 additions & 16 deletions src/NodeServices/Attributes.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System;
using System.Collections;
using System.Reflection;

namespace Autodesk.DesignScript.Runtime
{
Expand Down Expand Up @@ -289,21 +290,62 @@ public PreferredShortNameAttribute(string preferredShortName)
/// <summary>
/// This attribute indicates the node is obsolete
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class IsObsoleteAttribute : Attribute
{
public string Message { get; protected set; }

public IsObsoleteAttribute()
{
Message = String.Empty;
}

public IsObsoleteAttribute(string message)
{
Message = message;
}
}
[AttributeUsage(AttributeTargets.Method| AttributeTargets.Constructor | AttributeTargets.Property)]
public class IsObsoleteAttribute : Attribute
{
public string Message { get; protected set; }

public IsObsoleteAttribute()
{
Message = String.Empty;
}

public IsObsoleteAttribute(string message)
{
Message = message;
}

/// <summary>
/// Attribute constructor which enables localized message lookup.
/// </summary>
/// <param name="descriptionResourceID">resx id for this resource</param>
/// <param name="resourceType">type that contains resource strings.</param>
/// <exception cref="ArgumentNullException"></exception>
public IsObsoleteAttribute(string descriptionResourceID, Type resourceType)
{
LookupResourceByID(descriptionResourceID, resourceType);
}
/// <summary>
/// Attribute constructor which enables localized message lookup.
/// </summary>
/// <param name="descriptionResourceID">resx id for this resource</param>
/// <param name="typeName">name of type that contains resource strings.
/// !!!Please note that in some .net contexts you must use the fully assembly qualified type name
/// including version,culture info etc. In others only the type, assembly name are required.
/// <see cref="Type.AssemblyQualifiedName"/> </param>
/// <exception cref="ArgumentNullException"></exception>
public IsObsoleteAttribute(string descriptionResourceID, string typeName)
{
var type = Type.GetType(typeName);
LookupResourceByID(descriptionResourceID, type);
}
private void LookupResourceByID(string descriptionResourceID, Type resourceType)
{
if (resourceType == null)
throw new ArgumentNullException(nameof(resourceType));

var prop = resourceType.GetProperty(descriptionResourceID,
BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic);
if (prop != null && prop.PropertyType == typeof(string))
{
Message = prop.GetValue(null, null) as string;
}
else
{
Message = descriptionResourceID;
}
}
}


/// <summary>
Expand Down

0 comments on commit 8dcf850

Please sign in to comment.