当前位置: 首页>>代码示例>>C#>>正文


C# String.IsEmpty方法代码示例

本文整理汇总了C#中System.String.IsEmpty方法的典型用法代码示例。如果您正苦于以下问题:C# String.IsEmpty方法的具体用法?C# String.IsEmpty怎么用?C# String.IsEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.String的用法示例。


在下文中一共展示了String.IsEmpty方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Parse

      /// <summary>Parses the input JSON document into an output BPL object of the given expected type.</summary>
      public override bool Parse(String input, Type expectedType) {
         Clear();
         Input = input;
         if (input.IsEmpty()) {
            AddError("Input JSON string is empty.");
            return false;
         }
         var expectedClass = (expectedType != null ? BplClass.Get(expectedType) : null);
         if (expectedType != null && expectedClass == null) {
            AddError("Expected BPL class '{0}' is invalid.", expectedType);
            return false;
         }

         try {
            var inputJson = _tokenizeJson(input);
            var migrators = _customMigrators as IEnumerable<Func<Hashtable, bool>>;
            if (migrators == null && expectedClass != null) {
               migrators = expectedClass.JsonMigrationFunctions;
            }
            if (migrators != null) {
               foreach (var migrator in migrators) {
                  if (migrator(inputJson)) WasMigrated = true;
               }
            }
            return _parse(inputJson, expectedClass);
         } catch (Exception e) {
            AddException(e);
            return false;
         }

      }
开发者ID:borkaborka,项目名称:gmit,代码行数:32,代码来源:BplJsonParser.cs

示例2: GetSessionInternal

        private IClientSession GetSessionInternal(String sessionId, bool createIfNotExists)
        {
            sessionId = sessionId.HasValue() ? sessionId
                : (HttpContext.Current == null ? (string)ContextData.Get(CLIENT_SESSION_KEY)
                    : HttpContext.Current.Session[CLIENT_SESSION_KEY].AsString());

            if (sessionId.IsEmpty())
                sessionId = Guid.NewGuid().ToString("N").ToLower();

            IClientSession result = null;
            if (!_sessions.TryGetValue(sessionId, out result) && createIfNotExists)
            {
                lock (__lockObject)
                {
                    result = new ClientSession(sessionId, this);
                    if (HttpContext.Current == null)
                        ContextData.Set(CLIENT_SESSION_KEY, sessionId);
                    else
                        HttpContext.Current.Session[CLIENT_SESSION_KEY] = sessionId;
                    _sessions[sessionId] = result;
                }
            }
            else if (!result.isAlive)
                return GetSessionInternal(Guid.NewGuid().ToString("N").ToLower(), true);
            return result;
        }
开发者ID:christal1980,项目名称:wingsoa,代码行数:26,代码来源:ClientSessionManager.cs

示例3: FirstUpper

 public static String FirstUpper(String phrase)
 {
     if (!phrase.IsEmpty())
         return phrase.Substring(0, 1).ToUpper() + phrase.Substring(1);
     else
         return "";
 }
开发者ID:christal1980,项目名称:wingsoa,代码行数:7,代码来源:StringHelper.cs

示例4: About

 private void About(SqlTwitchUser speaker, String additionalText)
 {
     if (!additionalText.IsEmpty() && additionalText.Equals("sober")) {
         room.SendChatMessage("//TODO get quote from sober"); //I NEED SOMEETHING FROM YOU SOBER ~1am
     }
     else {
         room.SendChatMessage("Hi, I am HardlyBot! I am a chatbot designed to host card games. I am currently open source and made by HardlySober @ http://bit.ly/1LUViNe ");
     }
 }
开发者ID:1amnick,项目名称:HardlyBot,代码行数:9,代码来源:HelloCommand.cs

示例5: TimeMeOut

 private void TimeMeOut(SqlTwitchUser speaker, String time)
 {
     try {
         if (time.IsEmpty()) {
             room.SendChatMessage(".timeout " + speaker.userName + " " + Random.Uint.Between(1, 600));
         }
         else {
             room.SendChatMessage(".timeout " + speaker.userName + " " + Int32.Parse(time));
         }
     }
     catch (Exception) {
         //*do nothing ever i want this to be (somewhat)secret*//
     }
 }
开发者ID:1amnick,项目名称:HardlyBot,代码行数:14,代码来源:HelloCommand.cs

