NickStrupat / NameOf

Provides strongly typed access to a compile-time string representing the name of a variable, field, property, method, event, enum, or type.
MIT License
20 stars 7 forks source link

Use a property of a type in a different assembly #11

Open buddde opened 7 years ago

buddde commented 7 years ago

Hello,

I really like your project. I want to use it in one assembly and use types which can be found in a different assembly.

Unfortunately, that does not work currently.

I was able to fix the issue by inserting the an additional pattern in NameOf.Fody.ModuleWeaver.nameOfCallPatterns:

new [] {
    new PatternInstruction(OpCodes.Callvirt, (i, p) => ((MethodReference)i.Operand).Name.Substring(4), (i, p) => ((MethodReference)i.Operand).Resolve().IsGetter),
    new OptionalPatternInstruction(OpCodes.Box),
    new NameOfPatternInstruction(),
}

This way, it works in your test-project. But when using this modified version of NameOf, I encounter errors by Fody:

MSBUILD : error : Fody: An unhandled exception occurred: MSBUILD : error : Exception: MSBUILD : error : Object reference not set to an instance of an object. MSBUILD : error : StackTrace: MSBUILD : error : at NameOf.Fody.ModuleWeaver.Execute() MSBUILD : error : at lambda_method(Closure , Object ) MSBUILD : error : at InnerWeaver.ExecuteWeavers() in c:\ConsoleBuildAgent\work\ed448661dbb30d2e\FodyIsolated\InnerWeaver.cs:line 144. MSBUILD : error : at InnerWeaver.Execute() in c:\ConsoleBuildAgent\work\ed448661dbb30d2e\FodyIsolated\InnerWeaver.cs:line 62. MSBUILD : error : Source: MSBUILD : error : NameOf.Fody MSBUILD : error : TargetSite: MSBUILD : error : Void Execute() MSBUILD : error :

Now, I do not know what to do.

Can you please help me?

Thank you.