Exemplo n.º 1
0
 private static System.Type FindIEnumerable(System.Type seqType)
 {
     if (seqType == null || seqType == typeof(string))
         return null;
     if (seqType.IsArray)
         return typeof(IEnumerable<>).MakeGenericType(seqType.GetElementType());
     if (seqType.IsGenericType) {
         foreach (System.Type arg in seqType.GetGenericArguments())
         {
             System.Type ienum = typeof(IEnumerable<>).MakeGenericType(arg);
             if (ienum.IsAssignableFrom(seqType)) {
                 return ienum;
             }
         }
     }
     System.Type[] ifaces = seqType.GetInterfaces();
     if (ifaces != null && ifaces.Length > 0) {
         foreach (System.Type iface in ifaces)
         {
             System.Type ienum = FindIEnumerable(iface);
             if (ienum != null) return ienum;
         }
     }
     if (seqType.BaseType != null && seqType.BaseType != typeof(object)) {
         return FindIEnumerable(seqType.BaseType);
     }
     return null;
 }
Exemplo n.º 2
0
 public TypeProjectItem(string alias, System.Type type)
     : base(alias)
 {
     if ((type.BaseType != null) || (type.GetInterfaces().Length != 0))
     {
         base.SetFlags(ProjectItemFlags.NonExpandable, false);
     }
     this._type = type;
 }
 private static List<PropertyInfo> GetInterfaceProperties(System.Type interfaceToReflect, List<PropertyInfo> properties)
 {
     var interfaces = interfaceToReflect.GetInterfaces();
     foreach (var inter in interfaces)
     {
         properties.AddRange(GetInterfaceProperties(inter, properties));
     }
     properties.AddRange(interfaceToReflect.GetProperties(BindingFlags.Public | BindingFlags.Instance).ToList());
     return properties.Distinct().OrderBy(i => i.Name).ToList();
 }
Exemplo n.º 4
0
        public static System.Type TryGetCollectionItemType(System.Type collectionType)
        {
            if (collectionType == null)
                return null;

            if (collectionType.IsInterface && IsCollectionType(collectionType))
                return collectionType.GetGenericArguments().Single();

            System.Type enumerableType = collectionType.GetInterfaces().FirstOrDefault(IsCollectionType);
            if (enumerableType == null)
                return null;

            return enumerableType.GetGenericArguments().Single();
        }
        public static bool IsAssignableToGenericType(System.Type givenType, System.Type genericType)
        {
            var interfaceTypes = givenType.GetInterfaces();

            foreach (var it in interfaceTypes)
                if (it.IsGenericType)
                    if (it.GetGenericTypeDefinition() == genericType) return true;

            System.Type baseType = givenType.BaseType;
            if (baseType == null) return false;

            return baseType.IsGenericType &&
                baseType.GetGenericTypeDefinition() == genericType ||
                IsAssignableToGenericType(baseType, genericType);
        }
