Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PropertyEmitter"/> class.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="property">The property.</param>
        public PropertyEmitter(TypeEmitter parent, PropertyReference property, bool isStatic = false)
        {
            BackingField = property.GetBackingField();
            Parent       = parent;
            Target       = property as PropertyDefinition ?? property.Resolve();
            toStatic     = isStatic;

            if (Target.GetMethod != null)
            {
                getter = new MethodEmitter(parent, Target.GetMethod);
            }
            else
            {
                var existing = Parent.Target.GetMethod($"get_{Target.Name}", Target.PropertyType, new TypeReference[0], new GenericParameter[0]);
                if (existing != null)
                {
                    Target.GetMethod = existing.Resolve();
                    getter           = new MethodEmitter(parent, Target.GetMethod);
                }
            }

            if (Target.SetMethod != null)
            {
                setter = new MethodEmitter(parent, Target.SetMethod);
            }
            else
            {
                var existing = Parent.Target.GetMethod($"set_{Target.Name}", Target.Module.TypeSystem.Void, new[] { Target.PropertyType }, new GenericParameter[0]);
                if (existing != null)
                {
                    Target.SetMethod = existing.Resolve();
                    setter           = new MethodEmitter(parent, Target.SetMethod);
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MethodEmitter"/> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="method">The method.</param>
 public MethodEmitter(TypeEmitter parent, MethodReference method)
 {
     Parent = parent;
     Target = method as MethodDefinition ?? method.Resolve();
 }