示例6: Parse

      /// <summary>Parses an input XML document into an output BPL object.</summary>
      public override bool Parse(String input) {
         Clear();
         Input = input;
         if (input.IsEmpty()) {
            AddError("Input XML string is empty");
            return false;
         }

         try {
            XDocument inputXml = null;
            using (var reader = XmlReader.Create(new StringReader(input), _getReaderSettings())) {
               inputXml = XDocument.Load(reader, PreserveErrorsInfo ? LoadOptions.SetLineInfo : LoadOptions.None);
            }
            var migrators = _customMigrators ?? _classMigrators;
            if (migrators != null) {
               foreach (var migrator in migrators) {
                  if (migrator(inputXml.Root)) WasMigrated = true;
               }
            }
            _mapping = new XmlNamespaceMap(inputXml);
            _resolver = new BplReferenceResolver();
            _resolver.CustomResolver = CustomResolver;

            if (inputXml.Root != null) {
               Output = _deserializeObject(inputXml.Root);
            }
            if (!Success) return false;

            if (ResolutionStrategy != BplResolutionStrategy.Manual) {
               var success = _resolver.Resolve();
               if (success || ResolutionStrategy == BplResolutionStrategy.Tolerant) {
                  Output.CompleteInitialization();
               } else {
                  foreach (var R in _resolver.Pending) {
                     AddError("Failed to resolve reference from '{0}' to '{1}' ('{2}' association).", R.Source, R.TargetId, R.Property.Name);
                  }
               }
            }
            Pending = _resolver.Pending;
            return true;
         } catch (Exception e) {
            AddException(e);
            return false;
         }
      }
开发者ID:borkaborka,项目名称:gmit,代码行数:46,代码来源:BplXmlParser.cs

示例7: Logon

        public ActionResult Logon(String usr, String pwd, String token, String fwd)
        {
            if (!token.IsEmpty())
                DecodeToken(token, ref usr, ref pwd, ref fwd);
            else if (usr.IsEmpty())
                return RedirectToAction("LoginView", new { fwd = fwd });
            var tokenDic = new Dictionary<String, String>();
            tokenDic["usr"] = usr.AsString();
            tokenDic["pwd"] = pwd.AsString();
            tokenDic["fwd"] = fwd.AsString();
            token = tokenDic.GetToken();

            var authService = ServiceLocator.GetInstance<IAuthenticationService>();
            var msg = "";
            if (!authService.PerformLogin(usr, pwd, out msg))
                return RedirectToAction("LoginError", new { token = token, msg = msg });
            return RedirectToAction("LoginSuccess", new { token = token });
        }
开发者ID:christal1980,项目名称:wingsoa,代码行数:18,代码来源:LoginController.cs

示例8: Parse

      /// <summary>Parses an input XML document into an output BPL object.</summary>
      public override bool Parse(String input) {
         Clear();
         Input = input;
         if (input.IsEmpty()) {
            Errors.AddError("Input HEX string is empty");
            return false;
         }

         try {
            var buffer = _fromHexString(Input);
            var reader = new BplBinaryReader(buffer);
            Output = reader.Deserialize();
            return true;
         } catch (Exception e) {
            Errors.AddException(e);
            return false;
         }
      }
开发者ID:borkaborka,项目名称:gmit,代码行数:19,代码来源:BplHexParser.cs

示例9: ReturnFalseIfNotEmpty

 public void ReturnFalseIfNotEmpty(String value)
 {
     Assert.False(value.IsEmpty());
 }
开发者ID:SparkSoftware,项目名称:infrastructure,代码行数:4,代码来源:StringExtensionTests.cs

示例10: Delete

        public override int Delete (String table, String whereClause, params String[] whereArgs)
        {
            Debug.Assert(!table.IsEmpty());

            var command = GetDeleteCommand(table, whereClause, whereArgs);

            var resultCount = -1;
            try {
                resultCount = command.ExecuteNonQuery ();
            } catch (Exception ex) {
                Log.E(Tag, "Error deleting from table " + table, ex);
            } finally {
                command.Dispose();
            }
            return resultCount;
        }
开发者ID:jonlipsky,项目名称:couchbase-lite-net,代码行数:16,代码来源:MonoSQLiteStorageEngine.cs

示例11: Update

        public override int Update (String table, ContentValues values, String whereClause, params String[] whereArgs)
        {
            Debug.Assert(!table.IsEmpty());
            Debug.Assert(values != null);

            var builder = new SqliteCommandBuilder();
            builder.SetAllValues = false;

            var command = GetUpdateCommand(table, values, whereClause, whereArgs);

            var resultCount = -1;
            try {
                resultCount = (Int32)command.ExecuteNonQuery ();
            } catch (Exception ex) {
                Log.E(Tag, "Error updating table " + table, ex);
            }
            return resultCount;
        }
