Beispiel #1
0
 /// <summary>
 /// 初始化IL类型
 /// </summary>
 /// <param name="def">MONO返回的类型定义</param>
 /// <param name="domain">ILdomain</param>
 public ILType(TypeReference def, Runtime.Enviorment.AppDomain domain)
 {
     this.typeRef = def;
     RetriveDefinitino(def);
     appdomain = domain;
     jitFlags  = domain.DefaultJITFlags;
 }
Beispiel #2
0
 public CLRType(Type clrType, Runtime.Enviorment.AppDomain appdomain)
 {
     this.clrType   = clrType;
     this.appdomain = appdomain;
     isPrimitive    = clrType.IsPrimitive;
     isValueType    = clrType.IsValueType;
     isDelegate     = clrType.BaseType == typeof(MulticastDelegate);
 }
Beispiel #3
0
 public ILType(TypeReference def, Runtime.Enviorment.AppDomain domain)
 {
     this.typeRef = def;
     if (def is GenericInstanceType)
     {
         definition = (TypeDefinition)((GenericInstanceType)def).ElementType;
     }
     else
     {
         definition = (TypeDefinition)def;
     }
     appdomain = domain;
 }
 public ILRuntimeFieldInfo(FieldDefinition def, ILRuntimeType declaredType, int fieldIdx, IType fieldType)
 {
     definition    = def;
     this.name     = def.Name;
     dType         = declaredType;
     ilType        = dType.ILType;
     appdomain     = ilType.AppDomain;
     this.isStatic = false;
     this.fieldIdx = fieldIdx;
     if (isStatic)
     {
         attr |= System.Reflection.FieldAttributes.Static;
     }
     this.fieldType = fieldType;
 }
 public ILRuntimeFieldInfo(FieldDefinition def, ILRuntimeType declaredType, bool isStatic, int fieldIdx)
 {
     definition    = def;
     this.name     = def.Name;
     dType         = declaredType;
     ilType        = dType.ILType;
     appdomain     = ilType.AppDomain;
     this.isStatic = isStatic;
     this.fieldIdx = fieldIdx;
     if (isStatic)
     {
         attr |= System.Reflection.FieldAttributes.Static;
     }
     fieldType = isStatic ? ilType.StaticFieldTypes[fieldIdx] : ilType.FieldTypes[fieldIdx];
 }
Beispiel #6
0
 public CSHotFixFieldInfo(FieldDefinition def, CSHotFixType declaredType, int fieldIdx, IType fieldType)
 {
     definition    = def;
     this.name     = def.Name;
     dType         = declaredType;
     ilType        = dType.ILType;
     appdomain     = ilType.AppDomain;
     this.isStatic = false;
     this.fieldIdx = fieldIdx;
     if (isStatic)
     {
         attr |= System.Reflection.FieldAttributes.Static;
     }
     if (def.IsPublic)
     {
         attr |= System.Reflection.FieldAttributes.Public;
     }
     else
     {
         attr |= System.Reflection.FieldAttributes.Private;
     }
     this.fieldType = fieldType;
 }
Beispiel #7
0
 public CLRType(Type clrType, Runtime.Enviorment.AppDomain appdomain)
 {
     this.clrType   = clrType;
     this.appdomain = appdomain;
     isPrimitive    = clrType.IsPrimitive;
     isEnum         = clrType.IsEnum;
     isValueType    = clrType.IsValueType;
     isDelegate     = clrType.BaseType == typeof(MulticastDelegate);
     if (isPrimitive)
     {
         var t = TypeForCLR;
         if (t == typeof(int) || t == typeof(uint) || t == typeof(short) || t == typeof(ushort) || t == typeof(byte) || t == typeof(sbyte) || t == typeof(char) || t == typeof(bool))
         {
             defaultObject.ObjectType = ObjectTypes.Integer;
             defaultObject.Value      = 0;
             defaultObject.ValueLow   = 0;
         }
         else if (t == typeof(long) || t == typeof(ulong))
         {
             defaultObject.ObjectType = ObjectTypes.Long;
             defaultObject.Value      = 0;
             defaultObject.ValueLow   = 0;
         }
         else if (t == typeof(float))
         {
             defaultObject.ObjectType = ObjectTypes.Float;
             defaultObject.Value      = 0;
             defaultObject.ValueLow   = 0;
         }
         else if (t == typeof(double))
         {
             defaultObject.ObjectType = ObjectTypes.Double;
             defaultObject.Value      = 0;
             defaultObject.ValueLow   = 0;
         }
     }
 }
