Пример #1
0
        /// <summary>
        /// Get licenses from resources embedded in the specified assembly. If assembly is null, licenses are loaded from the assembly containing the LicenseProvider implementation.
        /// </summary>
        /// <returns></returns>
        public List <ICreditInfo> GetCredits(Assembly assembly = null)
        {
            assembly = GetAssembly(assembly);
            List <Assembly> assemblies = new List <Assembly>();

            assemblies.Add(assembly);
            AssemblyName[] referencedAssemblies = assembly.GetReferencedAssemblies();
            foreach (var assemblyName in referencedAssemblies)
            {
                Assembly referencedAssembly = Assembly.Load(assemblyName);
                assemblies.Add(referencedAssembly);
            }
            List <ICreditInfo> credits = new List <ICreditInfo>();

            foreach (Assembly a in assemblies)
            {
                string[]          resourceNames    = a.GetManifestResourceNames();
                IEmbeddedResource embeddedResource = new EmbeddedResource();
                List <string>     resourceNameList = new List <string>(resourceNames.Length);
                resourceNameList.AddRange(resourceNames);
                resourceNameList.Sort();
                foreach (string resourceName in resourceNameList)
                {
                    if (resourceName.ToLower().EndsWith("credit.xml"))
                    {
                        using (Stream resourceStream = embeddedResource.ExtractToStream(resourceName, a))
                        {
                            try
                            {
                                var creditInfo = SerializerHelper <CreditInfo> .DeSerialize(resourceStream);

                                credits.Add(creditInfo);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Failed to deserialize embedded resource '{0}' in '{1}'. {2}",
                                                  resourceName, a.FullName, ex.Message);
                            }
                        }
                    }
                }
            }
            return(credits);
        }
Пример #2
0
    public static void Test()
    {
        MyRegex original = new MyRegex {
            Regex = "\\b[1-3]{1}\\b#Must be a value of 1 to 3"
        };
        string xml = SerializerHelper <MyRegex> .Serialize(original);

        Console.WriteLine("--- SERIALIZE ---");
        Console.WriteLine(xml);
        Console.WriteLine();
        Console.WriteLine();
        Console.WriteLine("--- DESERIALIZE ---");
        MyRegex deSerial = SerializerHelper <MyRegex> .DeSerialize(xml);

        Console.WriteLine("Equals? " + (deSerial.Regex.Equals(original.Regex)));
        Console.WriteLine();
        Console.WriteLine();
        Console.WriteLine("Console.ReadKey();");
        Console.ReadKey();
    }