public static void AddAttribute(IAttributeHolder holder, CodeAttributeDeclarationCollection attributs, bool isWebService, bool includeOperationContract, string namespaceText) { List <ConstObjectPointer> list = holder.GetCustomAttributeList(); if (list != null && list.Count > 0) { foreach (ConstObjectPointer cop in list) { if (!includeOperationContract) { if (typeof(OperationContractAttribute).IsAssignableFrom(cop.BaseClassType)) { continue; } } if (!isWebService) { if (typeof(WebServiceAttribute).Equals(cop.BaseClassType)) { isWebService = true; } } CodeAttributeArgument[] aa = new CodeAttributeArgument[cop.ParameterCount]; for (int i = 0; i < cop.ParameterCount; i++) { aa[i] = new CodeAttributeArgument(cop.GetParameterCode(null, null, i)); } CodeAttributeDeclaration a = new CodeAttributeDeclaration( cop.TypeString, aa); if (cop.ParameterCount == 0) { AttributeConstructor ac = cop.Value as AttributeConstructor; if (ac != null && ac.Values != null) { IList <CodeAttributeArgument> lst = ac.CreatePropertyExpressions(); foreach (CodeAttributeArgument caa in lst) { a.Arguments.Add(caa); } } bool isInterface = (holder is InterfaceClass); bool isServiceContract = cop.BaseClassType.FullName.StartsWith("System.ServiceModel.ServiceContractAttribute", StringComparison.Ordinal); if (isInterface && isServiceContract) { bool hasNamespace = false; if (ac != null && ac.Values != null) { if (string.IsNullOrEmpty(ac.Values[PROP_Namespace] as string)) { } else { hasNamespace = true; } } if (!hasNamespace) { a.Arguments.Add(new CodeAttributeArgument(PROP_Namespace, new CodePrimitiveExpression(string.Format(CultureInfo.InvariantCulture, "http://{0}", namespaceText)))); } } } attributs.Add(a); } } }
public PropertyDescriptorNamedValue(string name, Attribute[] attrs, AttributeConstructor owner, Type valueType) : base(name, attrs) { _owner = owner; _valueType = valueType; }