Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use partial templates like a files? #122

Open
VladShupik opened this issue Oct 19, 2022 · 1 comment
Open

How to use partial templates like a files? #122

VladShupik opened this issue Oct 19, 2022 · 1 comment

Comments

@VladShupik
Copy link

VladShupik commented Oct 19, 2022

Good evening! I would like to share my problem.
I am using your library, and I have one issue with partial views. So, I have 2 files .cshtml - 1) Main General file with . 2) Block

with some text from model.

I implemented custom MyBaseTemplateClass with Extension for Compile method as same as you share in your documentation. I saw Intellisence for Include methods etc. But when I am calling method compile my code crushed and the reason :
---> System.Reflection.AmbiguousMatchException: Ambiguous match found."
at System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
at System.Type.GetProperty(String name, BindingFlags bindingAttr).
COMPILE
INCLUDE

Also I attached my source files, second one when I use Include method and first where I create dictionary with 1 partial view and send to compile with main template file, may be you can help me and will say where I have mistake. Thanks for your time, have a nice day! P.S Before compile I read text from .cshtml and return string of template.

@VladShupik
Copy link
Author

@adoconnection, I found how to solve the problem that I wrote earlier. If we are used some classes with inheritance and classes have the same names of properties engine compile crushed. You have AnonymousTypeWrapper and method TryGetMember, on 24 line all broke with exception : "Ambiguous match found". So also I found link with the same problem. GetProperty reflection results(https://stackoverflow.com/questions/11443707/getproperty-reflection-results-in-ambiguous-match-found-on-new-property).

Problem

This is idea how can fix it -> PropertyInfo property = this.model.GetType().GetProperties().First(p => p.Name == binder.Name);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant