public static GetType ( string typeName, bool throwOnError ) : |
||
typeName | string | |
throwOnError | bool | |
리턴 |
public EnumDescriptor(XmlElement elem) { string cls = elem.GetAttribute("type"); enumType = Registry.GetType(cls, true); this.name = enumType.FullName; values = new Hashtable(); // This gets the list of enum names and gets the value of each of them. // This is not done the other way (get the values, and then the names from them) // because it won't work if two different enum members have the same value ArrayList list = new ArrayList(); Hashtable evalues = new Hashtable(); foreach (string name in Enum.GetNames(enumType)) { object value = Enum.Parse(enumType, name); list.Add(value); evalues[name] = value; } foreach (XmlElement valueElem in elem.SelectNodes("value")) { string name = valueElem.GetAttribute("name"); if (!evalues.Contains(name)) { throw new ArgumentException("<enum> node for " + enumType.FullName + " contains extra element " + name); } Enum value = (Enum)evalues[name]; values[value] = new EnumValue(value, valueElem.GetAttribute("label"), valueElem.GetAttribute("description")); evalues.Remove(name); } // Remove from the array the values not declared in the xml file foreach (object val in evalues.Values) { list.Remove(val); } values_array = (Enum[])list.ToArray(typeof(Enum)); }
PropertyDefinition FindProperty(TypeDefinition cls, string name) { foreach (PropertyDefinition propInfo in cls.Properties) { if (propInfo.Name == name) { return(propInfo); } } if (cls.BaseType == null) { return(null); } string baseType = cls.BaseType.FullName; Type t = Registry.GetType(baseType, false); if (t != null) { PropertyInfo prop = t.GetProperty(name); if (prop != null) { TypeReference tref = new TypeReference(prop.PropertyType.Namespace, prop.PropertyType.Name, cls.Module, cls.Module, prop.PropertyType.IsValueType); PropertyDefinition pdef = new PropertyDefinition(name, Mono.Cecil.PropertyAttributes.None, tref); CreateGetMethod(pdef); CreateSetMethod(pdef); return(pdef); } } TypeDefinition bcls = cecilLib.FindTypeDefinition(baseType); if (bcls != null) { return(FindProperty(bcls, name)); } else { return(null); } }
EventDefinition FindEvent(TypeDefinition cls, string name) { foreach (EventDefinition eventInfo in cls.Events) { if (eventInfo.Name == name) { return(eventInfo); } } if (cls.BaseType == null) { return(null); } string baseType = cls.BaseType.FullName; Type t = Registry.GetType(baseType, false); if (t != null) { EventInfo ev = t.GetEvent(name); if (ev != null) { TypeReference tref = new TypeReference(ev.EventHandlerType.Namespace, ev.EventHandlerType.Name, cls.Module, cls.Module, ev.EventHandlerType.IsValueType); return(new EventDefinition(name, Mono.Cecil.EventAttributes.None, tref)); } } TypeDefinition bcls = cecilLib.FindTypeDefinition(baseType); if (bcls != null) { return(FindEvent(bcls, name)); } else { return(null); } }
public TypedClassDescriptor(Assembly assembly, XmlElement elem) { bool inheritedWrapper = false; wrapped = Registry.GetType(elem.GetAttribute("type"), true); if (wrapped != null) { ConstructorInfo[] cInfos = wrapped.GetConstructors(); foreach (ConstructorInfo ci in cInfos) { if (ci.GetParameters().Length == 0) { cinfoNoParams = ci; break; } } } if (elem.HasAttribute("wrapper")) { wrapper = Registry.GetType(elem.GetAttribute("wrapper"), true); } else { inheritedWrapper = true; string baseClass = elem.GetAttribute("base-type"); if (baseClass.Length > 0) { // If a base type is specified, use the wrapper of that base type TypedClassDescriptor parent = Registry.LookupClassByName(baseClass) as TypedClassDescriptor; if (parent != null) { wrapper = parent.WrapperType; } } else { for (Type type = wrapped.BaseType; type != null; type = type.BaseType) { TypedClassDescriptor parent = Registry.LookupClassByName(type.FullName) as TypedClassDescriptor; if (parent != null) { wrapper = parent.WrapperType; break; } } } if (wrapper == null) { throw new ArgumentException(string.Format("No wrapper type for class {0}", wrapped.FullName)); } } gtype = (GLib.GType)wrapped; cname = gtype.ToString(); string iconname = elem.GetAttribute("icon"); if (iconname.Length > 0) { try { // Using the pixbuf resource constructor generates a gdk warning. Gdk.PixbufLoader loader = new Gdk.PixbufLoader(assembly, iconname); icon = loader.Pixbuf; } catch { Console.WriteLine("Could not load icon: " + iconname); icon = GetDefaultIcon(); } } else { icon = GetDefaultIcon(); } BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly; // If the wrapper is inherited from a base class, ignore the CreateInstance method // since it is going to create an instance of the base class. if (!inheritedWrapper) { ctorMethodInfoWithClass = wrapper.GetMethod("CreateInstance", flags, null, new Type[] { typeof(ClassDescriptor) }, null); if (ctorMethodInfoWithClass == null) { ctorMethodInfo = wrapper.GetMethod("CreateInstance", flags, null, Type.EmptyTypes, null); } } // Look for a constructor even if a CreateInstance method was // found, since it may return null. cinfo = wrapped.GetConstructor(Type.EmptyTypes); if (cinfo == null) { useGTypeCtor = true; cinfo = wrapped.GetConstructor(new Type[] { typeof(IntPtr) }); } Load(elem); }
public TypedPropertyDescriptor(XmlElement elem, ItemGroup group, TypedClassDescriptor klass) : base(elem, group, klass) { this.klass = klass; string propertyName = elem.GetAttribute("name"); int dot = propertyName.IndexOf('.'); if (dot != -1) { // Sub-property (eg, "Alignment.Value") memberInfo = FindProperty(klass.WrapperType, klass.WrappedType, propertyName.Substring(0, dot)); isWrapperProperty = memberInfo.DeclaringType.IsSubclassOf(typeof(ObjectWrapper)); gladeProperty = new TypedPropertyDescriptor(isWrapperProperty ? klass.WrapperType : klass.WrappedType, memberInfo.Name); propertyInfo = FindProperty(memberInfo.PropertyType, propertyName.Substring(dot + 1)); } else { // Basic simple property propertyInfo = FindProperty(klass.WrapperType, klass.WrappedType, propertyName); isWrapperProperty = propertyInfo.DeclaringType.IsSubclassOf(typeof(ObjectWrapper)); } // Wrapper properties that override widgets properties (using the same name) // must be considered runtime properties (will be available at run-time). if (!isWrapperProperty || klass.WrappedType.GetProperty(propertyName) != null) { isRuntimeProperty = true; } if (!IsInternal && propertyInfo.PropertyType.IsEnum && Registry.LookupEnum(propertyInfo.PropertyType.FullName) == null) { throw new ArgumentException("No EnumDescriptor for " + propertyInfo.PropertyType.FullName + "(" + klass.WrappedType.FullName + "." + propertyName + ")"); } pspec = FindPSpec(propertyInfo); if (isWrapperProperty && pspec == null) { PropertyInfo pinfo = klass.WrappedType.GetProperty(propertyInfo.Name, flags); if (pinfo != null) { pspec = FindPSpec(pinfo); } } if (pspec != null) { // This information will be overridden by what's specified in the xml file description = pspec.Blurb; minimum = pspec.Minimum; maximum = pspec.Maximum; label = propertyName; if (!elem.HasAttribute("ignore-default")) { hasDefault = Type.GetTypeCode(PropertyType) != TypeCode.Object || PropertyType.IsEnum; } } else { label = propertyInfo.Name; gladeOverride = true; } string typeName = elem.GetAttribute("editor"); if (typeName.Length > 0) { editorType = Registry.GetType(typeName, false); } // Look for a default value attribute object[] ats = propertyInfo.GetCustomAttributes(typeof(DefaultValueAttribute), true); if (ats.Length > 0) { DefaultValueAttribute at = (DefaultValueAttribute)ats [0]; defaultValue = at.Value; } // Load default data Load(elem); }
protected void Load(XmlElement elem) { if (elem.HasAttribute("label")) { label = elem.GetAttribute("label"); } if (label == null) { label = elem.GetAttribute("name"); } if (elem.HasAttribute("description")) { description = elem.GetAttribute("description"); } if (elem.HasAttribute("min")) { minimum = StringToValue(elem.GetAttribute("min")); } if (elem.HasAttribute("max")) { maximum = StringToValue(elem.GetAttribute("max")); } if (elem.HasAttribute("glade-override")) { gladeOverride = true; } if (elem.HasAttribute("glade-name")) { gladeName = elem.GetAttribute("glade-name"); } if (elem.HasAttribute("init-with-name")) { initWithName = true; } if (elem.HasAttribute("translatable")) { translatable = true; } if (elem.HasAttribute("default")) { defaultValue = StringToValue(elem.GetAttribute("default")); hasDefault = true; } string convTypeName = elem.GetAttribute("type-converter"); if (convTypeName.Length > 0) { Type type = Registry.GetType(convTypeName, true); typeConverter = (TypeConverter)Activator.CreateInstance(type); } }
public CecilSignalDescriptor(CecilWidgetLibrary lib, XmlElement elem, Stetic.ItemGroup group, Stetic.ClassDescriptor klass, EventDefinition sinfo) : base(elem, group, klass) { if (sinfo != null) { string handler = sinfo.EventType.FullName; handlerTypeName = handler.Replace('/', '+'); Type t = Registry.GetType(handler, false); if (t != null) { MethodInfo mi = t.GetMethod("Invoke"); handlerReturnTypeName = mi.ReturnType.FullName; ParameterInfo[] pars = mi.GetParameters(); handlerParameters = new ParameterDescriptor [pars.Length]; for (int n = 0; n < pars.Length; n++) { handlerParameters [n] = new ParameterDescriptor(pars[n].Name, pars[n].ParameterType.FullName); } } else { // If the type is generic, the type arguments must be ignored when looking for the type string tn = handler; int i = handler.IndexOf('<'); if (i != -1) { tn = handler.Substring(0, i); // Convert the type name to a type reference handler = handler.Replace('<', '['); handler = handler.Replace('>', ']'); } TypeDefinition td = lib.FindTypeDefinition(tn); if (td != null) { MethodDefinition mi = null; foreach (MethodDefinition md in td.Methods) { if (md.Name == "Invoke") { mi = md; break; } } if (mi != null) { handlerReturnTypeName = CecilWidgetLibrary.GetInstanceType(td, sinfo.EventType, mi.ReturnType.ReturnType); handlerParameters = new ParameterDescriptor [mi.Parameters.Count]; for (int n = 0; n < handlerParameters.Length; n++) { ParameterDefinition par = mi.Parameters [n]; handlerParameters [n] = new ParameterDescriptor(par.Name, CecilWidgetLibrary.GetInstanceType(td, sinfo.EventType, par.ParameterType)); } } } else { handlerParameters = new ParameterDescriptor [0]; } } SaveCecilXml(elem); } else { handlerTypeName = elem.GetAttribute("handlerTypeName"); handlerReturnTypeName = elem.GetAttribute("handlerReturnTypeName"); ArrayList list = new ArrayList(); foreach (XmlNode npar in elem.ChildNodes) { XmlElement epar = npar as XmlElement; if (epar == null) { continue; } list.Add(new ParameterDescriptor(epar.GetAttribute("name"), epar.GetAttribute("type"))); } handlerParameters = (ParameterDescriptor[])list.ToArray(typeof(ParameterDescriptor)); } Load(elem); }