Beispiel #8
0
 public ILRuntimeType(ILType t)
 {
     type      = t;
     appdomain = t.AppDomain;
 }
Beispiel #9
0
 public CSHotFixType(ILType t)
 {
     type      = t;
     appdomain = t.AppDomain;
 }
        public static object CreateInstance(this CustomAttribute attribute, IType at, Runtime.Enviorment.AppDomain appdomain)
        {
            object       ins;
            List <IType> param = null;

            if (at is ILType)
            {
                var it = (ILType)at;
                if (!attribute.HasConstructorArguments)
                {
                    ins = it.Instantiate(true);
                }
                else
                {
                    ins = it.Instantiate(false);
                    if (param == null)
                    {
                        param = new List <IType>();
                    }
                    param.Clear();
                    object[] p = new object[attribute.ConstructorArguments.Count];
                    for (int j = 0; j < attribute.ConstructorArguments.Count; j++)
                    {
                        var ca = attribute.ConstructorArguments[j];
                        param.Add(appdomain.GetType(ca.Type, null, null));
                        p[j] = ca.Value;
                    }
                    var ctor = it.GetConstructor(param);
                    appdomain.Invoke(ctor, ins, p);
                }

                if (attribute.HasProperties)
                {
                    object[] p = new object[1];
                    foreach (var j in attribute.Properties)
                    {
                        p[0] = j.Argument.Value;
                        var setter = it.GetMethod("set_" + j.Name, 1);
                        appdomain.Invoke(setter, ins, p);
                    }
                }
            }
            else
            {
                param = new List <IType>();
                object[] p = null;
                if (attribute.HasConstructorArguments)
                {
                    p = new object[attribute.ConstructorArguments.Count];
                    for (int j = 0; j < attribute.ConstructorArguments.Count; j++)
                    {
                        var ca = attribute.ConstructorArguments[j];
                        param.Add(appdomain.GetType(ca.Type, null, null));
                        p[j] = ca.Value;
                    }
                }
                ins = ((CLRMethod)at.GetConstructor(param)).ConstructorInfo.Invoke(p);
                if (attribute.HasProperties)
                {
                    foreach (var j in attribute.Properties)
                    {
                        var prop = at.TypeForCLR.GetProperty(j.Name);
                        prop.SetValue(ins, j.Argument.Value, null);
                    }
                }
            }

            return(ins);
        }
Beispiel #11
0
 public DebugService(Runtime.Enviorment.AppDomain domain)
 {
     this.domain = domain;
 }
Beispiel #12
0
 public static object CheckCLRTypes(this Type pt, Runtime.Enviorment.AppDomain domain, object obj)
 {
     if (obj == null)
     {
         return(null);
     }
     if (pt.IsPrimitive && pt != typeof(int))
     {
         if (pt == typeof(bool) && !(obj is bool))
         {
             obj = (int)obj == 1;
         }
         else if (pt == typeof(byte) && !(obj is byte))
         {
             obj = (byte)(int)obj;
         }
         else if (pt == typeof(short) && !(obj is short))
         {
             obj = (short)(int)obj;
         }
         else if (pt == typeof(char) && !(obj is char))
         {
             obj = (char)(int)obj;
         }
         else if (pt == typeof(ushort) && !(obj is ushort))
         {
             obj = (ushort)(int)obj;
         }
         else if (pt == typeof(uint) && !(obj is uint))
         {
             obj = (uint)(int)obj;
         }
         else if (pt == typeof(sbyte) && !(obj is sbyte))
         {
             obj = (sbyte)(int)obj;
         }
         else if (pt == typeof(ulong) && !(obj is ulong))
         {
             obj = (ulong)(long)obj;
         }
     }
     else if (pt == typeof(Delegate) || pt.IsSubclassOf(typeof(Delegate)))
     {
         if (obj is Delegate)
         {
             return(obj);
         }
         if (pt == typeof(Delegate))
         {
             return(((IDelegateAdapter)obj).Delegate);
         }
         return(((IDelegateAdapter)obj).GetConvertor(pt));
     }
     else if (pt.IsByRef)
     {
         return(CheckCLRTypes(pt.GetElementType(), domain, obj));
     }
     else if (pt.IsEnum)
     {
         return(Enum.ToObject(pt, obj));
     }
     else if (obj is ILTypeInstance)
     {
         if (!(obj is ILEnumTypeInstance))
         {
             return(((ILTypeInstance)obj).CLRInstance);
         }
     }
     return(obj);
 }