public void WrongAssemblyNamesOK()
        {
            ResXDataNode node = GetNodeFileRefToIcon();

            AssemblyName [] ass = new AssemblyName [1];
            ass [0] = new AssemblyName("DummyAssembly");

            string name = node.GetValueTypeName(ass);

            Assert.AreEqual(typeof(Icon).AssemblyQualifiedName, name);
        }
        public void NullObjectReturnedFromResXGetValueTypeNameReturnsObject()
        {
            ResXDataNode node         = new ResXDataNode("aname", (object)null);
            ResXDataNode returnedNode = GetNodeFromResXReader(node);

            Assert.IsNotNull(returnedNode, "#A1");
            Assert.IsNull(returnedNode.GetValue((AssemblyName [])null), "#A2");
            string type = returnedNode.GetValueTypeName((AssemblyName [])null);

            Assert.AreEqual(typeof(object).AssemblyQualifiedName, type, "#A3");
        }
Ejemplo n.º 3
0
        public void InvalidMimeTypeAndType_WriteBack()
        {
            ResXDataNode node = GetNodeFromResXReader(typeconResXInvalidMimeTypeAndType);

            Assert.IsNotNull(node, "#A1");
            ResXDataNode returnedNode = GetNodeFromResXReader(node);

            Assert.IsNotNull(returnedNode, "#A2");
            string type = returnedNode.GetValueTypeName((AssemblyName [])null);

            Assert.AreEqual("A.type", type, "#A3");
        }
