NameOf
NameOf copied to clipboard
NameOf on insance is not (yet) supported
When I try to compile the following code:
using System;
using System.ComponentModel;
namespace NameOfTest
{
[ImmutableObject(true)]
public sealed class Foo
{
public Foo(string property)
{
Property = property;
}
public string Property { get; private set; }
}
class Program
{
[STAThread]
static void Main()
{
var foo = new Foo("bar");
Console.WriteLine(Name.Of(foo.Property));
}
}
}
Then I get the following compiler error:
1> Fody (version 1.27.1.0) Executing
1>MSBUILD : error : Fody: An unhandled exception occurred:
1>MSBUILD : error : Exception:
1>MSBUILD : error : This usage of 'Name.Of' is not supported. Source: c:\Users\Johann\Documents\Visual Studio 2013\Projects\NameOfTest\NameOfTest\Program.cs - line 23
1>MSBUILD : error : StackTrace:
1>MSBUILD : error : at NameOf.Fody.ModuleWeaver.ProcessNameOfCallInstruction(Instruction instruction, ILProcessor ilProcessor) in c:\Users\Nick\Documents\Visual Studio 2013\Projects\NameOf\NameOf.Fody\ModuleWeaver.cs:line 202
1>MSBUILD : error : at NameOf.Fody.ModuleWeaver.ProcessMethod(MethodDefinition methodDefinition) in c:\Users\Nick\Documents\Visual Studio 2013\Projects\NameOf\NameOf.Fody\ModuleWeaver.cs:line 75
1>MSBUILD : error : at NameOf.Fody.ModuleWeaver.Execute() in c:\Users\Nick\Documents\Visual Studio 2013\Projects\NameOf\NameOf.Fody\ModuleWeaver.cs:line 18
1>MSBUILD : error : at lambda_method(Closure , Object )
1>MSBUILD : error : at InnerWeaver.ExecuteWeavers(List`1 weaverInstances) in c:\ConsoleBuildAgent\work\ed448661dbb30d2e\FodyIsolated\InnerWeaver.cs:line 111
1>MSBUILD : error : at InnerWeaver.Execute() in c:\ConsoleBuildAgent\work\ed448661dbb30d2e\FodyIsolated\InnerWeaver.cs:line 51
1>MSBUILD : error : Source:
1>MSBUILD : error : NameOf.Fody
1>MSBUILD : error : TargetSite:
1>MSBUILD : error : Void ProcessNameOfCallInstruction(Mono.Cecil.Cil.Instruction, Mono.Cecil.Cil.ILProcessor)
1>MSBUILD : error :
1> Finished Fody 10ms.
Apparently it is simply not implemented yet.
Agreed, this particular case isn't matched by the current IL patterns. It looks like I need to flesh-out the unit tests and go over all the IL patterns.
I've added the pattern and your code works now. I've updated the NuGet package to 0.8.1. Thanks for your help and patience.
Is your issue resolved? Can I close this?
have not tried yet. will try later.
The issue still remains open:
using ...
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private NotifyTester _NotifyTester = new NotifyTester();
private AutoNotifyTester _AutoNotifyTester = new AutoNotifyTester();
public Form1()
{
InitializeComponent();
textBox1.DataBindings.Add(global::Name.Of(_NotifyTester.TestString), _NotifyTester, "testString", false, DataSourceUpdateMode.OnPropertyChanged);
textBox2.DataBindings.Add("Text", _NotifyTester, "TestString", false, DataSourceUpdateMode.OnPropertyChanged);
}
private void button1_Click(object sender, EventArgs e)
{
_NotifyTester.TestString = "Some value";
}
}
}
yields:
Error 2 Fody: An unhandled exception occurred:
Exception:
This usage of 'Name.Of' is not supported. Source: c:\Users\123456\Documents\Visual Studio 2012\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs - line 21
StackTrace:
at NameOf.Fody.ModuleWeaver.ProcessNameOfCallInstruction(Instruction instruction, ILProcessor ilProcessor) in c:\Users\nick.strupat\Documents\Visual Studio 2013\Projects\NameOf\NameOf.Fody\ModuleWeaver.cs:line 184
at NameOf.Fody.ModuleWeaver.ProcessMethod(MethodDefinition methodDefinition) in c:\Users\nick.strupat\Documents\Visual Studio 2013\Projects\NameOf\NameOf.Fody\ModuleWeaver.cs:line 69
at NameOf.Fody.ModuleWeaver.Execute() in c:\Users\nick.strupat\Documents\Visual Studio 2013\Projects\NameOf\NameOf.Fody\ModuleWeaver.cs:line 18
at lambda_method(Closure , Object )
at InnerWeaver.ExecuteWeavers() in c:\ConsoleBuildAgent\work\ed448661dbb30d2e\FodyIsolated\InnerWeaver.cs:line 164
at InnerWeaver.Execute() in c:\ConsoleBuildAgent\work\ed448661dbb30d2e\FodyIsolated\InnerWeaver.cs:line 82
Source:
NameOf.Fody
TargetSite:
Void ProcessNameOfCallInstruction(Mono.Cecil.Cil.Instruction, Mono.Cecil.Cil.ILProcessor)
WindowsFormsApplication1