开发者ID:jonlipsky,项目名称:couchbase-lite-net,代码行数:18,代码来源:MonoSQLiteStorageEngine.cs

示例12: IsEmpty

 public void IsEmpty(String source, Boolean expected)
 {
     Assert.Equal(expected, source.IsEmpty());
     Assert.NotEqual(expected, source.IsNotEmpty());
 }
开发者ID:JasonMing,项目名称:Nextension,代码行数:5,代码来源:StringExtensionsTests.cs

示例13: CommandLineConfig

        protected CommandLineConfig(String[] s_args)
        {
            Log = Logger.Get(GetType());
            Log.MinLevel = Level.Info;

            if (s_args.Count() == 1 && s_args[0] == "/?")
            {
                Banners.About();
                throw new ConfigException(String.Empty);
            }
            else
            {
                if (s_args.LastOrDefault() == "/verbose")
                {
                    IsVerbose = true;
                    s_args = s_args.SkipLast().ToArray();

                    Info.WriteLine("Detected the \"/verbose\" switch, entering verbose mode.");
                    Log.MinLevel = Level.Debug;

                    Debug.EnsureBlankLine();
                    Debug.Write("Command line args are: ");
                    if (s_args.IsEmpty()) Debug.WriteLine("empty");
                    else Debug.WriteLine("({0} arg{1})", s_args.Count(), s_args.Count() == 1 ? "" : "s");
                    s_args.ForEach((arg, i) => Debug.WriteLine("{0}: {1}", i + 1, arg));
                }

                Debug.EnsureBlankLine();
                Debug.WriteLine("Pre-parsing arguments...");
                var named_args = new Dictionary<String, String>();
                var shortcut_args = new List<String>();
                foreach (var s_arg in s_args)
                {
                    var m = s_arg.Parse("^-(?<name>.*?):(?<value>.*)$");
                    var name = m != null ? m["name"] : null;
                    var value = m != null ? m["value"] : s_arg;
                    if (m != null) Debug.WriteLine("Parsed \"{0}\" as name/value pair: {1} => \"{2}\".", s_arg, name, value);
                    else Debug.WriteLine("Parsed \"{0}\" as raw value.", s_arg);

                    if (name == null)
                    {
                        if (named_args.IsNotEmpty()) throw new ConfigException("Fatal error: shortcut arguments must be specified before named arguments.");
                        else shortcut_args.Add(value);
                    }
                    else
                    {
                        if (named_args.ContainsKey(name)) throw new ConfigException("Fatal error: duplicate argument \"{0}\".", name);
                        else named_args.Add(name, value);
                    }
                }
                Debug.WriteLine("Pre-parse completed: found {0} named argument{1} and {2} shortcut argument{3}.",
                    named_args.Count(), named_args.Count() == 1 ? "" : "s",
                    shortcut_args.Count(), shortcut_args.Count() == 1 ? "" : "s");

                Debug.EnsureBlankLine();
                Debug.WriteLine("Parsing arguments...");

                var parsed_args = new Dictionary<PropertyInfo, Object>();
                if (named_args.IsNotEmpty())
                {
                    Debug.WriteLine("Parsing named arguments...");
                    parsed_args = ParseArgs(named_args);
                }

                if (shortcut_args.IsNotEmpty())
                {
                    Debug.WriteLine("Parsing shortcut arguments...");

                    Dictionary<PropertyInfo, Object> parsed_shortcut_args = null;
                    var shortcuts = GetType().Attrs<ShortcutAttribute>().OrderBy(shortcut => shortcut.Priority);
                    var bind_errors = new Dictionary<String, String>();
                    foreach (var shortcut in shortcuts)
                    {
                        Debug.WriteLine("Considering shortcut schema \"{0}\"...", shortcut.Schema);
                        var words = shortcut.Schema.SplitWords();
                        if (words.Count() != shortcut_args.Count())
                        {
                            var message = String.Format("argument count mismatch.");
                            bind_errors.Add(shortcut.Schema, message);
                            Debug.WriteLine("Schema \"{0}\" won't work: {1}", shortcut.Schema, message);
                            continue;
                        }

                        try { parsed_shortcut_args = ParseArgs(words.Zip(shortcut_args).ToDictionary(t => t.Item1, t => t.Item2)); }
                        catch (ConfigException cex)
                        {
                            bind_errors.Add(shortcut.Schema, cex.Message);
                            Debug.WriteLine(cex.Message);
                            Debug.WriteLine("Schema \"{0}\" won't work: failed to parse arguments.", shortcut.Schema);

                            continue;
                        }

                        var dupes = Set.Intersect(parsed_args.Keys, parsed_shortcut_args.Keys);
                        if (dupes.IsNotEmpty())
                        {
                            var a = dupes.AssertFirst().Attr<ParamAttribute>();
                            var name = named_args.Keys.Single(k => a.Aliases.Contains(k));
                            Debug.WriteLine("Schema \"{0}\" won't work: shortcut argument duplicates parsed argument \"{1}\".", shortcut.Schema, name);
                            parsed_shortcut_args = null;
//.........这里部分代码省略.........
开发者ID:xeno-by,项目名称:xenogears,代码行数:101,代码来源:CommandLineConfig.cs

示例14: VerifyResult

        protected void VerifyResult(String s_expected, String s_actual)
        {
            (s_expected != null && s_actual != null).AssertTrue();
            s_expected = PreprocessReference(s_expected);
            s_actual = PreprocessResult(s_actual);

            var success = false;
            String failMsg = null;
            if (s_expected.IsEmpty())
            {
                Log.EnsureBlankLine();
                Log.WriteLine(s_actual);

                Assert.Fail(String.Format(
                    "Reference result for unit test '{1}' is empty.{0}" +
                    "Please, verify the trace dumped above and put in into the resource file.",
                    Environment.NewLine, UnitTest.CurrentTest.GetCSharpRef(ToCSharpOptions.Informative)));
            }
            else
            {
                var expected = s_expected.SplitLines();
                var actual = s_actual.SplitLines();
                if (expected.Count() != actual.Count())
                {
                    success = false;
                    failMsg = String.Format(
                        "Number of lines doesn't match. Expected {0}, actually found {1}" + Environment.NewLine,
                        expected.Count(), actual.Count());
                }
                else
                {
                    success = expected.Zip(actual).SkipWhile((t, i) =>
                    {
                        if (t.Item1 != t.Item2)
                        {
                            var maxLines = Math.Max(actual.Count(), expected.Count());
                            var maxDigits = (int)Math.Floor(Math.Log10(maxLines)) + 1;
                            failMsg = String.Format(
                                "Line {1} (starting from 1) doesn't match.{0}{4}{2}{0}{5}{3}",
                                Environment.NewLine, i + 1,
                                t.Item1.Replace(" ", "·"), t.Item2.Replace(" ", "·"),
                                "E:".PadRight(maxDigits + 3), "A:".PadRight(maxDigits + 3));
                            return false;
                        }
                        else
                        {
                            return true;
                        }
                    }).IsEmpty();
                }

                if (!success)
                {
                    var maxLines = Math.Max(actual.Count(), expected.Count());
                    var maxDigits = (int)Math.Floor(Math.Log10(maxLines + 1)) + 1;
                    var maxActual = Math.Max(actual.MaxOrDefault(line => line.Length), "Actual".Length);
                    var maxExpected = Math.Max(expected.MaxOrDefault(line => line.Length), "Expected".Length);
                    var total = maxDigits + 3 + maxActual + 3 + maxExpected;

                    Log.EnsureBlankLine();
                    Log.WriteLine(String.Format("{0} | {1} | {2}",
                        "N".PadRight(maxDigits),
                        "Actual".PadRight(maxActual),
                        "Expected".PadRight(maxExpected)));
                    Log.WriteLine(total.Times("-"));

                    0.UpTo(maxLines - 1).ForEach(i =>
                    {
                        var l_actual = actual.ElementAtOrDefault(i, String.Empty);
                        var l_expected = expected.ElementAtOrDefault(i, String.Empty);
                        Log.WriteLine(String.Format("{0} | {1} | {2}",
                            (i + 1).ToString().PadLeft(maxDigits),
                            l_actual.PadRight(maxActual),
                            l_expected.PadRight(maxExpected)));
                    });

                    Log.EnsureBlankLine();
                    Log.WriteLine(failMsg);
                    Assert.Fail("Actual result doesn't match expected result.");
                }
            }
        }
开发者ID:xeno-by,项目名称:xenogears,代码行数:82,代码来源:BaseTests.cs


注:本文中的System.String.IsEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。