Exemplo n.º 6
0
        private static MethodInfo GetMethodFromInterface(System.Type type, string methodName, System.Type[] parameterTypes)
        {
            const BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly;
            if (type == null)
                return null;

            MethodInfo method = type.GetMethod(methodName, flags, null, parameterTypes, null);
            if (method == null)
            {
                System.Type[] interfaces = type.GetInterfaces();
                foreach (var @interface in interfaces)
                {
                    method = GetMethodFromInterface(@interface, methodName, parameterTypes);
                    if (method != null)
                        return method;
                }
            }
            return method;
        }
 private static MethodInfo[] GetIntroducedMethods(System.Type type, ref string[] methodAttributes)
 {
     BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;
     MethodInfo[] methods = type.GetMethods(bindingAttr);
     if (!type.IsInterface)
     {
         methodAttributes = new string[methods.Length];
         FindMethodAttributes(type, methods, ref methodAttributes, bindingAttr);
         ArrayList list = new ArrayList();
         foreach (System.Type type2 in type.GetInterfaces())
         {
             foreach (MethodInfo info in type.GetInterfaceMap(type2).TargetMethods)
             {
                 if (!info.IsPublic && (type.GetMethod(info.Name, bindingAttr | BindingFlags.NonPublic) != null))
                 {
                     list.Add(info);
                 }
             }
         }
         MethodInfo[] infoArray2 = null;
         if (list.Count > 0)
         {
             infoArray2 = new MethodInfo[methods.Length + list.Count];
             for (int i = 0; i < methods.Length; i++)
             {
                 infoArray2[i] = methods[i];
             }
             for (int j = 0; j < list.Count; j++)
             {
                 infoArray2[methods.Length + j] = (MethodInfo) list[j];
             }
             return infoArray2;
         }
     }
     return methods;
 }
 private static System.Type[] GetIntroducedInterfaces(System.Type type)
 {
     ArrayList list = new ArrayList();
     foreach (System.Type type2 in type.GetInterfaces())
     {
         if (!type2.FullName.StartsWith("System."))
         {
             list.Add(type2);
         }
     }
     System.Type[] typeArray2 = new System.Type[list.Count];
     for (int i = 0; i < list.Count; i++)
     {
         typeArray2[i] = (System.Type) list[i];
     }
     return typeArray2;
 }
