Thanks a lot, JB! May be it can be implemented to be automatically? :)

On 3 дек, 17:05, Jb Evain <[email protected]> wrote:
> Hey,
>
>
>
>
>
>
>
>
>
> On Fri, Dec 3, 2010 at 12:56 PM, Stanislav <[email protected]> 
> wrote:
> > This code must create local variable and init it by Attribute object
>
> >        public static void EmitAttributeInitialization(this
> > CustomAttribute attribute, MethodDefinition m0)
> >        {
> >            var module  = m0.Module;
> >            var emitter = m0.Body.GetILProcessor();
> >            var _Attribute = attribute.AttributeType;
>
> >            var __attrContainer = m0.Body.AddVariable(_Attribute);
> >            var ins = m0.Body.Instructions[0];
>
> >            var ctor = (MethodDefinition)(from f in
> > _Attribute.Resolve().Methods
> >                               where f.IsConstructor && f.IsPublic
> > select f).First();
>
> >            emitter.InsertBefore(ins, emitter.Create(OpCodes.Newobj,
> > ctor));
>
> You need to use:
>
> emitter.Create (OpCodes.Newobj, module.Import (ctor));
>
> If the attribute is defined in another module.
>
> Jb

-- 
--
mono-cecil

Reply via email to