Announcement

Collapse
No announcement yet.

Usage of NonScriptableAttribute

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Usage of NonScriptableAttribute

    I'd like to add custom metadata to bridged classes for automatic processing by a windows app. In other words, I need to add custom attributes to class members, and those attributes should be ignored by the bridge transpiler.

    Is the following approach correct for this scenario?
    [NonScriptable]
    public sealed class MyCustomAttribute: Attribute
    {
    }
    And just another question in this context: Can the DLL's compiled by bridge be loaded via Assembly.Load() and then be inspected using regular .NET reflection?

    I'm developing a very interesting framework on top of Bridge and I'm hoping to setup some sort of partnership once it's completed. Are you open to this idea? Will share more details once I'm close to the finish line :-)

    Thanks!
    Marco

    #2
    Hi Marco,

    Your approach is correct, [NonScriptable] attribute will instruct Bridge to ignore the attribute type when emitting JavaScript. At the same time MyCustomAttribute will still be presented in the DLL's metadata, so you can process that attribute from within .NET apps.

    Regarding the question about reflection, as fabricio.murta mentioned here - Bridge doesn't use standard mscorlib assembly and this prevents Bridge assemblies from being loaded in the .NET Application Domain in a regular way. However, you can explore metadata using 3rd party libraries. For instance, this is how it's possible with Mono.Cecil:

    using System;
    using System.Linq;
    using Mono.Cecil;
    
    namespace MetadataDemo
    {
        class Program
        {
            static void Main()
            {
                var assembly = AssemblyDefinition.ReadAssembly(@"D:\BridgeDemo\bin\Debug\BridgeDemo.dll");
    
                foreach (var type in assembly.MainModule.Types)
                {
                    var hasMyCustomAttr = type.CustomAttributes.Any(x => x.AttributeType.Name == "MyCustomAttribute");
                    if (hasMyCustomAttr)
                    {
                        Console.WriteLine(type.FullName);
                    }
                }
            }
        }
    }
    Hope that helps.

    Comment


      #3
      Thanks a lot Andrey! You guys are my heroes! :-) I've been wrapping my head around this problem last night and just couldn't get the regular .NET reflection to read those assemblies. Now it all makes sense, and I was able to reproduce your sample successfully!

      Thanks so much! Now I can further pursue my idea. Will keep you posted once I have a close-to-finished product. Best regards, Marco

      Comment


        #4
        I'm developing a very interesting framework on top of Bridge and I'm hoping to setup some sort of partnership once it's completed. Are you open to this idea? Will share more details once I'm close to the finish line :-)
        Sounds interesting. Keep us updated on your process. Be sure to let us know if you have any questions or comments and we'll do our best to assist.

        Comment

        Working...
        X