Exemplo n.º 9
0
        /// <summary>
        /// Finds the OPC specifications supported by the .NET server.
        /// </summary>
        private Specifications GetSpecifications(System.Type systemType)
        {
            if (systemType == null)
            {
                return Specifications.None;
            }

            Specifications specifications = Specifications.None;

            foreach (System.Type interfaces in systemType.GetInterfaces())
            {
                if (interfaces.GUID == typeof(OpcRcw.Da.IOPCItemProperties).GUID)
                {
                    specifications |= Specifications.DA2;
                }

                if (interfaces.GUID == typeof(OpcRcw.Da.IOPCBrowse).GUID)
                {
                    specifications |= Specifications.DA3;
                }

                if (interfaces.GUID == typeof(OpcRcw.Ae.IOPCEventServer).GUID)
                {
                    specifications |= Specifications.AE;
                }

                if (interfaces.GUID == typeof(OpcRcw.Hda.IOPCHDA_Server).GUID)
                {
                    specifications |= Specifications.HDA;
                }
            }

            return specifications;
        }
 private static IEnumerable<System.Type> GetAllInterfaces(System.Type currentType)
 {
     var interfaces = currentType.GetInterfaces();
     foreach (var current in interfaces)
     {
         yield return current;
         foreach (var @interface in GetAllInterfaces(current))
         {
             yield return @interface;
         }
     }
 }
 private static bool IsTypeActiveXControl(System.Type type)
 {
     if (IsTypeComObject(type))
     {
         string name = @"CLSID\{" + type.GUID.ToString() + @"}\Control";
         RegistryKey key = Registry.ClassesRoot.OpenSubKey(name);
         if (key == null)
         {
             return false;
         }
         key.Close();
         System.Type[] interfaces = type.GetInterfaces();
         if ((interfaces != null) && (interfaces.Length >= 1))
         {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 12
0
		public static bool IsCollection(System.Type clazz)
		{
            bool isNonGenericCollection = Collection.superClass.IsAssignableFrom(clazz);
            if (isNonGenericCollection)
            {
                return true;
            }
            Type[] types = clazz.GetInterfaces();
            for (int i = 0; i < types.Length; i++)
            {
                //Console.WriteLine(types[i].ToString()+ " / "  + types[i].FullName);
                int ind = types[i].FullName.IndexOf("System.Collections.Generic.ICollection");
                if ( ind != -1)
                {
                    return true;
                }
   

            }
            //return Collection.superClass.IsAssignableFrom(clazz) || CollectionGeneric.superClass.IsAssignableFrom(clazz);
            return false;
		}
 public AxWrapperGen(System.Type axType)
 {
     this.axctl = axType.Name;
     this.axctl = this.axctl.TrimStart(new char[] { '_', '1' });
     this.axctl = "Ax" + this.axctl;
     this.clsidAx = axType.GUID;
     CustomAttributeData[] attributeData = GetAttributeData(axType, typeof(ComSourceInterfacesAttribute));
     if ((attributeData.Length == 0) && axType.BaseType.GUID.Equals(axType.GUID))
     {
         attributeData = GetAttributeData(axType.BaseType, typeof(ComSourceInterfacesAttribute));
     }
     if (attributeData.Length > 0)
     {
         CustomAttributeData data = attributeData[0];
         CustomAttributeTypedArgument argument = data.ConstructorArguments[0];
         string str = argument.Value.ToString();
         int length = str.IndexOfAny(new char[1]);
         string name = str.Substring(0, length);
         this.axctlEventsType = axType.Module.Assembly.GetType(name);
         if (this.axctlEventsType == null)
         {
             this.axctlEventsType = System.Type.GetType(name, false);
         }
         if (this.axctlEventsType != null)
         {
             this.axctlEvents = this.axctlEventsType.FullName;
         }
     }
     System.Type[] interfaces = axType.GetInterfaces();
     this.axctlType = interfaces[0];
     foreach (System.Type type in interfaces)
     {
         if (GetAttributeData(type, typeof(CoClassAttribute)).Length > 0)
         {
             System.Type[] typeArray2 = type.GetInterfaces();
             if ((typeArray2 != null) && (typeArray2.Length > 0))
             {
                 this.axctl = "Ax" + type.Name;
                 this.axctlType = typeArray2[0];
                 break;
             }
         }
     }
     this.axctlIface = this.axctlType.Name;
     foreach (System.Type type2 in interfaces)
     {
         if (type2 == typeof(IEnumerable))
         {
             this.enumerableInterface = true;
             break;
         }
     }
     try
     {
         attributeData = GetAttributeData(this.axctlType, typeof(InterfaceTypeAttribute));
         if (attributeData.Length > 0)
         {
             CustomAttributeData data2 = attributeData[0];
             CustomAttributeTypedArgument argument2 = data2.ConstructorArguments[0];
             this.dispInterface = argument2.Value.Equals(ComInterfaceType.InterfaceIsIDispatch);
         }
     }
     catch (MissingMethodException)
     {
     }
 }
		/// <summary>
		/// Helper method to find the Property <c>get</c>.
		/// </summary>
		/// <param name="type">The <see cref="System.Type"/> to find the Property in.</param>
		/// <param name="propertyName">The name of the mapped Property to get.</param>
		/// <returns>
		/// The <see cref="BasicGetter"/> for the Property <c>get</c> or <c>null</c>
		/// if the Property could not be found.
		/// </returns>
		internal static BasicGetter GetGetterOrNull( System.Type type, string propertyName )
		{
			
			if( type==typeof( object ) || type==null )
			{
				// the full inheritance chain has been walked and we could
				// not find the Property get
				return null;
			}

			PropertyInfo property = type.GetProperty( propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly );

			if( property != null )
			{
				return new BasicGetter( type, property, propertyName );
			}
			else
			{
				// recursively call this method for the base Type
				BasicGetter getter = GetGetterOrNull( type.BaseType, propertyName );
				
				// didn't find anything in the base class - check to see if there is 
				// an explicit interface implementation.
				if( getter == null )
				{
					System.Type[ ] interfaces = type.GetInterfaces();
					for( int i = 0; getter == null && i < interfaces.Length; i++ )
					{
						getter = GetGetterOrNull( interfaces[ i ], propertyName );
					}
				}
				return getter;
			}

		}
		/// <summary>
		/// Helper method to find the Property <c>set</c>.
		/// </summary>
		/// <param name="type">The <see cref="System.Type"/> to find the Property in.</param>
		/// <param name="propertyName">The name of the mapped Property to set.</param>
		/// <returns>
		/// The <see cref="BasicSetter"/> for the Property <c>set</c> or <see langword="null" />
		/// if the Property could not be found.
		/// </returns>
		internal static BasicSetter GetSetterOrNull(System.Type type, string propertyName)
		{
			if (type == typeof(object) || type == null)
			{
				// the full inheritance chain has been walked and we could
				// not find the Property get
				return null;
			}

			BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;

			if (type.IsValueType)
			{
				// the BindingFlags.IgnoreCase is important here because if type is a struct, the GetProperty method does
				// not ignore case by default. If type is a class, it _does_ ignore case... we're better off explicitly
				// stating that casing should be ignored so we get the same behavior for both structs and classes
				bindingFlags = bindingFlags | BindingFlags.IgnoreCase;
			}

			PropertyInfo property = type.GetProperty(propertyName, bindingFlags);

			if (property != null && property.CanWrite)
			{
				return new BasicSetter(type, property, propertyName);
			}

			// recursively call this method for the base Type
			BasicSetter setter = GetSetterOrNull(type.BaseType, propertyName);

			// didn't find anything in the base class - check to see if there is 
			// an explicit interface implementation.
			if (setter == null)
			{
				System.Type[] interfaces = type.GetInterfaces();
				for (int i = 0; setter == null && i < interfaces.Length; i++)
				{
					setter = GetSetterOrNull(interfaces[i], propertyName);
				}
			}
			return setter;
		}
Exemplo n.º 16
0
        public override bool CanConvertFrom(System.Type fromType, System.Type toType, bool toNotNullable, NarrowingLevel level)
        {
            if (fromType == typeof(double) && toType == typeof(string))
                return true;
            else if (fromType == typeof(string) && toType == typeof(double))
                return !toNotNullable;

            else if(fromType.GetInterfaces().Any(x => x == typeof(IConvertible)))
                return true;

            return base.CanConvertFrom(fromType, toType, toNotNullable, level);
        }
Exemplo n.º 17
0
 private static PropertyCache GetCachedProperties(System.Type type)
 {
     RuntimeHelpers.RunClassConstructor(type.TypeHandle);
     PropertyCache propertyCache;
     if (!ModelProperty.cachedProperties.TryGetValue(type, out propertyCache))
     {
         propertyCache = new PropertyCache();
         ModelProperty.cachedProperties.Add(type, propertyCache);
         HashSet<ModelProperty> allProperties = new HashSet<ModelProperty>();
         Dictionary<string, ModelProperty> propertyList;
         if (ModelProperty.properties.TryGetValue(type, out propertyList))
         {
             propertyCache.DeclaredProperties.AddRange(propertyList.Values);
             allProperties.UnionWith(propertyList.Values);
             foreach (var prop in propertyList.Values)
             {
                 if (!propertyCache.Properties.Any(p => p.Name == prop.Name))
                 {
                     propertyCache.Properties.Add(prop);
                 }
             }
         }
         foreach (var super in type.GetInterfaces())
         {
             var superProperties = ModelProperty.GetCachedProperties(super).AllProperties;
             allProperties.UnionWith(superProperties);
             foreach (var prop in superProperties)
             {
                 if (!propertyCache.Properties.Any(p => p.Name == prop.Name))
                 {
                     propertyCache.Properties.Add(prop);
                 }
             }
         }
         propertyCache.AllProperties.AddRange(allProperties);
     }
     return propertyCache;
 }
Exemplo n.º 18
0
		static public object Reconstitute(System.Type type, string data)
		{
			object returnData = null;

			if (type == typeof(String)) 
				returnData = (string)data;
			else if (type == typeof(Boolean)) 
				returnData = Convert.ToBoolean(data);

			else if (type == typeof(SByte)) 
				returnData = Convert.ToSByte(data);
			else if (type == typeof(Int16)) 
				returnData = Convert.ToInt16(data);
			else if (type == typeof(Int32)) 
				returnData = Convert.ToInt32(data);
			else if (type == typeof(Int64)) 
				returnData = Convert.ToInt64(data);
			else if (type == typeof(Byte))
				returnData = Convert.ToByte(data);

			else if (type == typeof(UInt16)) 
				returnData = Convert.ToUInt16(data);
			else if (type == typeof(UInt32)) 
				returnData = Convert.ToUInt32(data);
			else if (type == typeof(UInt64)) 
				returnData = Convert.ToUInt64(data);

			else if (type == typeof(Decimal)) 
				returnData = Convert.ToDecimal(data);
			else if (type == typeof(Guid)) 
				returnData = new Guid(data);
			else if (type == typeof(Single)) 
				returnData = Convert.ToSingle(data);
			else if (type == typeof(Double)) 
				returnData = Convert.ToDouble(data);

			else if (type == typeof(DateTime)) 
				returnData = DateTime.Parse(data);
			else if (type == typeof(TimeSpan)) 
				returnData = TimeSpan.Parse(data);

			else 
			{
				LoadCustomSerializers();
				ITypeSerializer cts =_serializers[type] as ITypeSerializer;
				if (cts != null) 
				{
					returnData = cts.Reconstitute(data);
				}
				else 
				{
					bool found = false;
					foreach (ITypeSerializer ts in _serializers.Values) 
					{
						if (ts.DataType.IsClass)
						{
							if (type.IsSubclassOf(ts.DataType)) 
							{
								returnData = ts.Reconstitute(data);
								found = true;
							}
						}
						else if (ts.DataType.IsInterface) 
						{
							Type[] ifaces = type.GetInterfaces();
							foreach (Type iface in ifaces) 
							{
								if (iface == ts.DataType) 
								{
									returnData = ts.Reconstitute(data);
									found = true;
									break;
								}
							}
						}
						if (found) break;
					}

					if (!found) 
					{
						throw new Exception("Unserializable type: " + data.GetType().FullName);
					}
				}
			}

			return returnData;
		}
Exemplo n.º 19
0
	/// <summary>
	/// Recursively finds a match for each method, starting with the class, and then
	/// searching the superclass and interfaces.
	/// </summary>
	/// <param name="clazz">Class to check</param>
	/// <param name="methodInfos">array of methods we are searching to match</param>
	/// <param name="upcastCount">current number of methods we have matched</param>
	/// <returns>count of matched methods</returns>
	private static int getAccessibleMethods(System.Type clazz, MethodInfo[] methodInfos, int upcastCount) {
	    int l = methodInfos.Length;

	    /*
	    *  if this class is public, then check each of the currently
	    *  'non-upcasted' methods to see if we have a match
	    */

	    //UPGRADE_TODO: Method java.lang.reflect.Modifier.isPublic was not converted. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1095"'
	    //UPGRADE_ISSUE: Method 'java.lang.Class.getModifiers' was not converted. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1000_javalangClassgetModifiers"'
	    if (clazz.IsPublic) {
		for (int i = 0; i < l && upcastCount < l; ++i) {
		    try {
			MethodInfo methodInfo = methodInfos[i];

			if (!methodInfo.upcast) {
			    methodInfo.tryUpcasting(clazz);
			    upcastCount++;
			}
		    } catch (System.MethodAccessException e) {
			/*
			*  Intentionally ignored - it means
			*  it wasn't found in the current class
			*/
		    }
		}

		/*
		*  Short circuit if all methods were upcast
		*/

		if (upcastCount == l) {
		    return upcastCount;
		}
	    }

	    /*
	    *   Examine superclass
	    */

	    System.Type superclazz = clazz.BaseType;

	    if (superclazz != null) {
		upcastCount = getAccessibleMethods(superclazz, methodInfos, upcastCount);

		/*
		*  Short circuit if all methods were upcast
		*/

		if (upcastCount == l) {
		    return upcastCount;
		}
	    }

	    /*
	    *  Examine interfaces. Note we do it even if superclazz == null.
	    *  This is redundant as currently java.lang.Object does not implement
	    *  any interfaces, however nothing guarantees it will not in future.
	    */

	    System.Type[] interfaces = clazz.GetInterfaces();

	    for (int i = interfaces.Length; i-- > 0; ) {
		upcastCount = getAccessibleMethods(interfaces[i], methodInfos, upcastCount);

		/*
		*  Short circuit if all methods were upcast
		*/

		if (upcastCount == l) {
		    return upcastCount;
		}
	    }

	    return upcastCount;
	}
Exemplo n.º 20
0
 public override bool ShouldMap(System.Type type)
 {
     return type.GetInterfaces().Any(x =>
          x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IEntityWithTypedId<>));
 }
Exemplo n.º 21
0
	/// <summary>  Looks up the method with specified name and signature in the first public
	/// superclass or implemented interface of the class.
	/// </summary>
	/// <param name="class">the class whose method is sought
	/// </param>
	/// <param name="name">the name of the method
	/// </param>
	/// <param name="paramTypes">the classes of method parameters
	/// </param>
	private static System.Reflection.MethodInfo getPublicMethod(System.Type clazz, System.String name, System.Type[] paramTypes) {
	    /*
	    *  if this class is public, then try to get it
	    */

	    if (clazz.IsPublic) {
		try {
		    return clazz.GetMethod(name, (System.Type[]) paramTypes);
		} catch (System.MethodAccessException e) {
		    /*
		    *  If the class does not have the method, then neither its
		    *  superclass nor any of its interfaces has it so quickly return
		    *  null.
		    */
		    return null;
		}
	    }

	    /*
	    *  try the superclass
	    */


	    System.Type superclazz = clazz.BaseType;

	    if (superclazz != null) {
		System.Reflection.MethodInfo superclazzMethod = getPublicMethod(superclazz, name, paramTypes);

		if (superclazzMethod != null) {
		    return superclazzMethod;
		}
	    }

	    /*
	    *  and interfaces
	    */

	    System.Type[] interfaces = clazz.GetInterfaces();

	    for (int i = 0; i < interfaces.Length; ++i) {
		System.Reflection.MethodInfo interfaceMethod = getPublicMethod(interfaces[i], name, paramTypes);

		if (interfaceMethod != null) {
		    return interfaceMethod;
		}
	    }

	    return null;
	}
Exemplo n.º 22
0
 public override bool accepts(System.Type classObject)
 {
     System.Type[] interfaces = classObject.GetInterfaces();
     for (int i = 0; i < interfaces.Length; i++)
     {
         if (typeof(IChemFile).Equals(interfaces[i]))
             return true;
     }
     return false;
 }
 private static bool IsTypeActiveXControl(System.Type type)
 {
     if ((type.IsClass && type.IsCOMObject) && (type.IsPublic && !type.GUID.Equals(Guid.Empty)))
     {
         try
         {
             CustomAttributeData[] attributeData = GetAttributeData(type, typeof(ComVisibleAttribute));
             if (attributeData.Length != 0)
             {
                 CustomAttributeTypedArgument argument = attributeData[0].ConstructorArguments[0];
                 if (argument.Value.Equals(false))
                 {
                     return false;
                 }
             }
         }
         catch
         {
             return false;
         }
         string name = @"CLSID\{" + type.GUID.ToString() + @"}\Control";
         RegistryKey key = Registry.ClassesRoot.OpenSubKey(name);
         if (key == null)
         {
             return false;
         }
         key.Close();
         System.Type[] interfaces = type.GetInterfaces();
         if ((interfaces != null) && (interfaces.Length >= 1))
         {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 24
0
 private static bool isOut(System.Type t)
 {
     foreach (var i in t.GetInterfaces())
     {
         if (!i.IsGenericType)
             continue;
         if (typeof(IOutStep<>).IsAssignableFrom(i.GetGenericTypeDefinition()))
             return true;
     }
     return false;
 }
Exemplo n.º 25
0
 public void ImplementsInterface(System.Type type, System.Type interf)
 {
     Assert.IsTrue(type.GetInterfaces().Contains(interf), string.Format("{0} does not implement {1}!", type.Name, interf.Name));
 }
Exemplo n.º 26
0
//-----------------------------------------------------------------------------
// Helper to import the specific type and return a TypeEntry. 
// This will recursively import all base types.
// Returns null if we can't import the type.
//-----------------------------------------------------------------------------         
    protected TypeEntry AddImportedType(System.Type tImport)
    {     
        #if true   
        // Don't import non-public classes
        // be wary of nesting
        //if (tImport.IsClass || tImport.IsValueType)
        {
            if (tImport.DeclaringType == null)
            {
                // Not nested
                if (!tImport.IsPublic)
                    return null;
            } else {
                // If Nested, check topmost containing class.
                System.Type t = tImport;
                while (t.DeclaringType != null)
                {
                    t = t.DeclaringType;
                }
                if (!t.IsPublic)
                    return null;            
            }
        }
        #endif
                    
        // If we've already imported this, then nothing to do.   
        {
            TypeEntry t = TryLookupCLRType(tImport);
            if (t != null)
                return t;
        }
        
        // Blue doesn't handle Generics (from V2.0 CLR), so just ignore them when imported.
        if (IsGenericType(tImport))
        {
            Console.WriteLine("Skipping Generic type:" + tImport.FullName);
            return null;
        }

        #if false
        // Debugging facility. Userbreakpoint when we import a specific class.
        if (tImport.Name == "IDictionaryEnumerator")
            System.Diagnostics.Debugger.Break();
        #endif
        
        // Stub immediately to avoid infinite cycles.        
        TypeEntry tBlue = TypeEntry.CreateImportStub(tImport);
        m_hashClrType.Add(tImport, tBlue);
                
        // If we're a nested type, make sure our containing type is imported.                        
        if (tImport.DeclaringType != null)
        {
            AddImportedType(tImport.DeclaringType);
        }
                      
        
        Scope scope = this.CreateImportedContext(tImport);
                             
        
        string stClass = tImport.Name;     
        
        // Already check for multiple imports       
        //if (LookupSymbol(scope, stClass, false) == null)
        {           
            
            // Add Base class
            TypeEntry tSuper = null;            
            if (tImport.BaseType != null)
            {                
                tSuper = AddImportedType(tImport.BaseType);
            }
                
            // Add interfaces, removing all interfaces that we can't access
            System.Type [] tCLRInterfaces = tImport.GetInterfaces();
            ArrayList al = new ArrayList(tCLRInterfaces.Length);            
            
            foreach(System.Type tInterface in tCLRInterfaces)
            {                
                TypeEntry t = AddImportedType(tInterface);
                if (t != null)
                    al.Add(t);
            }
            TypeEntry [] tBlueInterfaces = (TypeEntry[]) al.ToArray(typeof(TypeEntry));
            
            TypeEntry tParent = (tImport.DeclaringType == null) ? 
                null :
                this.ResolveCLRTypeToBlueType(tImport.DeclaringType);
                       
            // @todo - do we have to check if we've been imported again?
            
            // We create the symbol, but don't add the scope until we need to.
            // (else that would be a lot of scopes to add that we'd never use)
            // Note that this must be done on the same reference that we added at the top
            // because by now, the other types have links to that original reference.
            tBlue.FinishImportStub(tSuper, tBlueInterfaces, tParent);
            scope.AddSymbol(tBlue);
                
            
#if true   
            // If we have any nested classes, add them.
            // This will require us to create the class scope.            
            System.Type [] tNestedTypes = tImport.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic);
            if (tNestedTypes.Length > 0)
            {
                tBlue.EnsureScopeCreated();
                foreach(System.Type tNested in tNestedTypes)
                {                
                    AddImportedType(tNested);
                }
            }
#endif            
            return tBlue;
        } 
        /*
        else 
        {            
            ThrowError(SymbolError.IllegalAssembly(tImport.Assembly, 
                "Class '" + tImport.FullName + "' defined multiple times"));
            return null;
        }
        */
    
    } // end function
Exemplo n.º 27
0
		private IEnumerable<System.Type> GetAllInterfaces(System.Type currentType)
		{
			System.Type[] interfaces = currentType.GetInterfaces();

			foreach (System.Type current in interfaces)
			{
				yield return current;
				foreach (System.Type @interface in GetAllInterfaces(current))
				{
					yield return @interface;
				}
			}
		}
Exemplo n.º 28
0
        internal static CLRClass Load(System.Type type, Frame caller, bool makeConstant)
        {
            if (type == null)
                return null;

            CLRClass klass;
            if (!TryLoad(type, out klass))
            {
                System.Type baseType = type.BaseType;
                CLRClass baseClass = baseType == null 
                    ? null
                    : Load(baseType, caller, makeConstant && baseType.Assembly == type.Assembly);

                if (baseClass != null)
                {
                    klass = new CLRClass(type, baseClass, Type.Class);
                    klass.my_class = new CLRClass(type, baseClass.my_class, Type.IClass);

                    System.Type[] inherited = baseType.GetInterfaces();
                    foreach (System.Type iface in type.GetInterfaces())
                    {
                        if (0 > System.Array.IndexOf(inherited, iface))
                            Class.rb_include_module(caller, klass, Load(iface, caller, false));
                    }
                }
                else
                {
                    if (type.IsInterface)
                    {
                        klass = new CLRClass(type, null, Type.Module);
                        klass.my_class = new CLRClass(type, Init.rb_cModule, Type.IClass);
                    }
                    else
                    {
                        klass = new CLRClass(type, Init.rb_cObject, Type.Class);
                        klass.my_class = new CLRClass(type, Init.rb_cClass, Type.IClass);
                    }

                    foreach (System.Type iface in type.GetInterfaces())
                        Class.rb_include_module(caller, klass, Load(iface, caller, false));
                }

                Augmentations.Augment(type, klass, caller);
                klass = Define(type, klass);
            }

            if (makeConstant)
            {
                Class context = context = Ruby.Runtime.Init.rb_cObject;
                if (type.Namespace != null)
                {
                    foreach (string Namespace in type.Namespace.Split('.'))
                    {
                        Class innerContext;
                        string constant = FormatConstant(Namespace);

                        if (context.const_defined(constant, false) && (innerContext = context.const_get(constant, caller) as Class) != null)
                            context = innerContext;
                        else
                            context.define_const(constant, context = new CLRNamespace(Namespace));
                    }
                }

                if (type.IsNested)
                {
                    // nested types can be loaded by a getter in their owner
                    // ruby: Namespace::Type.InnerType
                }
                else if (type.IsGenericTypeDefinition)
                {
                    string name = type.Name.Substring(0, type.Name.LastIndexOf('`'));
                    string containerName =
                        type.Namespace == null
                        ? name
                        : type.Namespace + "." + name;

                    // if a non-generic type exists with the same name
                    // we can use that in the construction of a generic type
                    System.Type container = type.Assembly.GetType(containerName);

                    // otherwise we much build a GenericContainer
                    if (container == null)
                    {
                        string constant = FormatConstant(name);
                        if (!context.const_defined(constant))
                            context.define_const(constant, new GenericContainer(type.Assembly, containerName, null));
                    }
                }
                else
                {
                    context.define_const(FormatConstant(type.Name), klass);
                }
            }

            return klass;
        }
 private PropertyInfo[] GetProperties(System.Type type)
 {
     List<PropertyInfo> list = new List<PropertyInfo>();
     list.AddRange(type.GetProperties(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance));
     if (type.IsInterface)
     {
         foreach (System.Type type2 in type.GetInterfaces())
         {
             list.AddRange(type2.GetProperties(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Instance));
         }
     }
     return list.ToArray();
 }
Exemplo n.º 30
0
 /// <summary>
 /// 验证类型是否为合法插件类型
 /// </summary>
 /// <param name="t">目标类型</param>
 /// <returns></returns>
 private bool IsValidPlugin(System.Type t)
 {
     foreach (System.Type type in t.GetInterfaces())
     {
         if (type.FullName == "Client.Plugin.IPlugin")
         {
             return true;
         }
     }
     return false;
 }