Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal static class PluginExtentionMethods
- {
- private static Action<object, Plugin, string> _copier;
- static PluginExtentionMethods()
- {
- ParameterExpression instanceParam = Expression.Parameter(typeof(object), "instance");
- ParameterExpression destinationParam = Expression.Parameter(typeof(Plugin), "destination");
- ParameterExpression sourceParam = Expression.Parameter(typeof(string), "propName");
- BinaryExpression copyExp = Expression.Assign(Expression.Property(destinationParam, typeof(), Expression.Property(instanceParam, source.Name)));
- _copier = Expression.Lambda<Action<object, Plugin, string>>(copyExp, instanceParam, destinationParam, sourceParam).Compile();
- }
- /// <summary>
- /// Copy the value from the source property to the instance
- /// </summary>
- public static void Copy(this PropertyInfo source, Plugin destinationType, object instance)
- {
- _copier(instance, destinationType, source.Name);
- }
- }
- // note: there is a issue 'cause we can't past the property name. (the idea was to allow passing property names at the run-time, but it looks like we are not allowed to do that in c#)
- // this code was a snipped from a feature I was building to Subtitle Edit (Plugin system)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement