mikehillberg / middleweight-reflection Goto Github PK
View Code? Open in Web Editor NEW.Net library to read .Net Assembly and Windows WinMD metadata files, based on System.Reflection.Metadata
License: MIT License
.Net library to read .Net Assembly and Windows WinMD metadata files, based on System.Reflection.Metadata
License: MIT License
// var g = t.GetGenericTypeParameters(); // t is "IList<Windows.UI.Xaml.Controls.MenuFlyoutBase>"
g.GetBaseType()
wrongly returns null
re-fetching the type from the LoadContext based on GetFullName() gets an MrType object with the right base type
MyUserControl
(inherits from Windows.UI.Xaml.UserControl
)context.LoadAssemblyFromPath( )
called once for Windows.winmd
, and once for RuntimeComponent.winmd
MyUserControl
type (e.g. iterate via winmd.GetAllTypes()
)calling type.GetBaseType()
returns null instead of Windows.UI.Xaml.UserControl
properly resolves to the type in the other assembly that's loaded in the context
When a parameter type or return type is something like Windows.Foundation.Collections.IVector`1
, it gets reported back as its .net projection System.Collections.Generic.IList`1
, even when the load context has the "use winrt projection" option set.
Is there a way to map back to the WF type, or do I have to keep a mapping of the type names and convert it in my app?
prop
{MrProperty: ContentControl.Content}
Attributes: None
DeclaringType: {Windows.UI.Xaml.Controls.ContentControl}
Definition: {System.Reflection.Metadata.PropertyDefinition}
DefinitionHandle: {System.Reflection.Metadata.PropertyDefinitionHandle}
Getter: {MrMethod: ContentControl.get_Content}
Setter: {MrMethod: ContentControl.put_Content}
contentProperty
{MrProperty: ContentControl.Content}
Attributes: None
DeclaringType: {Windows.UI.Xaml.Controls.ContentControl}
Definition: {System.Reflection.Metadata.PropertyDefinition}
DefinitionHandle: {System.Reflection.Metadata.PropertyDefinitionHandle}
Getter: {MrMethod: ContentControl.get_Content}
Setter: {MrMethod: ContentControl.put_Content}
prop == contentProperty
false
I have an attribute and I want to reflect over its AttributeUsage attribute
However when I get the AttributeUsageAttribute instance, doing GetArguments(,) returns no fixed nor named args.
given a MrProperty prop
whose type I expect to be Object,
prop.GetPropertyType().TypeCode
is 0 (not set)
// get a MrType of WUX.Media.Animation.TransitionCollection
var t = LoadContext.GetType("Windows.UI.Xaml.Media.Animation.TransitionCollection");
t.GetMethodsAndConstructors(out var methods, out var ctors);
var insertAt = methods.First(m => m.GetName() == "InsertAt");
This throws, the methods array is empty
I'd like to be able to create an instance of MrType at runtime, that is not backed by any real type, is this possible?
var context = new MrLoadContext();
throws Expected assembly name 'mscorlib', actual is 'System.Private.CoreLib'
:
However for .net core 5, mscorlib seems to be mapped to System.Private.CoreLib. The throwing code is:
I have a type/method that I've added [deprecated("foo", deprecate, 1)]
to.
ca.GetArguments(out var fixedArgs, out var namedArgs);
both argument lists are empty, because it's trying to resolve the custom attribute in the same Assembly
where it is applied to.
The code correctly identifies the need to resolve DeprecationType
in the Windows.FoundationContract
assembly, but this is marked as a fake assembly, so it calls RaiseFakeTypeRequired
, but the FakeTypeRequired
event handler is null.
Update:
The solution is to do something like:
context.FakeTypeRequired += (sender, e) => {
var ctx = sender as MrLoadContext;
if (e.AssemblyName == "Windows.Foundation.FoundationContract")
{
e.ReplacementType = ctx.GetTypeFromAssembly(e.TypeName, "Windows");
}
};
This should probably be a default though, or at least documented :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.