本文整理汇总了C#中this类的典型用法代码示例。如果您正苦于以下问题:C# this类的具体用法?C# this怎么用?C# this使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
this类属于命名空间,在下文中一共展示了this类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Times
/// <summary>
/// Repeats the specified <see cref="Action"/> the number of times.
/// </summary>
/// <param name="input">The number of times to repeat the <see cref="Action"/>.</param>
/// <param name="action">The <see cref="Action"/> to repeat.</param>
public static void Times(this int input, Action action)
{
while (input-- > 0)
{
action();
}
}
示例2: GetTarget
public static Obj_AI_Hero GetTarget(this Spell spell,
bool ignoreShields = true,
Vector3 from = default(Vector3),
IEnumerable<Obj_AI_Hero> ignoredChampions = null)
{
return TargetSelector.GetTarget(spell, ignoreShields, from, ignoredChampions);
}
示例3: GetMd5Sum
// Create an md5 sum string of this string
public static string GetMd5Sum(this string str)
{
// First we need to convert the string into bytes, which
// means using a text encoder.
Encoder enc = System.Text.Encoding.Unicode.GetEncoder();
// Create a buffer large enough to hold the string
byte[] unicodeText = new byte[str.Length * 2];
enc.GetBytes(str.ToCharArray(), 0, str.Length, unicodeText, 0, true);
// Now that we have a byte array we can ask the CSP to hash it
MD5 md5 = new MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(unicodeText);
// Build the final string by converting each byte
// into hex and appending it to a StringBuilder
var sb = new StringBuilder();
for (int i = 0; i < result.Length; i++)
{
sb.Append(result[i].ToString("X2"));
}
// And return it
return sb.ToString();
}
示例4: GetEntityType
public static Type GetEntityType(this Type type)
{
if (!type.IsCrudController()) return null;
var @interface = type.FindInterfaceThatCloses(typeof(CrudController<,>));
return @interface.GetGenericArguments()[0];
}
示例5: Decrypt
public static string Decrypt(this string stringToDecrypt, string key)
{
if (string.IsNullOrEmpty(stringToDecrypt))
{
throw new ArgumentException("An empty string value cannot be encrypted.");
}
if (string.IsNullOrEmpty(key))
{
throw new ArgumentException("Cannot decrypt using an empty key. Please supply a decryption key.");
}
//var cspp = new CspParameters { KeyContainerName = key };
var cspp = new CspParameters { KeyContainerName = key, Flags = CspProviderFlags.UseMachineKeyStore };
var rsa = new RSACryptoServiceProvider(cspp) { PersistKeyInCsp = true };
var decryptArray = stringToDecrypt.Split(new[] { "-" }, StringSplitOptions.None);
var decryptByteArray = Array.ConvertAll(decryptArray, (s => Convert.ToByte(byte.Parse(s, System.Globalization.NumberStyles.HexNumber))));
byte[] bytes = rsa.Decrypt(decryptByteArray, true);
string result = System.Text.Encoding.UTF8.GetString(bytes);
return result;
}
示例6: Dump
public static void Dump(this IMix mix, string name = null)
{
Console.WriteLine("-------------------------------------------------------");
if (name != null)
{
Console.WriteLine(name);
Console.WriteLine("-------------------------------------------------------");
}
for (int i = 0; i < mix.Count; i++)
{
IMixItem item = mix[i];
Transition transition = item.Transition;
string strategy = transition.Strategy == null
? "<null strategy>"
: transition.Strategy.Description;
Console.WriteLine(">>> {0} --> {1} using {2}", transition.FromKey, transition.ToKey, strategy);
Console.WriteLine("{0}. {1}/{2:0.#}bpm {3}", i, item.ActualKey, item.ActualBpm, item.Track);
}
Console.WriteLine("{0} tracks total.", mix.Count);
Console.WriteLine("-------------------------------------------------------");
}
示例7: ToOpenTKSingle
public static MouseButton ToOpenTKSingle(this MouseButtons buttons)
{
if ((buttons & MouseButtons.Left) != MouseButtons.None) return MouseButton.Left;
else if ((buttons & MouseButtons.Right) != MouseButtons.None) return MouseButton.Right;
else if ((buttons & MouseButtons.Middle) != MouseButtons.None) return MouseButton.Middle;
else return MouseButton.LastButton;
}
示例8: SetTime
/// <summary>
/// Sets the time on the specified DateTime value using the specified time zone.
/// </summary>
/// <param name = "datetimeOff">The base date.</param>
/// <param name = "timespan">The TimeSpan to be applied.</param>
/// <param name = "localTimeZone">The local time zone.</param>
/// <returns>/// The DateTimeOffset including the new time value/// </returns>
public static DateTimeOffset SetTime(this DateTimeOffset datetimeOff, TimeSpan timespan,
TimeZoneInfo localTimeZone)
{
var localDate = datetimeOff.ToLocalDateTime(localTimeZone);
localDate.SetTime(timespan);
return localDate.ToDateTimeOffset(localTimeZone);
}
示例9: AppendQueryParam
/// <summary>
/// Appends key=value to the string.
/// Does not append ? or & before key=value.
/// </summary>
public static StringBuilder AppendQueryParam(this StringBuilder sb, string key, string value)
{
Debug.Assert(!string.IsNullOrWhiteSpace(key));
Debug.Assert(value != null);
return sb.Append(key).Append('=').Append(value);
}
示例10: AddFromAssembly
public static IServiceCollection AddFromAssembly(this IServiceCollection serviceCollection, Assembly assembly)
{
var builder = new ServiceDescriptorsBuilder().AddSourceAssembly(assembly);
BuildAndFill(serviceCollection, builder);
return serviceCollection;
}
示例11: SubstringBefore
/// <summary>
/// Return the substring up to but not including the first instance of 'c'.
/// If 'c' is not found, the entire string is returned.
/// </summary>
public static string SubstringBefore (this String src, char c) {
if (String.IsNullOrEmpty(src)) return "";
int idx = Math.Min(src.Length, src.IndexOf(c));
if (idx < 0) return src;
return src.Substring(0, idx);
}
示例12: GenerateSmtpClient
public static SmtpClient GenerateSmtpClient(this SmtpConfigurationEntity config)
{
if (config.DeliveryMethod != SmtpDeliveryMethod.Network)
{
return new SmtpClient
{
DeliveryFormat = config.DeliveryFormat,
DeliveryMethod = config.DeliveryMethod,
PickupDirectoryLocation = config.PickupDirectoryLocation,
};
}
else
{
SmtpClient client = EmailLogic.SafeSmtpClient(config.Network.Host, config.Network.Port);
client.DeliveryFormat = config.DeliveryFormat;
client.UseDefaultCredentials = config.Network.UseDefaultCredentials;
client.Credentials = config.Network.Username.HasText() ? new NetworkCredential(config.Network.Username, config.Network.Password) : null;
client.EnableSsl = config.Network.EnableSSL;
foreach (var cc in config.Network.ClientCertificationFiles)
{
client.ClientCertificates.Add(cc.CertFileType == CertFileType.CertFile ?
X509Certificate.CreateFromCertFile(cc.FullFilePath)
: X509Certificate.CreateFromSignedFile(cc.FullFilePath));
}
return client;
}
}
示例13: IsLegalSize
public static bool IsLegalSize(this int size, KeySizes[] legalSizes, out bool validatedByZeroSkipSizeKeySizes)
{
validatedByZeroSkipSizeKeySizes = false;
for (int i = 0; i < legalSizes.Length; i++)
{
KeySizes currentSizes = legalSizes[i];
// If a cipher has only one valid key size, MinSize == MaxSize and SkipSize will be 0
if (currentSizes.SkipSize == 0)
{
if (currentSizes.MinSize == size)
{
// Signal that we were validated by a 0-skipsize KeySizes entry. Needed to preserve a very obscure
// piece of back-compat behavior.
validatedByZeroSkipSizeKeySizes = true;
return true;
}
}
else if (size >= currentSizes.MinSize && size <= currentSizes.MaxSize)
{
// If the number is in range, check to see if it's a legal increment above MinSize
int delta = size - currentSizes.MinSize;
// While it would be unusual to see KeySizes { 10, 20, 5 } and { 11, 14, 1 }, it could happen.
// So don't return false just because this one doesn't match.
if (delta % currentSizes.SkipSize == 0)
{
return true;
}
}
}
return false;
}
示例14: DeserializeObject
public static void DeserializeObject(this Stream stream, object obj, List<string> nameTable)
{
while (stream.Position < stream.Length)
{
stream.ReadAndMapProperty(obj, nameTable);
}
}
示例15: return
/*public static float NextFloat(this Random rand, float maxValue = 1.0f, float minValue=0.0f)
{
return (float)rand.NextDouble() * (maxValue - minValue) + minValue;
}*/
public static Vector2 NextVector2(this Random rand, float maxLength = 1.0f, float minLength = 1.0f)
{
double theta = rand.NextDouble() * 2 * Math.PI;
float length = rand.NextFloat(minLength, maxLength);
return new Vector2(length * (float)Math.Cos(theta), length * (float)Math.Sin(theta));
}