예제 #1
0
        private void CompareTypes()
        {
            IEnumerable <string> referenceTypes = GetTypeNames(() => ReferenceType.DefinedTypes).ToList();
            IEnumerable <string> newTypes       = GetTypeNames(() => NewType.DefinedTypes).ToList();

            // Missing types
            foreach (string type in referenceTypes.Except(newTypes))
            {
                ComparerResult.AddRemovedItem(GetItemType(ReferenceType.GetType(type)), type, Severity.Error);
            }

            // New types
            foreach (string type in newTypes.Except(referenceTypes))
            {
                ComparerResult.AddAddedItem(GetItemType(NewType.GetType(type)), type, Severity.Warning);
            }

            // Equal types
            foreach (string type in referenceTypes.Intersect(newTypes))
            {
                ComparerResult.AddComparerResult(ComparerContext.CreateComparer(ReferenceType.GetType(type), NewType.GetType(type)).Compare());
            }
        }
예제 #2
0
 public ConstructorInstance(ConstructorInfo constructor)
     : base(NewType.GetType(constructor.DeclaringType), constructor.Attributes, NewType.VOID_TYPE, CONSTRUCTOR_NAME,
            TypeUtil.GetClassesToTypes(constructor.GetParameters()))
 {
     this.method = constructor;
 }
예제 #3
0
 public ConstructorInstance(Type owner, MethodAttributes access, params Type[] parameters)
     : base(NewType.GetType(owner), access, NewType.VOID_TYPE, CONSTRUCTOR_NAME, TypeUtil.GetClassesToTypes(parameters))
 {
     // Intended blank
 }
예제 #4
0
 public FieldInstance(FieldInfo field)
     : this(NewType.GetType(field.DeclaringType), field.Attributes, field.Name, NewType.GetType(field.FieldType))
 {
     this.field = field;
 }
예제 #5
0
 public FieldInstance(NewType owner, FieldAttributes access, String name, Type type)
     : this(owner, access, name, NewType.GetType(type))
 {
     // Intended blank
 }
예제 #6
0
        public virtual FieldInstance ImplementStaticAssignedField(String staticFieldName, Type fieldType, Object fieldValue)
        {
            FieldInstance field = new FieldInstance(FieldAttributes.Public | FieldAttributes.Static, staticFieldName, NewType.GetType(fieldType));

            field = ImplementField(field, null);
            field = HideFromDebug(field);
            if (fieldValue != null)
            {
                IValueResolveDelegate vrd = null;
                if (fieldValue is IValueResolveDelegate)
                {
                    vrd = (IValueResolveDelegate)fieldValue;
                }
                else
                {
                    vrd = new NoOpValueResolveDelegate(fieldValue);
                }
                ((BytecodeBehaviorState)State).QueueFieldInitialization(field.Name, vrd);
            }
            return(field);
        }
예제 #7
0
 public void Visit(TypeAttributes access, String name, Type superName, Type[] interfaces)
 {
     tb                = ambethClassLoader.CreateNewType(access, name, superName, interfaces);
     newType           = NewType.GetType(tb);
     ambethClassLoader = null;
 }
예제 #8
0
 protected static NewType GetReturnType(MethodBase method)
 {
     return(method is MethodInfo?NewType.GetType(((MethodInfo)method).ReturnType) : NewType.VOID_TYPE);
 }
