public override MethodInfo GetAddMethod(bool nonPublic) { if ((this.addMethod == null) && (this.declaringType.ResolveType(DesignTimeType.GetTypeNameFromCodeTypeReference(this.codeDomEvent.Type, this.declaringType)) != null)) { CodeMemberMethod methodInfo = new CodeMemberMethod { Name = "add_" + this.name, ReturnType = new CodeTypeReference(typeof(void)) }; methodInfo.Parameters.Add(new CodeParameterDeclarationExpression(this.codeDomEvent.Type, "Handler")); methodInfo.Attributes = this.memberAttributes; this.addMethod = new DesignTimeMethodInfo(this.declaringType, methodInfo, true); } return(this.addMethod); }
internal DesignTimeFieldInfo(DesignTimeType declaringType, CodeMemberField codeDomField) { if (declaringType == null) { throw new ArgumentNullException("Declaring Type"); } if (codeDomField == null) { throw new ArgumentNullException("codeDomEvent"); } this.declaringType = declaringType; this.codeDomField = codeDomField; this.fieldAttributes = Helper.ConvertToFieldAttributes(codeDomField.Attributes); }
internal DesignTimeEventInfo(DesignTimeType declaringType, CodeMemberEvent codeDomEvent) { if (declaringType == null) { throw new ArgumentNullException("Declaring Type"); } if (codeDomEvent == null) { throw new ArgumentNullException("codeDomEvent"); } this.declaringType = declaringType; this.codeDomEvent = codeDomEvent; this.name = Helper.EnsureTypeName(codeDomEvent.Name); this.memberAttributes = codeDomEvent.Attributes; this.addMethod = null; this.removeMethod = null; }
public override MethodInfo GetRemoveMethod(bool nonPublic) { if (this.removeMethod == null) { Type handlerType = declaringType.ResolveType(DesignTimeType.GetTypeNameFromCodeTypeReference(this.codeDomEvent.Type, declaringType)); if (handlerType != null) { CodeMemberMethod codeRemoveMethod = new CodeMemberMethod(); codeRemoveMethod.Name = "remove_" + this.name; codeRemoveMethod.ReturnType = new CodeTypeReference(typeof(void)); codeRemoveMethod.Parameters.Add(new CodeParameterDeclarationExpression(handlerType, "Handler")); codeRemoveMethod.Attributes = this.memberAttributes; this.removeMethod = new DesignTimeMethodInfo(declaringType, codeRemoveMethod, true); } } return(this.removeMethod); }
private void AddTypes() { if (this.typeProvider != null && this.types != null) { this.types.Clear(); foreach (CodeNamespace codeNamespace in this.codeCompileUnit.Namespaces) { foreach (CodeTypeDeclaration codeTypeDeclaration in codeNamespace.Types) { // Look for partial type string typename = Helper.EnsureTypeName(codeTypeDeclaration.Name); if (codeNamespace.Name.Length > 0) { typename = (Helper.EnsureTypeName(codeNamespace.Name) + "." + typename); } DesignTimeType partialType = this.typeProvider.GetType(typename, false) as DesignTimeType; if (partialType == null) { partialType = new DesignTimeType(null, codeTypeDeclaration.Name, codeNamespace.Imports, codeNamespace.Name, this.typeProvider); this.types.Add(partialType); this.typeProvider.AddType(partialType); } partialType.AddCodeTypeDeclaration(codeTypeDeclaration); } } Queue nestedQueue = new Queue(this.types); while (nestedQueue.Count != 0) { Type type = nestedQueue.Dequeue() as Type; if (type.DeclaringType != null) { this.types.Add(type); } foreach (Type nestedType2 in type.GetNestedTypes(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) { nestedQueue.Enqueue(nestedType2); } } } }
private void AddTypes() { if ((this.typeProvider != null) && (this.types != null)) { this.types.Clear(); foreach (CodeNamespace namespace2 in this.codeCompileUnit.Namespaces) { foreach (CodeTypeDeclaration declaration in namespace2.Types) { string name = Helper.EnsureTypeName(declaration.Name); if (namespace2.Name.Length > 0) { name = Helper.EnsureTypeName(namespace2.Name) + "." + name; } DesignTimeType item = this.typeProvider.GetType(name, false) as DesignTimeType; if (item == null) { item = new DesignTimeType(null, declaration.Name, namespace2.Imports, namespace2.Name, this.typeProvider); this.types.Add(item); this.typeProvider.AddType(item); } item.AddCodeTypeDeclaration(declaration); } } Queue queue = new Queue(this.types); while (queue.Count != 0) { Type type2 = queue.Dequeue() as Type; if (type2.DeclaringType != null) { this.types.Add(type2); } foreach (Type type3 in type2.GetNestedTypes(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance)) { queue.Enqueue(type3); } } } }
private void AddTypes() { if (this.typeProvider != null && this.types != null) { this.types.Clear(); foreach (CodeNamespace codeNamespace in this.codeCompileUnit.Namespaces) { foreach (CodeTypeDeclaration codeTypeDeclaration in codeNamespace.Types) { // Look for partial type string typename = Helper.EnsureTypeName(codeTypeDeclaration.Name); if (codeNamespace.Name.Length > 0) typename = (Helper.EnsureTypeName(codeNamespace.Name) + "." + typename); DesignTimeType partialType = this.typeProvider.GetType(typename, false) as DesignTimeType; if (partialType == null) { partialType = new DesignTimeType(null, codeTypeDeclaration.Name, codeNamespace.Imports, codeNamespace.Name, this.typeProvider); this.types.Add(partialType); this.typeProvider.AddType(partialType); } partialType.AddCodeTypeDeclaration(codeTypeDeclaration); } } Queue nestedQueue = new Queue(this.types); while (nestedQueue.Count != 0) { Type type = nestedQueue.Dequeue() as Type; if (type.DeclaringType != null) this.types.Add(type); foreach (Type nestedType2 in type.GetNestedTypes(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)) nestedQueue.Enqueue(nestedType2); } } }
public Type GetType(string name, bool throwOnError) { if (name == null) { throw new ArgumentNullException("name"); } EnsureCurrentTypes(); bool hasTypeLoadErrors = false; Type returnType = null; string typeName = string.Empty; string[] parameters = null; string elementDecorator = string.Empty; if (ParseHelpers.ParseTypeName(name, ParseHelpers.ParseTypeNameLanguage.NetFramework, out typeName, out parameters, out elementDecorator)) { if ((parameters != null) && (parameters.Length > 0)) { //Generic type Type templateType = GetType(typeName, throwOnError); if ((templateType == null) || (!templateType.IsGenericTypeDefinition)) { return(null); } Type[] templateParamTypes = new Type[parameters.Length]; for (int index = 0; index < parameters.Length; index++) { Type templateParameter = GetType(parameters[index], throwOnError); if (templateParameter == null) { return(null); } templateParamTypes[index] = templateParameter; } return(templateType.MakeGenericType(templateParamTypes)); } else if (elementDecorator != string.Empty) { //type with element (Array, ByRef, Pointer) Type elementType = this.GetType(typeName); if (elementType != null) { // first we verify the name is formated well (AssemblyQualifiedName for generic // parameters + no spaces in array brackets) System.Text.StringBuilder nameBuilder = new System.Text.StringBuilder(elementType.FullName); for (int loop = 0; loop < elementDecorator.Length; loop++) { if (elementDecorator[loop] != ' ') { nameBuilder.Append(elementDecorator[loop]); } } name = nameBuilder.ToString(); // let tha assembly of the element type a chance to find a type (will fail only // if element contains parameter from external assembly if (elementType.Assembly != null) { returnType = elementType.Assembly.GetType(name, false); } if (returnType == null) { // now we can fetch or create the type if (this.hashOfDTTypes.Contains(name)) { returnType = this.hashOfDTTypes[name] as Type; } else { returnType = new DesignTimeType(null, name, this); this.hashOfDTTypes.Add(name, returnType); } return(returnType); } } } else { // regular type, get the type name string assemblyName = string.Empty; int indexOfComma = name.IndexOf(','); if (indexOfComma != -1) { typeName = name.Substring(0, indexOfComma); assemblyName = name.Substring(indexOfComma + 1).Trim(); } typeName = typeName.Trim(); if (typeName.Length > 0) { returnType = this.designTimeTypes[typeName] as Type; if (returnType == null) { foreach (DictionaryEntry dictionaryEntry in this.rawAssemblyLoaders) { AssemblyLoader assemblyLoader = dictionaryEntry.Value as AssemblyLoader; if ((assemblyName.Length == 0) || (ParseHelpers.AssemblyNameEquals(assemblyLoader.AssemblyName, assemblyName))) { try { returnType = assemblyLoader.GetType(typeName); } catch (Exception e) { if (!this.typeLoadErrors.Contains(dictionaryEntry.Key)) { this.typeLoadErrors[dictionaryEntry.Key] = e; hasTypeLoadErrors = true; } // bubble up exceptions only when appropiate if (throwOnError) { throw e; } } if (returnType != null) { break; } } } } if (returnType == null) { foreach (DictionaryEntry dictionaryEntry in this.assemblyLoaders) { AssemblyLoader assemblyLoader = dictionaryEntry.Value as AssemblyLoader; if ((assemblyName.Length == 0) || (ParseHelpers.AssemblyNameEquals(assemblyLoader.AssemblyName, assemblyName))) { try { returnType = assemblyLoader.GetType(typeName); } catch (Exception e) { if (!this.typeLoadErrors.Contains(dictionaryEntry.Key)) { this.typeLoadErrors[dictionaryEntry.Key] = e; hasTypeLoadErrors = true; } // bubble up exceptions only when appropiate if (throwOnError) { throw e; } } if (returnType != null) { break; } } } } if (hasTypeLoadErrors) { if (this.TypeLoadErrorsChanged != null) { FireEventsNoThrow(this.TypeLoadErrorsChanged, new object[] { this, EventArgs.Empty }); } } if (returnType == null && this.localAssembly != null && assemblyName == this.localAssembly.FullName) { returnType = this.localAssembly.GetType(typeName); } } } } if (returnType == null) { if (throwOnError) { throw new Exception(TypeSystemSR.GetString(CultureInfo.CurrentCulture, "Error_TypeResolution", name)); } else { return(null); } } // replace the System.Type with RTTypeWrapper for generic types. // WinOE if (this.designTimeTypes != null && this.designTimeTypes.Count > 0 && returnType.Assembly != null && returnType.IsGenericTypeDefinition) { if (this.hashOfRTTypes.Contains(returnType)) { returnType = (Type)this.hashOfRTTypes[returnType]; } else { Type returnType2 = new RTTypeWrapper(this, returnType); this.hashOfRTTypes.Add(returnType, returnType2); returnType = returnType2; } } return(returnType); }
public Type GetType(string name, bool throwOnError) { if (name == null) throw new ArgumentNullException("name"); EnsureCurrentTypes(); bool hasTypeLoadErrors = false; Type returnType = null; string typeName = string.Empty; string[] parameters = null; string elementDecorator = string.Empty; if (ParseHelpers.ParseTypeName(name, ParseHelpers.ParseTypeNameLanguage.NetFramework, out typeName, out parameters, out elementDecorator)) { if ((parameters != null) && (parameters.Length > 0)) { //Generic type Type templateType = GetType(typeName, throwOnError); if ((templateType == null) || (!templateType.IsGenericTypeDefinition)) return null; Type[] templateParamTypes = new Type[parameters.Length]; for (int index = 0; index < parameters.Length; index++) { Type templateParameter = GetType(parameters[index], throwOnError); if (templateParameter == null) return null; templateParamTypes[index] = templateParameter; } return templateType.MakeGenericType(templateParamTypes); } else if (elementDecorator != string.Empty) { //type with element (Array, ByRef, Pointer) Type elementType = this.GetType(typeName); if (elementType != null) { // first we verify the name is formated well (AssemblyQualifiedName for generic // parameters + no spaces in array brackets) System.Text.StringBuilder nameBuilder = new System.Text.StringBuilder(elementType.FullName); for (int loop = 0; loop < elementDecorator.Length; loop++) if (elementDecorator[loop] != ' ') nameBuilder.Append(elementDecorator[loop]); name = nameBuilder.ToString(); // let tha assembly of the element type a chance to find a type (will fail only // if element contains parameter from external assembly if (elementType.Assembly != null) returnType = elementType.Assembly.GetType(name, false); if (returnType == null) { // now we can fetch or create the type if (this.hashOfDTTypes.Contains(name)) { returnType = this.hashOfDTTypes[name] as Type; } else { returnType = new DesignTimeType(null, name, this); this.hashOfDTTypes.Add(name, returnType); } return returnType; } } } else { // regular type, get the type name string assemblyName = string.Empty; int indexOfComma = name.IndexOf(','); if (indexOfComma != -1) { typeName = name.Substring(0, indexOfComma); assemblyName = name.Substring(indexOfComma + 1).Trim(); } typeName = typeName.Trim(); if (typeName.Length > 0) { returnType = this.designTimeTypes[typeName] as Type; if (returnType == null) { foreach (DictionaryEntry dictionaryEntry in this.rawAssemblyLoaders) { AssemblyLoader assemblyLoader = dictionaryEntry.Value as AssemblyLoader; if ((assemblyName.Length == 0) || (ParseHelpers.AssemblyNameEquals(assemblyLoader.AssemblyName, assemblyName))) { try { returnType = assemblyLoader.GetType(typeName); } catch (Exception e) { if (!this.typeLoadErrors.Contains(dictionaryEntry.Key)) { this.typeLoadErrors[dictionaryEntry.Key] = e; hasTypeLoadErrors = true; } // bubble up exceptions only when appropiate if (throwOnError) throw e; } if (returnType != null) break; } } } if (returnType == null) { foreach (DictionaryEntry dictionaryEntry in this.assemblyLoaders) { AssemblyLoader assemblyLoader = dictionaryEntry.Value as AssemblyLoader; if ((assemblyName.Length == 0) || (ParseHelpers.AssemblyNameEquals(assemblyLoader.AssemblyName, assemblyName))) { try { returnType = assemblyLoader.GetType(typeName); } catch (Exception e) { if (!this.typeLoadErrors.Contains(dictionaryEntry.Key)) { this.typeLoadErrors[dictionaryEntry.Key] = e; hasTypeLoadErrors = true; } // bubble up exceptions only when appropiate if (throwOnError) throw e; } if (returnType != null) break; } } } if (hasTypeLoadErrors) { if (this.TypeLoadErrorsChanged != null) FireEventsNoThrow(this.TypeLoadErrorsChanged, new object[] { this, EventArgs.Empty }); } if (returnType == null && this.localAssembly != null && assemblyName == this.localAssembly.FullName) returnType = this.localAssembly.GetType(typeName); } } } if (returnType == null) { if (throwOnError) throw new Exception(TypeSystemSR.GetString(CultureInfo.CurrentCulture, "Error_TypeResolution", name)); else return null; } // replace the System.Type with RTTypeWrapper for generic types. // WinOE if (this.designTimeTypes != null && this.designTimeTypes.Count > 0 && returnType.Assembly != null && returnType.IsGenericTypeDefinition) { if (this.hashOfRTTypes.Contains(returnType)) { returnType = (Type)this.hashOfRTTypes[returnType]; } else { Type returnType2 = new RTTypeWrapper(this, returnType); this.hashOfRTTypes.Add(returnType, returnType2); returnType = returnType2; } } return returnType; }
internal DesignTimePropertyInfo(DesignTimeType declaringType, CodeMemberProperty property) { this.property = property; this.declaringType = declaringType; }
public Type GetType(string name, bool throwOnError) { if (name == null) { throw new ArgumentNullException("name"); } this.EnsureCurrentTypes(); bool flag = false; Type type = null; string typeName = string.Empty; string[] parameters = null; string elemantDecorator = string.Empty; if (ParseHelpers.ParseTypeName(name, ParseHelpers.ParseTypeNameLanguage.NetFramework, out typeName, out parameters, out elemantDecorator)) { if ((parameters != null) && (parameters.Length > 0)) { Type type2 = this.GetType(typeName, throwOnError); if ((type2 == null) || !type2.IsGenericTypeDefinition) { return(null); } Type[] typeArguments = new Type[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { Type type3 = this.GetType(parameters[i], throwOnError); if (type3 == null) { return(null); } typeArguments[i] = type3; } return(type2.MakeGenericType(typeArguments)); } if (elemantDecorator != string.Empty) { Type type4 = this.GetType(typeName); if (type4 != null) { StringBuilder builder = new StringBuilder(type4.FullName); for (int j = 0; j < elemantDecorator.Length; j++) { if (elemantDecorator[j] != ' ') { builder.Append(elemantDecorator[j]); } } name = builder.ToString(); if (type4.Assembly != null) { type = type4.Assembly.GetType(name, false); } if (type == null) { if (this.hashOfDTTypes.Contains(name)) { return(this.hashOfDTTypes[name] as Type); } type = new DesignTimeType(null, name, this); this.hashOfDTTypes.Add(name, type); return(type); } } } else { string thatName = string.Empty; int index = name.IndexOf(','); if (index != -1) { typeName = name.Substring(0, index); thatName = name.Substring(index + 1).Trim(); } typeName = typeName.Trim(); if (typeName.Length > 0) { type = this.designTimeTypes[typeName] as Type; if (type == null) { foreach (DictionaryEntry entry in this.rawAssemblyLoaders) { AssemblyLoader loader = entry.Value as AssemblyLoader; if ((thatName.Length == 0) || ParseHelpers.AssemblyNameEquals(loader.AssemblyName, thatName)) { try { type = loader.GetType(typeName); } catch (Exception exception) { if (!this.typeLoadErrors.Contains(entry.Key)) { this.typeLoadErrors[entry.Key] = exception; flag = true; } if (throwOnError) { throw exception; } } if (type != null) { break; } } } } if (type == null) { foreach (DictionaryEntry entry2 in this.assemblyLoaders) { AssemblyLoader loader2 = entry2.Value as AssemblyLoader; if ((thatName.Length == 0) || ParseHelpers.AssemblyNameEquals(loader2.AssemblyName, thatName)) { try { type = loader2.GetType(typeName); } catch (Exception exception2) { if (!this.typeLoadErrors.Contains(entry2.Key)) { this.typeLoadErrors[entry2.Key] = exception2; flag = true; } if (throwOnError) { throw exception2; } } if (type != null) { break; } } } } if (flag && (this.TypeLoadErrorsChanged != null)) { FireEventsNoThrow(this.TypeLoadErrorsChanged, new object[] { this, EventArgs.Empty }); } if (((type == null) && (this.localAssembly != null)) && (thatName == this.localAssembly.FullName)) { type = this.localAssembly.GetType(typeName); } } } } if (type == null) { if (throwOnError) { throw new Exception(TypeSystemSR.GetString(CultureInfo.CurrentCulture, "Error_TypeResolution", new object[] { name })); } return(null); } if (((this.designTimeTypes == null) || (this.designTimeTypes.Count <= 0)) || ((type.Assembly == null) || !type.IsGenericTypeDefinition)) { return(type); } if (this.hashOfRTTypes.Contains(type)) { return((Type)this.hashOfRTTypes[type]); } Type type5 = new RTTypeWrapper(this, type); this.hashOfRTTypes.Add(type, type5); return(type5); }
public Type GetType(string name, bool throwOnError) { if (name == null) { throw new ArgumentNullException("name"); } this.EnsureCurrentTypes(); bool flag = false; Type type = null; string typeName = string.Empty; string[] parameters = null; string elemantDecorator = string.Empty; if (ParseHelpers.ParseTypeName(name, ParseHelpers.ParseTypeNameLanguage.NetFramework, out typeName, out parameters, out elemantDecorator)) { if ((parameters != null) && (parameters.Length > 0)) { Type type2 = this.GetType(typeName, throwOnError); if ((type2 == null) || !type2.IsGenericTypeDefinition) { return null; } Type[] typeArguments = new Type[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { Type type3 = this.GetType(parameters[i], throwOnError); if (type3 == null) { return null; } typeArguments[i] = type3; } return type2.MakeGenericType(typeArguments); } if (elemantDecorator != string.Empty) { Type type4 = this.GetType(typeName); if (type4 != null) { StringBuilder builder = new StringBuilder(type4.FullName); for (int j = 0; j < elemantDecorator.Length; j++) { if (elemantDecorator[j] != ' ') { builder.Append(elemantDecorator[j]); } } name = builder.ToString(); if (type4.Assembly != null) { type = type4.Assembly.GetType(name, false); } if (type == null) { if (this.hashOfDTTypes.Contains(name)) { return (this.hashOfDTTypes[name] as Type); } type = new DesignTimeType(null, name, this); this.hashOfDTTypes.Add(name, type); return type; } } } else { string thatName = string.Empty; int index = name.IndexOf(','); if (index != -1) { typeName = name.Substring(0, index); thatName = name.Substring(index + 1).Trim(); } typeName = typeName.Trim(); if (typeName.Length > 0) { type = this.designTimeTypes[typeName] as Type; if (type == null) { foreach (DictionaryEntry entry in this.rawAssemblyLoaders) { AssemblyLoader loader = entry.Value as AssemblyLoader; if ((thatName.Length == 0) || ParseHelpers.AssemblyNameEquals(loader.AssemblyName, thatName)) { try { type = loader.GetType(typeName); } catch (Exception exception) { if (!this.typeLoadErrors.Contains(entry.Key)) { this.typeLoadErrors[entry.Key] = exception; flag = true; } if (throwOnError) { throw exception; } } if (type != null) { break; } } } } if (type == null) { foreach (DictionaryEntry entry2 in this.assemblyLoaders) { AssemblyLoader loader2 = entry2.Value as AssemblyLoader; if ((thatName.Length == 0) || ParseHelpers.AssemblyNameEquals(loader2.AssemblyName, thatName)) { try { type = loader2.GetType(typeName); } catch (Exception exception2) { if (!this.typeLoadErrors.Contains(entry2.Key)) { this.typeLoadErrors[entry2.Key] = exception2; flag = true; } if (throwOnError) { throw exception2; } } if (type != null) { break; } } } } if (flag && (this.TypeLoadErrorsChanged != null)) { FireEventsNoThrow(this.TypeLoadErrorsChanged, new object[] { this, EventArgs.Empty }); } if (((type == null) && (this.localAssembly != null)) && (thatName == this.localAssembly.FullName)) { type = this.localAssembly.GetType(typeName); } } } } if (type == null) { if (throwOnError) { throw new Exception(TypeSystemSR.GetString(CultureInfo.CurrentCulture, "Error_TypeResolution", new object[] { name })); } return null; } if (((this.designTimeTypes == null) || (this.designTimeTypes.Count <= 0)) || ((type.Assembly == null) || !type.IsGenericTypeDefinition)) { return type; } if (this.hashOfRTTypes.Contains(type)) { return (Type) this.hashOfRTTypes[type]; } Type type5 = new RTTypeWrapper(this, type); this.hashOfRTTypes.Add(type, type5); return type5; }
internal DesignTimeConstructorInfo(DesignTimeType declaringType, CodeMemberMethod codeConstructor) { this.declaringType = declaringType; this.codeConstructor = codeConstructor; }
public object GetArgumentValueAs(IServiceProvider serviceProvider, int argumentIndex, Type requestedType) { if (argumentIndex >= this.ArgumentValues.Count || argumentIndex < 0) { throw new ArgumentException(SR.GetString(SR.Error_InvalidArgumentIndex), "argumentIndex"); } if (requestedType == null) { throw new ArgumentNullException("requestedType"); } SupportedLanguages language = CompilerHelpers.GetSupportedLanguage(serviceProvider); if (requestedType == typeof(string)) { string returnValue = this.ArgumentValues[argumentIndex] as string; // string values read by the code-dom parser are double escaped, so // remove the 2nd escaping (we need to leave the escaping in at parse time) // in case the attribute argument is never processed and emitted as // the code snippet if (returnValue != null) { try { returnValue = Regex.Unescape(returnValue); } catch { } } if (returnValue != null) { if (returnValue.EndsWith("\"", StringComparison.Ordinal)) { returnValue = returnValue.Substring(0, returnValue.Length - 1); } if (language == SupportedLanguages.CSharp && returnValue.StartsWith("@\"", StringComparison.Ordinal)) { returnValue = returnValue.Substring(2, returnValue.Length - 2); } else if (returnValue.StartsWith("\"", StringComparison.Ordinal)) { returnValue = returnValue.Substring(1, returnValue.Length - 1); } } return(returnValue); } else if (requestedType.IsEnum) { string parseableValue = ""; bool firstValue = true; foreach (string enumValue in (this.ArgumentValues[argumentIndex] as string).Split(new string[] { language == SupportedLanguages.CSharp ? "|" : "Or" }, StringSplitOptions.RemoveEmptyEntries)) { if (!firstValue) { parseableValue += ","; } int valueSep = enumValue.LastIndexOf('.'); if (valueSep != -1) { parseableValue += enumValue.Substring(valueSep + 1); } else { parseableValue += enumValue; } firstValue = false; } return(Enum.Parse(requestedType, parseableValue)); } else if (requestedType == typeof(bool)) { return(System.Convert.ToBoolean(this.ArgumentValues[argumentIndex], CultureInfo.InvariantCulture)); } else if (requestedType == typeof(Type)) { string typeName = ""; if (this.ArgumentValues[argumentIndex] is CodeTypeOfExpression) { typeName = DesignTimeType.GetTypeNameFromCodeTypeReference((this.ArgumentValues[argumentIndex] as CodeTypeOfExpression).Type, null); } ITypeProvider typeProvider = serviceProvider.GetService(typeof(ITypeProvider)) as ITypeProvider; if (typeProvider == null) { throw new Exception(SR.GetString(SR.General_MissingService, typeof(ITypeProvider).ToString())); } Type returnType = ParseHelpers.ParseTypeName(typeProvider, language, typeName); if (returnType == null) { // Try to parse the attribute value manually string[] genericParamTypeNames = null; string baseTypeName = string.Empty; string elementDecorators = string.Empty; if (ParseHelpers.ParseTypeName(typeName, language == SupportedLanguages.CSharp ? ParseHelpers.ParseTypeNameLanguage.CSharp : ParseHelpers.ParseTypeNameLanguage.VB, out baseTypeName, out genericParamTypeNames, out elementDecorators)) { if (baseTypeName != null && genericParamTypeNames != null) { string parsedTypeName = baseTypeName + "`" + genericParamTypeNames.Length.ToString(CultureInfo.InvariantCulture) + "["; foreach (string genericArg in genericParamTypeNames) { if (genericArg != genericParamTypeNames[0]) { parsedTypeName += ","; } Type genericArgType = ParseHelpers.ParseTypeName(typeProvider, language, genericArg); if (genericArgType != null) { parsedTypeName += "[" + genericArgType.FullName + "]"; } else { parsedTypeName += "[" + genericArg + "]"; } } parsedTypeName += "]"; returnType = ParseHelpers.ParseTypeName(typeProvider, language, parsedTypeName); } } } return(returnType); } return(null); }
internal DesignTimeMethodInfo(DesignTimeType declaringType, CodeMemberMethod methodInfo) { this.declaringType = declaringType; this.methodInfo = methodInfo; }
internal DesignTimeMethodInfo(DesignTimeType declaringType, CodeMemberMethod methodInfo, bool isSpecialName) { this.declaringType = declaringType; this.methodInfo = methodInfo; this.isSpecialName = isSpecialName; }
internal static Attribute[] LoadCustomAttributes(CodeAttributeDeclarationCollection codeAttributeCollection, DesignTimeType declaringType) { if (declaringType == null) throw new ArgumentNullException("declaringType"); if (codeAttributeCollection == null) return new Attribute[0]; List<Attribute> attributes = new List<Attribute>(); // walk through the attributes foreach (CodeAttributeDeclaration codeAttribute in codeAttributeCollection) { String[] argumentNames = new String[codeAttribute.Arguments.Count]; object[] argumentValues = new object[codeAttribute.Arguments.Count]; Type attributeType = declaringType.ResolveType(codeAttribute.Name); if (attributeType != null) { int index = 0; // walk through tha arguments foreach (CodeAttributeArgument codeArgument in codeAttribute.Arguments) { argumentNames[index] = codeArgument.Name; if (codeArgument.Value is CodePrimitiveExpression) argumentValues[index] = (codeArgument.Value as CodePrimitiveExpression).Value; else if (codeArgument.Value is CodeTypeOfExpression) argumentValues[index] = codeArgument.Value; else if (codeArgument.Value is CodeSnippetExpression) argumentValues[index] = (codeArgument.Value as CodeSnippetExpression).Value; else argumentValues[index] = new ArgumentException(SR.GetString(SR.Error_TypeSystemAttributeArgument)); index++; } bool alreadyExists = false; foreach (AttributeInfoAttribute attribInfo in attributes) { if (attribInfo.AttributeInfo.AttributeType.FullName.Equals(attributeType.FullName)) { alreadyExists = true; break; } } // bool allowMultiple = false; if (alreadyExists && attributeType.Assembly != null) { object[] usageAttribs = attributeType.GetCustomAttributes(typeof(System.AttributeUsageAttribute), true); if (usageAttribs != null && usageAttribs.Length > 0) { AttributeUsageAttribute usage = usageAttribs[0] as AttributeUsageAttribute; allowMultiple = usage.AllowMultiple; } } // now create and add the placeholder attribute if (!alreadyExists || allowMultiple) attributes.Add(AttributeInfoAttribute.CreateAttributeInfoAttribute(attributeType, argumentNames, argumentValues)); } } return attributes.ToArray(); }
internal static Attribute[] LoadCustomAttributes(CodeAttributeDeclarationCollection codeAttributeCollection, DesignTimeType declaringType) { if (declaringType == null) { throw new ArgumentNullException("declaringType"); } if (codeAttributeCollection == null) { return(new Attribute[0]); } List <Attribute> attributes = new List <Attribute>(); // walk through the attributes foreach (CodeAttributeDeclaration codeAttribute in codeAttributeCollection) { String[] argumentNames = new String[codeAttribute.Arguments.Count]; object[] argumentValues = new object[codeAttribute.Arguments.Count]; Type attributeType = declaringType.ResolveType(codeAttribute.Name); if (attributeType != null) { int index = 0; // walk through tha arguments foreach (CodeAttributeArgument codeArgument in codeAttribute.Arguments) { argumentNames[index] = codeArgument.Name; if (codeArgument.Value is CodePrimitiveExpression) { argumentValues[index] = (codeArgument.Value as CodePrimitiveExpression).Value; } else if (codeArgument.Value is CodeTypeOfExpression) { argumentValues[index] = codeArgument.Value; } else if (codeArgument.Value is CodeSnippetExpression) { argumentValues[index] = (codeArgument.Value as CodeSnippetExpression).Value; } else { argumentValues[index] = new ArgumentException(SR.GetString(SR.Error_TypeSystemAttributeArgument)); } index++; } bool alreadyExists = false; foreach (AttributeInfoAttribute attribInfo in attributes) { if (attribInfo.AttributeInfo.AttributeType.FullName.Equals(attributeType.FullName)) { alreadyExists = true; break; } } // bool allowMultiple = false; if (alreadyExists && attributeType.Assembly != null) { object[] usageAttribs = attributeType.GetCustomAttributes(typeof(System.AttributeUsageAttribute), true); if (usageAttribs != null && usageAttribs.Length > 0) { AttributeUsageAttribute usage = usageAttribs[0] as AttributeUsageAttribute; allowMultiple = usage.AllowMultiple; } } // now create and add the placeholder attribute if (!alreadyExists || allowMultiple) { attributes.Add(AttributeInfoAttribute.CreateAttributeInfoAttribute(attributeType, argumentNames, argumentValues)); } } } return(attributes.ToArray()); }
internal static Attribute[] LoadCustomAttributes(CodeAttributeDeclarationCollection codeAttributeCollection, DesignTimeType declaringType) { if (declaringType == null) { throw new ArgumentNullException("declaringType"); } if (codeAttributeCollection == null) { return(new Attribute[0]); } List <Attribute> list = new List <Attribute>(); foreach (CodeAttributeDeclaration declaration in codeAttributeCollection) { string[] argumentNames = new string[declaration.Arguments.Count]; object[] argumentValues = new object[declaration.Arguments.Count]; Type attributeType = declaringType.ResolveType(declaration.Name); if (attributeType != null) { int index = 0; foreach (CodeAttributeArgument argument in declaration.Arguments) { argumentNames[index] = argument.Name; if (argument.Value is CodePrimitiveExpression) { argumentValues[index] = (argument.Value as CodePrimitiveExpression).Value; } else if (argument.Value is CodeTypeOfExpression) { argumentValues[index] = argument.Value; } else if (argument.Value is CodeSnippetExpression) { argumentValues[index] = (argument.Value as CodeSnippetExpression).Value; } else { argumentValues[index] = new ArgumentException(SR.GetString("Error_TypeSystemAttributeArgument")); } index++; } bool flag = false; foreach (AttributeInfoAttribute attribute in list) { if (attribute.AttributeInfo.AttributeType.FullName.Equals(attributeType.FullName)) { flag = true; break; } } bool allowMultiple = false; if (flag && (attributeType.Assembly != null)) { object[] customAttributes = attributeType.GetCustomAttributes(typeof(AttributeUsageAttribute), true); if ((customAttributes != null) && (customAttributes.Length > 0)) { AttributeUsageAttribute attribute2 = customAttributes[0] as AttributeUsageAttribute; allowMultiple = attribute2.AllowMultiple; } } if (!flag || allowMultiple) { list.Add(AttributeInfoAttribute.CreateAttributeInfoAttribute(attributeType, argumentNames, argumentValues)); } } } return(list.ToArray()); }
internal static Attribute[] LoadCustomAttributes(CodeAttributeDeclarationCollection codeAttributeCollection, DesignTimeType declaringType) { if (declaringType == null) { throw new ArgumentNullException("declaringType"); } if (codeAttributeCollection == null) { return new Attribute[0]; } List<Attribute> list = new List<Attribute>(); foreach (CodeAttributeDeclaration declaration in codeAttributeCollection) { string[] argumentNames = new string[declaration.Arguments.Count]; object[] argumentValues = new object[declaration.Arguments.Count]; Type attributeType = declaringType.ResolveType(declaration.Name); if (attributeType != null) { int index = 0; foreach (CodeAttributeArgument argument in declaration.Arguments) { argumentNames[index] = argument.Name; if (argument.Value is CodePrimitiveExpression) { argumentValues[index] = (argument.Value as CodePrimitiveExpression).Value; } else if (argument.Value is CodeTypeOfExpression) { argumentValues[index] = argument.Value; } else if (argument.Value is CodeSnippetExpression) { argumentValues[index] = (argument.Value as CodeSnippetExpression).Value; } else { argumentValues[index] = new ArgumentException(SR.GetString("Error_TypeSystemAttributeArgument")); } index++; } bool flag = false; foreach (AttributeInfoAttribute attribute in list) { if (attribute.AttributeInfo.AttributeType.FullName.Equals(attributeType.FullName)) { flag = true; break; } } bool allowMultiple = false; if (flag && (attributeType.Assembly != null)) { object[] customAttributes = attributeType.GetCustomAttributes(typeof(AttributeUsageAttribute), true); if ((customAttributes != null) && (customAttributes.Length > 0)) { AttributeUsageAttribute attribute2 = customAttributes[0] as AttributeUsageAttribute; allowMultiple = attribute2.AllowMultiple; } } if (!flag || allowMultiple) { list.Add(AttributeInfoAttribute.CreateAttributeInfoAttribute(attributeType, argumentNames, argumentValues)); } } } return list.ToArray(); }
public object GetArgumentValueAs(IServiceProvider serviceProvider, int argumentIndex, Type requestedType) { if ((argumentIndex >= this.ArgumentValues.Count) || (argumentIndex < 0)) { throw new ArgumentException(SR.GetString("Error_InvalidArgumentIndex"), "argumentIndex"); } if (requestedType == null) { throw new ArgumentNullException("requestedType"); } SupportedLanguages supportedLanguage = CompilerHelpers.GetSupportedLanguage(serviceProvider); if (requestedType == typeof(string)) { string str = this.ArgumentValues[argumentIndex] as string; if (str != null) { try { str = Regex.Unescape(str); } catch { } } if (str != null) { if (str.EndsWith("\"", StringComparison.Ordinal)) { str = str.Substring(0, str.Length - 1); } if ((supportedLanguage == SupportedLanguages.CSharp) && str.StartsWith("@\"", StringComparison.Ordinal)) { return(str.Substring(2, str.Length - 2)); } if (str.StartsWith("\"", StringComparison.Ordinal)) { str = str.Substring(1, str.Length - 1); } } return(str); } if (requestedType.IsEnum) { string str2 = ""; bool flag = true; foreach (string str3 in (this.ArgumentValues[argumentIndex] as string).Split(new string[] { (supportedLanguage == SupportedLanguages.CSharp) ? "|" : "Or" }, StringSplitOptions.RemoveEmptyEntries)) { if (!flag) { str2 = str2 + ","; } int num = str3.LastIndexOf('.'); if (num != -1) { str2 = str2 + str3.Substring(num + 1); } else { str2 = str2 + str3; } flag = false; } return(Enum.Parse(requestedType, str2)); } if (requestedType == typeof(bool)) { return(Convert.ToBoolean(this.ArgumentValues[argumentIndex], CultureInfo.InvariantCulture)); } if (!(requestedType == typeof(Type))) { return(null); } string typeName = ""; if (this.ArgumentValues[argumentIndex] is CodeTypeOfExpression) { typeName = DesignTimeType.GetTypeNameFromCodeTypeReference((this.ArgumentValues[argumentIndex] as CodeTypeOfExpression).Type, null); } ITypeProvider service = serviceProvider.GetService(typeof(ITypeProvider)) as ITypeProvider; if (service == null) { throw new Exception(SR.GetString("General_MissingService", new object[] { typeof(ITypeProvider).ToString() })); } Type type = ParseHelpers.ParseTypeName(service, supportedLanguage, typeName); if (type != null) { return(type); } string[] parameters = null; string str5 = string.Empty; string elemantDecorator = string.Empty; if ((!ParseHelpers.ParseTypeName(typeName, (supportedLanguage == SupportedLanguages.CSharp) ? ParseHelpers.ParseTypeNameLanguage.CSharp : ParseHelpers.ParseTypeNameLanguage.VB, out str5, out parameters, out elemantDecorator) || (str5 == null)) || (parameters == null)) { return(type); } string str7 = str5 + "`" + parameters.Length.ToString(CultureInfo.InvariantCulture) + "["; foreach (string str8 in parameters) { if (str8 != parameters[0]) { str7 = str7 + ","; } Type type2 = ParseHelpers.ParseTypeName(service, supportedLanguage, str8); if (type2 != null) { str7 = str7 + "[" + type2.FullName + "]"; } else { str7 = str7 + "[" + str8 + "]"; } } str7 = str7 + "]"; return(ParseHelpers.ParseTypeName(service, supportedLanguage, str7)); }