How to read baseclass attribute #419
Replies: 9 comments 2 replies
-
If I understood you correctly, you are looking to find all the properties of an attribute attached to a field, including the properties defined in any of its base classes. Assuming you have your field stored in a var attribute = field.CustomAttributes.First(x => x.Constructor?.DeclaringType.Name == "OutputExecutionPortAttribute");
var type = attribute.Constructor.DeclaringType.Resolve(); Then, it is a matter of iterating all its properties, while also iterating all base types of the type: var properties = new List<PropertyDefinition>();
while (type is not null)
{
properties.AddRange(type.Properties);
type = type.BaseType?.Resolve();
} |
Beta Was this translation helpful? Give feedback.
-
yes. Thanks for quick reply. One more last query in below I need all
ConfigurationParameter when I start with TestNode Class
TestNode : PlatformVisualNode<TestNodeConfiguration>
{}
public class TestNodeConfiguration : BaseNodeConfiguration
{
[ConfigurationParameter]
public string text { get; set; }
}
public class BaseNodeConfiguration : BaseConfiguration
{
[ConfigurationParameter]
public bool IsProvider { get; set; }
}
public class BaseNodeConfiguration :Interface
{ [ConfigurationParameter]
public bool IsProvider1 { get; set; }
}
…On Wed, Mar 8, 2023 at 7:52 PM Washi ***@***.***> wrote:
If I understood you correctly, you are looking to find all the properties
of an attribute attached to a field, including the properties defined in
any of its base classes.
Assuming you have your field stored in a FieldDefinition field, you can
get its custom attributes and its corresponding type definition using
something like the following:
var attribute = field.CustomAttributes.First(x => x.Constructor?.DeclaringType.Name == "OutputExecutionPortAttribute");var type = attribute.Constructor.DeclaringType.Resolve();
Then, it is a matter of iterating all its properties, while also iterating
all base types of the type:
var properties = new List<PropertyDefinition>();while (type is not null)
{
properties.AddRange(type.Properties);
type = type.BaseType?.Resolve();
}
—
Reply to this email directly, view it on GitHub
<#419 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AM4MS6Y5TOPKQQJEQPMG2FLW3CI3RANCNFSM6AAAAAAVTVXX4E>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Can you please help with typesignature ? Today i was struggling to get that
…On Wednesday, March 8, 2023, Washi ***@***.***> wrote:
It would be a similar approach, where you'd traverse all types, their
properties and read their custom attributes. You can read more about
traversing the member tree on this page
<https://asmresolver.readthedocs.io/en/latest/dotnet/member-tree.html>.
Also, PlatformVisualNode<TestNodeConfiguration> is going to be a
TypeSpecification with a TypeSignature in it, you may also want to have a
look at the docs on type signatures
<https://asmresolver.readthedocs.io/en/latest/dotnet/type-signatures.html>
as well :).
—
Reply to this email directly, view it on GitHub
<#419 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AM4MS66MQCXNUA5ZZWATHOTW3CY23ANCNFSM6AAAAAAVTVXX4E>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
Regards,
Sneha Bihani
Mob:9960298364
|
Beta Was this translation helpful? Give feedback.
-
Please help
…On Wednesday, March 8, 2023, Sneha Bihani ***@***.***> wrote:
Can you please help with typesignature ? Today i was struggling to get
that
On Wednesday, March 8, 2023, Washi ***@***.***> wrote:
> It would be a similar approach, where you'd traverse all types, their
> properties and read their custom attributes. You can read more about
> traversing the member tree on this page
> <https://asmresolver.readthedocs.io/en/latest/dotnet/member-tree.html>.
> Also, PlatformVisualNode<TestNodeConfiguration> is going to be a
> TypeSpecification with a TypeSignature in it, you may also want to have
> a look at the docs on type signatures
> <https://asmresolver.readthedocs.io/en/latest/dotnet/type-signatures.html>
> as well :).
>
> —
> Reply to this email directly, view it on GitHub
> <#419 (reply in thread)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AM4MS66MQCXNUA5ZZWATHOTW3CY23ANCNFSM6AAAAAAVTVXX4E>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
--
Regards,
Sneha Bihani
Mob:9960298364
--
Regards,
Sneha Bihani
Mob:9960298364
|
Beta Was this translation helpful? Give feedback.
-
You have to be a bit more specific with what you'd need help with 😅. What part do you struggle with?
|
Beta Was this translation helpful? Give feedback.
-
How to get type signature and tyere attributes
…On Thursday, March 9, 2023, Washi ***@***.***> wrote:
You have to be a bit more specific with what you'd need help with 😅.
What part do you struggle with?
PlatformVisualNode<TestNodeConfiguration> is going to be a
GenericInstanceTypeSignature wrapped in a TypeSpecification. You'd have
to check whether the type's base type is such a type specification, and act
accordingly.
—
Reply to this email directly, view it on GitHub
<#419 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AM4MS647BFWE44NCY6LEHFDW3EFWVANCNFSM6AAAAAAVTVXX4E>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
Regards,
Sneha Bihani
Mob:9960298364
|
Beta Was this translation helpful? Give feedback.
-
var typeSignature = basetype.ToTypeSignature(); if
(typeSignature.ElementType == ElementType.GenericInst) { }
How to get list of arguments from here
Regards,
Sneha Bihani
Mob:9960298364
…On Thu, Mar 9, 2023 at 6:58 AM Sneha Bihani ***@***.***> wrote:
How to get type signature and tyere attributes
On Thursday, March 9, 2023, Washi ***@***.***> wrote:
> You have to be a bit more specific with what you'd need help with 😅.
> What part do you struggle with?
>
> PlatformVisualNode<TestNodeConfiguration> is going to be a
> GenericInstanceTypeSignature wrapped in a TypeSpecification. You'd have
> to check whether the type's base type is such a type specification, and act
> accordingly.
>
> —
> Reply to this email directly, view it on GitHub
> <#419 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AM4MS647BFWE44NCY6LEHFDW3EFWVANCNFSM6AAAAAAVTVXX4E>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
--
Regards,
Sneha Bihani
Mob:9960298364
|
Beta Was this translation helpful? Give feedback.
-
I got it. Thanks a lot for quick response.
…On Thu, Mar 9, 2023 at 10:32 AM Sneha Bihani ***@***.***> wrote:
var typeSignature = basetype.ToTypeSignature(); if
(typeSignature.ElementType == ElementType.GenericInst) { }
How to get list of arguments from here
Regards,
Sneha Bihani
Mob:9960298364
On Thu, Mar 9, 2023 at 6:58 AM Sneha Bihani ***@***.***> wrote:
> How to get type signature and tyere attributes
>
> On Thursday, March 9, 2023, Washi ***@***.***> wrote:
>
>> You have to be a bit more specific with what you'd need help with 😅.
>> What part do you struggle with?
>>
>> PlatformVisualNode<TestNodeConfiguration> is going to be a
>> GenericInstanceTypeSignature wrapped in a TypeSpecification. You'd have
>> to check whether the type's base type is such a type specification, and act
>> accordingly.
>>
>> —
>> Reply to this email directly, view it on GitHub
>> <#419 (comment)>,
>> or unsubscribe
>> <https://github.com/notifications/unsubscribe-auth/AM4MS647BFWE44NCY6LEHFDW3EFWVANCNFSM6AAAAAAVTVXX4E>
>> .
>> You are receiving this because you authored the thread.Message ID:
>> ***@***.***>
>>
>
>
> --
> Regards,
> Sneha Bihani
> Mob:9960298364
>
>
|
Beta Was this translation helpful? Give feedback.
-
I have struct defined in another assembly not referenced in my project but
I want to create instance for that how we can do?
Activator.CreateInstance(System.Type.GetType(prop.Type.FullName)
Microsoft.Maui.Gridlenth but it is not referenced.
…On Thu, Mar 9, 2023 at 11:08 AM Sneha Bihani ***@***.***> wrote:
I got it. Thanks a lot for quick response.
On Thu, Mar 9, 2023 at 10:32 AM Sneha Bihani ***@***.***> wrote:
> var typeSignature = basetype.ToTypeSignature(); if
> (typeSignature.ElementType == ElementType.GenericInst) { }
> How to get list of arguments from here
> Regards,
> Sneha Bihani
> Mob:9960298364
>
>
> On Thu, Mar 9, 2023 at 6:58 AM Sneha Bihani ***@***.***> wrote:
>
>> How to get type signature and tyere attributes
>>
>> On Thursday, March 9, 2023, Washi ***@***.***> wrote:
>>
>>> You have to be a bit more specific with what you'd need help with 😅.
>>> What part do you struggle with?
>>>
>>> PlatformVisualNode<TestNodeConfiguration> is going to be a
>>> GenericInstanceTypeSignature wrapped in a TypeSpecification. You'd
>>> have to check whether the type's base type is such a type specification,
>>> and act accordingly.
>>>
>>> —
>>> Reply to this email directly, view it on GitHub
>>> <#419 (comment)>,
>>> or unsubscribe
>>> <https://github.com/notifications/unsubscribe-auth/AM4MS647BFWE44NCY6LEHFDW3EFWVANCNFSM6AAAAAAVTVXX4E>
>>> .
>>> You are receiving this because you authored the thread.Message ID:
>>> ***@***.***
>>> com>
>>>
>>
>>
>> --
>> Regards,
>> Sneha Bihani
>> Mob:9960298364
>>
>>
|
Beta Was this translation helpful? Give feedback.
-
I want to get attribute "OutputExecutionPort" properties including base class.
Please help
Beta Was this translation helpful? Give feedback.
All reactions