Skip to content

Commit

Permalink
ExtractGenericArgumentDataContextChangeAttribute, ex5tension friendly…
Browse files Browse the repository at this point in the history
… constructor added
  • Loading branch information
Milan Mikuš committed Oct 12, 2023
1 parent c901e2b commit f7a83fd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,23 @@ public class ExtractGenericArgumentDataContextChangeAttribute : DataContextChang
public override int Order { get; }

public ExtractGenericArgumentDataContextChangeAttribute(Type genericType, int typeArgumentIndex, int order = 0)
: this(new ResolvedTypeDescriptor(genericType), typeArgumentIndex, order)
{
}


public ExtractGenericArgumentDataContextChangeAttribute(ITypeDescriptor genericType, int typeArgumentIndex, int order = 0)
{
if (!genericType.IsGenericTypeDefinition)
{
throw new ArgumentException($"The {nameof(genericType)} argument must be a generic type definition!", nameof(genericType));
}
if (typeArgumentIndex < 0 || typeArgumentIndex >= genericType.GetGenericArguments().Length)
if (typeArgumentIndex < 0 || typeArgumentIndex >= genericType.GetGenericArguments()!.Length)
{
throw new ArgumentOutOfRangeException(nameof(typeArgumentIndex), $"The {nameof(typeArgumentIndex)} is not a valid index of a type argument!");
}

GenericType = new ResolvedTypeDescriptor(genericType);
GenericType = genericType;
TypeArgumentIndex = typeArgumentIndex;
Order = order;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public interface ITypeDescriptor
string CSharpName { get; }
/// <summary> Returns type name including namespace with generic arguments in the C# style. </summary>
string CSharpFullName { get; }
bool IsGenericTypeDefinition { get; }

bool IsAssignableTo(ITypeDescriptor typeDescriptor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public ResolvedTypeDescriptor(Type type)
public string CSharpName => Type.ToCode(stripNamespace: true);
public string CSharpFullName => Type.ToCode();

public bool IsGenericTypeDefinition => Type.IsGenericTypeDefinition;

public bool IsAssignableTo(ITypeDescriptor typeDescriptor)
{
return ToSystemType(typeDescriptor).IsAssignableFrom(Type);
Expand Down

0 comments on commit f7a83fd

Please sign in to comment.