示例#1
0
文件: XmlnsCache.cs 项目: minsys/wpf
        private void GetNamespacesFromDefinitionAttr(Attribute attr, out string xmlns, out string clrns)
        {
            XmlnsDefinitionAttribute xmlnsAttr = (XmlnsDefinitionAttribute)attr;

            xmlns = xmlnsAttr.XmlNamespace;
            clrns = xmlnsAttr.ClrNamespace;
        }
        private IList <XmlNsDefinition> LoadNsDefs()
        {
            IList <XmlNsDefinition> result = new List <XmlNsDefinition>();

            System.Reflection.Assembly assembly = this.Assembly;
            if (assembly != null)
            {
                if (assembly.ReflectionOnly)
                {
                    this.EnsureReflectionOnlyAttributeData();
                    foreach (CustomAttributeData data in this._attributeData)
                    {
                        if (LooseTypeExtensions.AssemblyQualifiedNameEquals(data.Constructor.DeclaringType, typeof(XmlnsDefinitionAttribute)))
                        {
                            CustomAttributeTypedArgument argument = data.ConstructorArguments[0];
                            string xmlns = argument.Value as string;
                            CustomAttributeTypedArgument argument2 = data.ConstructorArguments[1];
                            string clrns = argument2.Value as string;
                            this.LoadNsDefHelper(result, xmlns, clrns, assembly);
                        }
                    }
                    return(result);
                }
                foreach (Attribute attribute in Attribute.GetCustomAttributes(assembly, typeof(XmlnsDefinitionAttribute)))
                {
                    XmlnsDefinitionAttribute attribute2 = (XmlnsDefinitionAttribute)attribute;
                    string xmlNamespace = attribute2.XmlNamespace;
                    string clrNamespace = attribute2.ClrNamespace;
                    this.LoadNsDefHelper(result, xmlNamespace, clrNamespace, assembly);
                }
            }
            return(result);
        }
示例#3
0
        private void GatherAssemblyInfo(string p)
        {
            try
            {
                ModuleDefinition module = ModuleDefinition.ReadModule(p);

                if (null == baseTypeDefiniation)
                {
                    baseTypeDefiniation = module.GetType("Tizen.NUI.Binding.BindableObject");
                }

                foreach (var attr in module.Assembly.CustomAttributes)
                {
                    if (attr.AttributeType.FullName == "Tizen.NUI.XmlnsDefinitionAttribute")
                    {
                        string xmlNamespace = attr.ConstructorArguments[0].Value as string;
                        string clrNamespace = attr.ConstructorArguments[1].Value as string;

                        int    level        = 0;
                        string assemblyName = module.Assembly.FullName;

                        if (true == attr.HasProperties)
                        {
                            foreach (var property in attr.Properties)
                            {
                                if ("Level" == property.Name)
                                {
                                    level = int.Parse(property.Argument.Value.ToString());
                                }
                                if ("AssemblyName" == property.Name)
                                {
                                    assemblyName = property.Argument.Value as string;
                                }
                            }
                        }

                        XmlnsDefinitionAttribute attribute = new XmlnsDefinitionAttribute(xmlNamespace, clrNamespace, level);
                        attribute.AssemblyName = assemblyName;
                        s_xmlnsDefinitions.Add(attribute);
                    }
                }

                module.Dispose();
            }
            catch (Exception e)
            {
                int temp = 0;
            }
        }
示例#4
0
        public static XmlnsDefinitionAttribute GetXmlnsDefinition(this CustomAttribute ca, AssemblyDefinition asmDef)
        {
            var attr = new XmlnsDefinitionAttribute(
                ca.ConstructorArguments[0].Value as string,
                ca.ConstructorArguments[1].Value as string);

            string assemblyName = null;

            if (ca.Properties.Count > 0)
            {
                assemblyName = ca.Properties[0].Argument.Value as string;
            }
            attr.AssemblyName = assemblyName ?? asmDef.Name.FullName;
            return(attr);
        }
