本文整理汇总了C#中StringType类的典型用法代码示例。如果您正苦于以下问题:C# StringType类的具体用法?C# StringType怎么用?C# StringType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringType类属于命名空间,在下文中一共展示了StringType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateRandomString
/// <summary>
/// Generate a random string of characters
/// </summary>
/// <param name="length">length of string</param>
/// <param name="type">type of string to be generated</param>
/// <returns></returns>
public static string GenerateRandomString(int length, StringType type)
{
switch (type)
{
case StringType.AlphaNumeric:
string allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
char[] chars = new char[length];
Random rd = new Random();
for (int i = 0; i < length; i++)
{
chars[i] = allowedChars[rd.Next(0, allowedChars.Length)];
}
return new string(chars);
break;
case StringType.AlphaNumericSymbol:
//Generate a cryptographic random number.
var rng = new RNGCryptoServiceProvider();
var buff = new byte[length];
rng.GetBytes(buff);
rng.Dispose();
// Return a Base64 string representation of the random number.
return Convert.ToBase64String(buff);
break;
default:
throw new ArgumentException("Type not supported");
}
}
示例2: ShouldDecodeLongString
public virtual void ShouldDecodeLongString()
{
var stringType = new StringType();
var longString = "MonkeyVeryLongStringmljalkdjflksjf lkdfjlsfjalkfjlsflskfjlsflsfjasdfjlsjflksfjlskjf fjlskfjlsjfs fkj lakdflsjfsa fafd sa";
var result = stringType.Encode(longString);
Assert.Equal(longString, stringType.Decode<string>(result));
}
示例3: Validate
/// <summary>
/// Validates given string for the given type.
/// </summary>
/// <param name="stringToValidate"> string to be validated. </param>
/// <param name="type"> Type of the string. </param>
/// <returns> True if string validates the required parameter </returns>
public static bool Validate(string stringToValidate, StringType type)
{
if (null == stringToValidate)
{
ExceptionManager.Throw(new ArgumentNullException("stringToValidate"));
}
bool result = false;
switch (type)
{
case StringType.Name:
result = ValidateName(stringToValidate);
break;
case StringType.EmailAddress:
result = ValidateEmailAddress(stringToValidate);
break;
case StringType.Address:
break;
case StringType.Password:
result = ValidatePassword(stringToValidate);
break;
default:
ExceptionManager.Throw(new ArgumentOutOfRangeException("type"));
break;
}
return result;
}
示例4: CertStrToName
internal extern static bool CertStrToName(CertEncodingType dwCertEncodingType,
[MarshalAs(UnmanagedType.LPWStr)]string pszX500,
StringType dwStrType,
IntPtr pvReserved,
byte[] pbEncoded,
[In, Out]ref int pcbEncoded,
[MarshalAs(UnmanagedType.LPWStr)]ref StringBuilder ppszError);
示例5: UnsynchronisedLyricsFrame
public UnsynchronisedLyricsFrame(string description, string language, StringType encoding) : base(FrameType.USLT, 4)
{
this.encoding = TagLib.Id3v2.Tag.DefaultEncoding;
this.encoding = encoding;
this.language = language;
this.description = description;
}
示例6: StringData
public StringData(string name, uint offset, uint address, StringType type, string value, int size, uint pluginLine)
: base(name, offset, address, pluginLine)
{
_value = value;
_size = size;
_type = type;
}
示例7: CommentsFrame
public CommentsFrame(string description, string language, StringType encoding) : base(FrameType.COMM, 4)
{
this.encoding = TagLib.Id3v2.Tag.DefaultEncoding;
this.encoding = encoding;
this.language = language;
this.description = description;
}
示例8: SynchronisedLyricsFrame
public SynchronisedLyricsFrame (string description, string language, SynchedTextType type, StringType encoding) : base (FrameType.SYLT, 4)
{
this.text_encoding = encoding;
this.language = language;
this.description = description;
this.lyrics_type = type;
}
示例9: ParseCommentsFields
private void ParseCommentsFields(ByteVector data)
{
if (data.Count < 5)
{
TagLibDebugger.Debug("A comment frame must contain at least 5 bytes.");
return;
}
textEncoding = (StringType)data[0];
language = data.Mid(1, 3);
int byte_align = textEncoding == StringType.Latin1 || textEncoding == StringType.UTF8 ? 1 : 2;
ByteVectorCollection l = ByteVectorCollection.Split(data.Mid(4), TextDelimiter(textEncoding), byte_align, 2);
if (l.Count == 2)
{
if (l[0].Data != null && l[0].Data.Count > 0)
description = l[0].ToString(textEncoding);
else description = string.Empty;
if (l[1].Data != null && l[1].Data.Count > 0)
text = l[1].ToString(textEncoding);
else text = string.Empty;
}
}
示例10: Id3v2CommentsFrame
public Id3v2CommentsFrame(StringType encoding) : base("COMM")
{
textEncoding = encoding;
//language = null;
//fields = null;
//type = null;
}
示例11: FindStrings
public IEnumerable<ProgramAddress> FindStrings(StringType stringType, int minLength)
{
foreach (var segment in program.ImageMap.Segments.Values)
{
Address segEnd = segment.Address + segment.Size;
var rdr = program.Architecture.CreateImageReader(program.Image, segment.Address);
Address addrStartRun = null;
int cValid = 0;
while (rdr.Address < segEnd)
{
byte ch = rdr.ReadByte();
if (!IsValid((char)ch))
{
if (ch == 0 && cValid >= minLength)
{
yield return new ProgramAddress(program, addrStartRun);
}
addrStartRun = null;
cValid = 0;
}
else
{
if (addrStartRun == null)
addrStartRun = rdr.Address - 1;
++cValid;
}
}
}
}
示例12: CorrectEncoding
protected static StringType CorrectEncoding(StringType type, byte version)
{
if (TagLib.Id3v2.Tag.ForceDefaultEncoding)
{
type = TagLib.Id3v2.Tag.DefaultEncoding;
}
return (((version >= 4) || (type != StringType.UTF8)) ? type : StringType.UTF16);
}
示例13: StringContentTokenizer
public StringContentTokenizer(StringType properties, char terminator, char openingParenthesis) {
Debug.Assert(!Tokenizer.IsLetterOrDigit(terminator));
_properties = properties;
_terminator = terminator;
_openingParenthesis = openingParenthesis;
_nestingLevel = 0;
}
示例14: StringFeatureAttribute
public StringFeatureAttribute(StringType splitType, string separator = " ", string exclusions = null)
{
SplitType = splitType;
Separator = separator;
ExclusionFile = exclusions;
CalculateExclusions();
}
示例15: WriteTomlStrings
public void WriteTomlStrings(StringType s, string expected)
{
// Act
var written = Toml.WriteString(s);
// Assert
Assert.Equal(expected, written.Trim());
}