Ejemplo n.º 4
0
        public void WrongAssemblyNamesOK()
        {
            ResXDataNode node = GetNodeEmdeddedIcon();

            AssemblyName [] ass = new AssemblyName [1];

            ass [0] = new AssemblyName("System.Design");

            string name = node.GetValueTypeName(ass);

            Assert.AreEqual(typeof(Icon).AssemblyQualifiedName, name);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns true if given node contains value of type T.
        /// </summary>
        public static bool HasValue <T>(this ResXDataNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            string type    = node.GetValueTypeName((ITypeResolutionService)null);
            bool   hasType = !string.IsNullOrEmpty(type) && Type.GetType(type) == typeof(T);

            return(hasType);
        }
Ejemplo n.º 6
0
        public void AssemblyNameUsedWhereOnlyFullNameInResX()
        {
            // DummyAssembly must be in the same directory as current assembly to work correctly
            string aName = "DummyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null";

            AssemblyName [] assemblyNames = new AssemblyName [] { new AssemblyName(aName) };

            ResXDataNode node = GetNodeFromResXReader(convertableResXWithoutAssemblyName);

            Assert.IsNotNull(node, "#A1");
            string returnedType = node.GetValueTypeName(assemblyNames);

            Assert.AreEqual("DummyAssembly.Convertable, " + aName, returnedType, "#A2");
        }
Ejemplo n.º 7
0
        internal static CodeCompileUnit Create(IDictionary resourceList, String baseName, String generatedCodeNamespace, String resourcesNamespace, CodeDomProvider codeProvider, bool internalClass, out String[] unmatchable)
        {
            if (resourceList == null)
            {
                throw new ArgumentNullException("resourceList");
            }

            Dictionary <String, ResourceData> resourceTypes = new Dictionary <String, ResourceData>(StringComparer.InvariantCultureIgnoreCase);

            foreach (DictionaryEntry de in resourceList)
            {
                ResXDataNode node = de.Value as ResXDataNode;
                ResourceData data;
                if (node != null)
                {
                    string keyname = (string)de.Key;
                    if (keyname != node.Name)
                    {
                        throw new ArgumentException(SR.GetString(SR.MismatchedResourceName, keyname, node.Name));
                    }

                    String typeName      = node.GetValueTypeName((AssemblyName[])null);
                    Type   type          = Type.GetType(typeName);
                    String valueAsString = node.GetValue((AssemblyName[])null).ToString();
                    data = new ResourceData(type, valueAsString);
                }
                else
                {
                    // If the object is null, we don't have a good way of guessing the
                    // type.  Use Object.  This will be rare after WinForms gets away
                    // from their resource pull model in Whidbey M3.
                    Type type = (de.Value == null) ? typeof(Object) : de.Value.GetType();
                    data = new ResourceData(type, de.Value == null ? null : de.Value.ToString());
                }
                resourceTypes.Add((String)de.Key, data);
            }

            // Note we still need to verify the resource names are valid language
            // keywords, etc.  So there's no point to duplicating the code above.

            return(InternalCreate(resourceTypes, baseName, generatedCodeNamespace, resourcesNamespace, codeProvider, internalClass, out unmatchable));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Check if the entry contains a localizable string
        /// </summary>
        private static bool IsLocalizableString(string key, ResXDataNode dataNode)
        {
            if (key.StartsWith(">>") || (key.StartsWith("$") && key != "$this.Text"))
            {
                return(false);
            }

            if (dataNode == null)
            {
                return(false);
            }
            if (dataNode.FileRef != null)
            {
                return(false);
            }

            var valueType = dataNode.GetValueTypeName((ITypeResolutionService)null);

            return(valueType.StartsWith("System.String, "));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Reads the specified XML resource file and returns a sequence of <see cref="ResXData"/>.
        /// </summary>
        /// <param name="resxFile">The path of the file to read.</param>
        /// <returns>The sequence of <see cref="ResXData"/>.</returns>
        private static IEnumerable <ResXData> ReadResX(string resxFile)
        {
            using (ResXResourceReader reader = new ResXResourceReader(resxFile))
            {
                reader.BasePath = Path.GetDirectoryName(resxFile);

                reader.UseResXDataNodes = true;

                foreach (DictionaryEntry entry in reader)
                {
                    ResXDataNode node = (ResXDataNode)entry.Value;

                    Type type = Type.GetType(node.GetValueTypeName((AssemblyName[])null));
                    if (type == typeof(string))
                    {
                        string name  = entry.Key.ToString();
                        string value = node.GetValue((AssemblyName[])null).ToString();

                        yield return(new ResXData(name, value));
                    }
                }
            }
        }
        public static CodeCompileUnit Create(IDictionary resourceList, string baseName, string generatedCodeNamespace, string resourcesNamespace, CodeDomProvider codeProvider, bool internalClass, out string[] unmatchable)
        {
            if (resourceList == null)
            {
                throw new ArgumentNullException("resourceList");
            }
            Dictionary <string, ResourceData> dictionary = new Dictionary <string, ResourceData>(StringComparer.InvariantCultureIgnoreCase);

            foreach (DictionaryEntry entry in resourceList)
            {
                ResourceData data;
                ResXDataNode node = entry.Value as ResXDataNode;
                if (node != null)
                {
                    string key = (string)entry.Key;
                    if (key != node.Name)
                    {
                        throw new ArgumentException(System.Design.SR.GetString("MismatchedResourceName", new object[] { key, node.Name }));
                    }
                    Type   type = Type.GetType(node.GetValueTypeName((AssemblyName[])null));
                    string valueIfItWasAString = null;
                    if (type == typeof(string))
                    {
                        valueIfItWasAString = (string)node.GetValue((AssemblyName[])null);
                    }
                    data = new ResourceData(type, valueIfItWasAString);
                }
                else
                {
                    Type type2 = (entry.Value == null) ? typeof(object) : entry.Value.GetType();
                    data = new ResourceData(type2, entry.Value as string);
                }
                dictionary.Add((string)entry.Key, data);
            }
            return(InternalCreate(dictionary, baseName, generatedCodeNamespace, resourcesNamespace, codeProvider, internalClass, out unmatchable));
        }
        public ResxGenItem(ResXOptions options, ResXDataNode node)
        {
            Node    = node;
            Ignored = true;            //and clear upon complete...

            Options = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            Args    = new List <ResxGenArgument>();
            try
            {
                if (node.FileRef != null)
                {
                    return;
                }
                Type type = Type.GetType(node.GetValueTypeName(AllowedNames));
                if (type == null || type != typeof(String))
                {
                    return;
                }
                Value = (String)node.GetValue(AllowedNames);
            }
            catch { return; }

            MemberName = Identifier = StronglyTypedResourceBuilder.VerifyResourceName(node.Name, Csharp);
            FullName   = ItemName = node.Name;

            Comments = node.Comment;
            string rawArgs = null;

            IsFormatter = FormatingMatch.IsMatch(Value);
            IsException = ExceptionMatch.IsMatch(node.Name);
            //if (!IsFormatter && !IsException)
            //    return;

            int pos;

            if ((pos = ItemName.IndexOf('(')) > 0)
            {
                rawArgs    = ItemName.Substring(pos);
                ItemName   = ItemName.Substring(0, pos);
                MemberName = StronglyTypedResourceBuilder.VerifyResourceName(ItemName, Csharp);
            }
            else if (Comments.StartsWith("(") && (pos = Comments.IndexOf(')')) > 0)
            {
                rawArgs  = Comments.Substring(0, 1 + pos);
                Comments = Comments.Substring(pos + 1).Trim();
            }
            if (!String.IsNullOrEmpty(rawArgs))
            {
                Args.AddRange(new ResxGenArgParser(rawArgs));
            }

            //now thats out of the way... let's transform the format string into something usable:
            Value = StringUtils.Transform(Value, FormatingMatch,
                                          delegate(Match m)
            {
                return("{" + GetArg(null, m.Groups["field"].Value) + m.Groups["suffix"].Value + "}");
            }
                                          );

            if (Comments.StartsWith(":") && Comments.IndexOf("Exception") > 0)
            {
                IsException = true;
            }

            bool parsedOptions = ParseOptions(ref Comments);

            FacilityId = options.FacilityId;
            bool hasId = GetMessageIdForItem(out MessageId);

            hasId |= GetHResultForItem(out HResult);

            HasArguments = Args.Count > 0;
            if (HasArguments || IsFormatter || IsException || hasId)
            {
                Ignored = false;
                if (!parsedOptions)
                {
                    throw new ApplicationException(String.Format("Unable to parse comment options: '{0}'", Comments));
                }
            }
            AutoLog = hasId && MessageId != 0 && options.AutoLog && GetOption("log", true);
        }
Ejemplo n.º 12
0
 private static bool isStringNode(ResXDataNode node)
 {
     return(node.FileRef == null &&
            node.GetValueTypeName((ITypeResolutionService)null) == typeof(string).AssemblyQualifiedName);
 }
Ejemplo n.º 13
0
        public void NullObjectGetValueTypeNameIsNull()
        {
            ResXDataNode node = new ResXDataNode("aname", (object)null);

            Assert.IsNull(node.GetValueTypeName((AssemblyName [])null), "#A1");
        }