예제 #9
0
        public virtual IMethodVisitor VisitMethod(MethodInstance method)
        {
            NewType owner = State.NewType;

            method = method.DeriveOwner();
            if (Log.DebugEnabled && !State.OriginalType.Name.Contains("Member"))
            {
                Log.Debug("Implement method: " + method.ToString());
            }
            Type[] parameters = new Type[method.Parameters.Length];
            for (int a = parameters.Length; a-- > 0;)
            {
                parameters[a] = method.Parameters[a].Type;
            }
            MethodAttributes access = method.Access;

            if (ConstructorInstance.CONSTRUCTOR_NAME.Equals(method.Name))
            {
                ConstructorBuilder mb = tb.DefineConstructor(access, access.HasFlag(MethodAttributes.Static) ? CallingConventions.Standard : CallingConventions.HasThis, parameters);
                ((BytecodeBehaviorState)State).MethodImplemented(new ConstructorInstance(newType, mb, method.Parameters));
                sb.Append("\r\n" + method.ToString());
                return(new MethodWriter(mb, new ConstructorInstance(owner, mb, method.Parameters), sb));
            }
            else
            {
                PropertyInstance propertyInfo = null;
                Object           eventInfo    = null;
                if (!access.HasFlag(MethodAttributes.Static))
                {
                    access |= MethodAttributes.Virtual;
                }
                access |= MethodAttributes.HideBySig;
                access |= MethodAttributes.ReuseSlot;
                access &= ~MethodAttributes.VtableLayoutMask;
                String propertyName = null, eventName = null;
                Type   propertyType = null;
                if (method.Name.StartsWith("get_") && method.Parameters.Length == 0)
                {
                    propertyName = method.Name.Substring(4);
                    propertyType = method.ReturnType.Type;
                }
                else if (method.Name.StartsWith("set_") && method.Parameters.Length == 1)
                {
                    propertyName = method.Name.Substring(4);
                    propertyType = method.Parameters[0].Type;
                }
                else if (method.Name.StartsWith("add_") && method.Parameters.Length == 1)
                {
                    eventName    = method.Name.Substring(4);
                    propertyType = method.Parameters[0].Type;
                }
                else if (method.Name.StartsWith("remove_") && method.Parameters.Length == 1)
                {
                    eventName    = method.Name.Substring(7);
                    propertyType = method.Parameters[0].Type;
                }
                if (propertyName != null)
                {
                    propertyInfo = State.GetProperty(propertyName, NewType.GetType(propertyType));
                    if (propertyInfo == null)
                    {
#if SILVERLIGHT
                        PropertyInfo pi = tb.DefineProperty(propertyName, PropertyAttributes.None, propertyType, null);
#else
                        CallingConventions cc = access.HasFlag(MethodAttributes.Static) ? CallingConventions.Standard : CallingConventions.HasThis;

                        PropertyInfo pi = tb.DefineProperty(propertyName, PropertyAttributes.None, cc, propertyType, null);
#endif
                        propertyInfo = new PropertyInstance(pi);
                        ((BytecodeBehaviorState)State).PropertyImplemented(propertyInfo);
                    }
                }
                else if (eventName != null)
                {
                    eventInfo = ((BytecodeBehaviorState)State).GetAlreadyImplementedEvent(eventName);
                    if (eventInfo == null)
                    {
                        CallingConventions cc = access.HasFlag(MethodAttributes.Static) ? CallingConventions.Standard : CallingConventions.HasThis;
                        EventBuilder       eb = tb.DefineEvent(eventName, EventAttributes.None, propertyType);
                        ((BytecodeBehaviorState)State).EventImplemented(eventName, eb);
                        eventInfo = eb;
                    }
                }
                MethodBuilder mb = tb.DefineMethod(method.Name, access, access.HasFlag(MethodAttributes.Static) ? CallingConventions.Standard : CallingConventions.HasThis, method.ReturnType.Type, parameters);
                //MethodInfo parentMI = State.CurrentType.GetMethod(method.Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
                //if (parentMI != null)
                //{
                //    tb.DefineMethodOverride(mb, parentMI);
                //}
                method = new MethodInstance(newType, mb, method.Parameters);
                ((BytecodeBehaviorState)State).MethodImplemented(method);

                if (propertyInfo != null && propertyInfo.Configurable)
                {
                    if (method.Name.StartsWith("get_"))
                    {
                        propertyInfo.Getter = method;
                    }
                    else if (method.Name.StartsWith("set_"))
                    {
                        propertyInfo.Setter = method;
                    }
                    else
                    {
                        throw new ArgumentException();
                    }
                }
                if (eventInfo != null && eventInfo is EventBuilder)
                {
                    EventBuilder eb = (EventBuilder)eventInfo;
                    if (method.Name.StartsWith("add_"))
                    {
                        eb.SetAddOnMethod(mb);
                    }
                    else if (method.Name.StartsWith("remove_"))
                    {
                        eb.SetRemoveOnMethod(mb);
                    }
                    else
                    {
                        throw new ArgumentException();
                    }
                }
                sb.Append("\r\n" + method.ToString());
                return(new MethodWriter(mb, method, sb));
            }
        }
예제 #10
0
 public static MethodInstance FindByTemplate(bool tryOnly, Type returnType, String methodName, params Type[] parameters)
 {
     return(FindByTemplate(tryOnly, NewType.GetType(returnType), methodName, TypeUtil.GetClassesToTypes(parameters)));
 }
예제 #11
0
 public MethodInstance(Type owner, MethodAttributes access, Type returnType, String name, params Type[] parameters)
     : this(owner != null ? NewType.GetType(owner) : null, access, NewType.GetType(returnType), name, TypeUtil.GetClassesToTypes(parameters))
 {
     // Intended blank
 }
예제 #12
0
 public MethodInstance(MethodBase method)
     : this(NewType.GetType(method.DeclaringType), method)
 {
     // Intended blank
 }
예제 #13
0
 public MethodInstance(NewType owner, Type declaringTypeOfMethod, Type returnType, String methodName, params Type[] parameters)
     : this(owner != null ? owner : NewType.GetType(declaringTypeOfMethod), ReflectUtil.GetDeclaredMethod(false, declaringTypeOfMethod, returnType, methodName,
                                                                                                          parameters))
 {
     // Intended blank
 }
예제 #14
0
 public static PropertyInstance FindByTemplate(String propertyName, Type propertyType, bool tryOnly)
 {
     return(FindByTemplate(propertyName, propertyType != null ? NewType.GetType(propertyType) : null, tryOnly));
 }