示例#5
0
        public static string GetAssemblyNameForNamespaceDeclaration(string namespaceDeclaration)
        {
            if (string.IsNullOrWhiteSpace(namespaceDeclaration))
            {
                return(null);
            }

            // Ordinary namespace declaration of the form
            // xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
            if (namespaceDeclaration.StartsWith(CLR_NAMESPACE, StringComparison.Ordinal))
            {
                int pos = namespaceDeclaration.IndexOf("=", CLR_NAMESPACE.Length + 1, StringComparison.Ordinal);
                if (pos > -1)
                {
                    Assembly a = GetAssemblyByName(namespaceDeclaration.Substring(pos + 1));
                    if (a != null)
                    {
                        return(a.FullName.Split(',')[0]);
                    }
                }
            }
            else if (namespaceDeclaration.StartsWith("http://", StringComparison.OrdinalIgnoreCase) ||
                     namespaceDeclaration.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
            {
                // Xmlns declaration of the form
                // xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
                foreach (Assembly assembly in assemblies)
                {
                    XmlnsDefinitionAttribute defnAttribute = null;
                    object[] attribs = assembly.GetCustomAttributes(typeof(XmlnsDefinitionAttribute), false);
                    if (attribs != null && attribs.Length > 0)
                    {
                        defnAttribute = attribs[0] as XmlnsDefinitionAttribute;
                    }

                    if (defnAttribute != null)
                    {
                        string namespaceMapping = defnAttribute.XmlNamespace;
                        if (namespaceDeclaration == namespaceMapping)
                        {
                            return(assembly.FullName.Split(',')[0]);
                        }
                    }
                }
            }
            return(null);
        }
示例#6
0
        IList <XmlNsDefinition> LoadNsDefs()
        {
            IList <XmlNsDefinition> result = new List <XmlNsDefinition>();

            Assembly assembly = Assembly;

            if (assembly == null)
            {
                return(result);
            }
            if (assembly.ReflectionOnly)
            {
                EnsureReflectionOnlyAttributeData();
                foreach (var cad in _attributeData)
                {
                    if (LooseTypeExtensions.AssemblyQualifiedNameEquals(cad.Constructor.DeclaringType, typeof(XmlnsDefinitionAttribute)))
                    {
                        // WPF 3.0 ignores XmlnsDefinitionAttribute.AssemblyName, and so do we
                        string xmlns = cad.ConstructorArguments[0].Value as string;
                        string clrns = cad.ConstructorArguments[1].Value as string;
                        LoadNsDefHelper(result, xmlns, clrns, assembly);
                    }
                }
            }
            else
            {
                Attribute[] attributes;
                attributes = Attribute.GetCustomAttributes(assembly, typeof(XmlnsDefinitionAttribute));
                foreach (Attribute attr in attributes)
                {
                    XmlnsDefinitionAttribute xmlnsDefAttr = (XmlnsDefinitionAttribute)attr;

                    string xmlns = xmlnsDefAttr.XmlNamespace;
                    string clrns = xmlnsDefAttr.ClrNamespace;
                    LoadNsDefHelper(result, xmlns, clrns, assembly);
                }
            }
            return(result);
        }
示例#7
0
        IList <XmlnsDefinitionAttribute> GetXmlnsDefinitionAttribules(GeneratorExecutionContext context)
        {
            var cache = new List <XmlnsDefinitionAttribute>();
            INamedTypeSymbol?xmlnsDefinitonAttribute = context.Compilation.GetTypeByMetadataName(typeof(XmlnsDefinitionAttribute).FullName);

            if (xmlnsDefinitonAttribute == null)
            {
                return(cache);
            }
            foreach (var reference in context.Compilation.References)
            {
                var symbol = context.Compilation.GetAssemblyOrModuleSymbol(reference) as IAssemblySymbol;
                if (symbol == null)
                {
                    continue;
                }
                foreach (var attr in symbol.GetAttributes())
                {
                    if (!SymbolEqualityComparer.Default.Equals(attr.AttributeClass, xmlnsDefinitonAttribute))
                    {
                        continue;
                    }
                    var xmlnsDef = new XmlnsDefinitionAttribute(attr.ConstructorArguments[0].Value as string, attr.ConstructorArguments[1].Value as string);
                    if (attr.NamedArguments.Length == 1 && attr.NamedArguments[0].Key == nameof(XmlnsDefinitionAttribute.AssemblyName))
                    {
                        xmlnsDef.AssemblyName = attr.NamedArguments[0].Value.Value as string;
                    }
                    else
                    {
                        xmlnsDef.AssemblyName = symbol.Name;
                    }
                    cache.Add(xmlnsDef);
                }
            }

            return(cache);
        }
示例#8
0
        private void GatherAssemblyInfo(string p)
        {
            try
            {
                System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFrom(p);

                Type definitionAttribute = assembly.GetType(bindingNameSpace + ".XmlnsDefinitionAttribute");

                if (null != definitionAttribute)
                {
                    foreach (object obj in assembly.GetCustomAttributes(definitionAttribute, false))
                    {
                        string assemblyName = definitionAttribute.GetProperty("AssemblyName").GetValue(obj, null) as string;
                        if (null == assemblyName)
                        {
                            assemblyName = assembly.FullName;
                        }

                        if (typeof(XamlCTask).Assembly.GetName().Name == assembly.GetName().Name)
                        {
                            continue;
                        }

                        string clrNamespace = definitionAttribute.GetProperty("ClrNamespace").GetValue(obj, null) as string;
                        string xmlNamespace = definitionAttribute.GetProperty("XmlNamespace").GetValue(obj, null) as string;

                        XmlnsDefinitionAttribute attribute = new XmlnsDefinitionAttribute(xmlNamespace, clrNamespace);
                        attribute.AssemblyName = assemblyName;
                        s_xmlnsDefinitions.Add(attribute);
                    }
                }
            }
            catch (Exception e)
            {
                int temp = 0;
            }
        }
示例#9
0
        private void addBehaviorClassToXmlElement(XElement behavior, List <XNamespace> namespaces, out List <XAttribute> additionalTagPrefixes)
        {
            additionalTagPrefixes = null;
            if (behavior == null)
            {
                return;
            }

            if (ClassImplementation != null)
            {
                XElement behaviorElement = new XElement(CLASS);
                behavior.Add(behaviorElement);

                Type behaviorType = ClassImplementation.GetType();
                XmlnsDefinitionAttribute defnAttribute = null;
                object[] attribs = behaviorType.Assembly.GetCustomAttributes(typeof(XmlnsDefinitionAttribute), false);
                if (attribs != null && attribs.Length > 0)
                {
                    defnAttribute = attribs[0] as XmlnsDefinitionAttribute;
                }

                string behaviorNamespace = behaviorType.Namespace;
                string namespaceMapping  = null;
                if (defnAttribute != null)
                {
                    namespaceMapping = defnAttribute.XmlNamespace;
                }
                else
                {
                    namespaceMapping = string.Format("clr-namespace:{0};assembly={1}", behaviorNamespace, behaviorType.Assembly.FullName.Split(',')[0]);
                }

                XNamespace namespaceForCommand = namespaces.FirstOrDefault <XNamespace>(x => x.NamespaceName == namespaceMapping);
                if (namespaceForCommand == null)
                {
                    namespaceForCommand = namespaceMapping;
                    string tagPrefix = behaviorNamespace.Replace('.', '_');

                    if (additionalTagPrefixes == null)
                    {
                        additionalTagPrefixes = new List <XAttribute>();
                    }

                    additionalTagPrefixes.Add(new XAttribute(XNamespace.Xmlns + tagPrefix, namespaceMapping));
                }

                XElement behaviorCommandImplElement = new XElement(namespaceForCommand + behaviorType.Name);
                behaviorElement.Add(behaviorCommandImplElement);

                ISupportsConfiguration supportsConfiguration = ClassImplementation as ISupportsConfiguration;
                if (supportsConfiguration != null)
                {
                    //string configData = null;
                    //try
                    //{
                    //    configData = supportsConfiguration.SaveConfiguration();
                    //}
                    //catch (Exception ex)
                    //{
                    //    Logger.Instance.LogError(ex);
                    //    OnBehaviorClassSaveConfigurationException(new ExceptionEventArgs(ex, null));
                    //}
                    if (!string.IsNullOrWhiteSpace(ConfigData))
                    {
                        ConfigData = ConfigData.Trim();
                        XElement configDataElement = new XElement(CONFIG_DATA);
                        if (ConfigData.StartsWith("<", StringComparison.Ordinal) && ConfigData.EndsWith(">", StringComparison.Ordinal))
                        {
                            try
                            {
                                XDocument xDoc = XDocument.Parse(ConfigData);
                                configDataElement.Add(xDoc.Root);
                            }
                            catch
                            {
                                configDataElement.Value = ConfigData;
                            }
                        }
                        else
                        {
                            configDataElement.Value = ConfigData;
                        }
                        behavior.Add(configDataElement);
                    }
                }
            }
        }