本文整理汇总了C#中this类的典型用法代码示例。如果您正苦于以下问题:C# this类的具体用法?C# this怎么用?C# this使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
this类属于命名空间,在下文中一共展示了this类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
}
开发者ID:Nearga,项目名称:Cimbalino-Phone-Toolkit,代码行数:12,代码来源:IntExtensions.cs
示例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);
}
开发者ID:juan2202,项目名称:LeagueSharp-Standalones,代码行数:7,代码来源:Extensions.cs
示例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();
}
开发者ID:jcoxhead,项目名称:SilverlightExamples,代码行数:26,代码来源:Md5Sum.cs
示例4: GetEntityType
public static Type GetEntityType(this Type type)
{
if (!type.IsCrudController()) return null;
var @interface = type.FindInterfaceThatCloses(typeof(CrudController<,>));
return @interface.GetGenericArguments()[0];
}
开发者ID:pjdennis,项目名称:fubumvc,代码行数:7,代码来源:CrudTypeExtensions.cs
示例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;
}
开发者ID:raminmjj,项目名称:SportsSystem,代码行数:27,代码来源:SecurityExtensions.cs
示例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("-------------------------------------------------------");
}
开发者ID:rdingwall,项目名称:mixplanner,代码行数:27,代码来源:MixExtensions.cs
示例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;
}
开发者ID:Andrea,项目名称:duality-withsvn-history,代码行数:7,代码来源:ExtMethodsMouseButtons.cs
示例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);
}
开发者ID:erashid,项目名称:Extensions,代码行数:14,代码来源:DateTimeOffsetExtension.cs
示例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);
}
开发者ID:d20021,项目名称:LiveSDK-for-Windows,代码行数:11,代码来源:StringBuilderExtension.cs
示例10: AddFromAssembly
public static IServiceCollection AddFromAssembly(this IServiceCollection serviceCollection, Assembly assembly)
{
var builder = new ServiceDescriptorsBuilder().AddSourceAssembly(assembly);
BuildAndFill(serviceCollection, builder);
return serviceCollection;
}
开发者ID:app-enhance,项目名称:ae-di,代码行数:7,代码来源:IServiceCollectionExtensions.cs
示例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);
}
开发者ID:vandenbergjp,项目名称:Simple.Web,代码行数:11,代码来源:StringHelpers.cs
示例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;
}
}
开发者ID:JackWangCUMT,项目名称:extensions,代码行数:29,代码来源:SmtpConfigurationLogic.cs
示例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;
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:33,代码来源:Helpers.cs
示例14: DeserializeObject
public static void DeserializeObject(this Stream stream, object obj, List<string> nameTable)
{
while (stream.Position < stream.Length)
{
stream.ReadAndMapProperty(obj, nameTable);
}
}
开发者ID:VakhtinAndrey,项目名称:lis-save-editor,代码行数:7,代码来源:StreamExtensions.cs
示例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));
}
开发者ID:Wronq,项目名称:RocknSpace,代码行数:11,代码来源:Extensions.cs
示例16: AppendEscapedXml
public static StringBuilder AppendEscapedXml(this StringBuilder builder, string value)
{
if (value == null) return builder;
builder.EnsureCapacity(builder.Length + value.Length + 10);
for (var i = 0; i < value.Length; i++)
{
switch (value[i])
{
case '&':
builder.Append("&");
break;
case '<':
builder.Append("<");
break;
case '>':
builder.Append(">");
break;
case '"':
builder.Append(""");
break;
case '\'':
builder.Append("'");
break;
default:
builder.Append(value[i]);
break;
}
}
return builder;
}
开发者ID:rneuber1,项目名称:InnovatorAdmin,代码行数:30,代码来源:XmlUtils.cs
示例17: GetInfoTooltip
public static UITextureAtlas GetInfoTooltip(this AssetManager assetManager, string infoTooltipName, string infoTooltipPath)
{
var infoTooltipAtlas = ScriptableObject.CreateInstance<UITextureAtlas>();
infoTooltipAtlas.padding = 0;
infoTooltipAtlas.name = infoTooltipName;
var shader = Shader.Find("UI/Default UI Shader");
if (shader != null) infoTooltipAtlas.material = new Material(shader);
var texture = assetManager.GetTexture(infoTooltipPath);
infoTooltipAtlas.material.mainTexture = texture;
const int ittW = 535;
const int ittH = 150;
var sprite = new UITextureAtlas.SpriteInfo
{
name = string.Format(infoTooltipName.ToUpper()),
region = new Rect(0f, 0f, 1f, 1f),
texture = new Texture2D(ittW, ittH, TextureFormat.ARGB32, false)
};
infoTooltipAtlas.AddSprite(sprite);
return infoTooltipAtlas;
}
开发者ID:primem0ver,项目名称:CSL.TransitAddonMod,代码行数:27,代码来源:AssetManagerExtensions.cs
示例18: AsIntermediary
public static IIntermediarySocket AsIntermediary(this EasyZMqConfigurer configurer, string backendAddress)
{
var frontendAddressBinder = configurer.AddressBinder;
var backendAddressBinder = new BindAddressBinder(new Uri(backendAddress));
return CreateIntermediarySocket(frontendAddressBinder, backendAddressBinder);
}
开发者ID:simonbaas,项目名称:EasyZMq,代码行数:7,代码来源:IntermediarySocketConfigurerExtension.cs
示例19: ActualMaxRange
/// <summary>
/// Returns maximum spell range based on hitbox of unit.
/// </summary>
/// <param name="spell"></param>
/// <param name="unit"></param>
/// <returns>Maximum spell range</returns>
public static float ActualMaxRange(this WoWSpell spell, WoWUnit unit)
{
if (spell.MaxRange == 0)
return 0;
// 0.3 margin for error
return unit != null ? spell.MaxRange + unit.CombatReach + 1f : spell.MaxRange;
}
开发者ID:Asphodan,项目名称:Alphabuddy,代码行数:13,代码来源:Spell.cs
示例20: GetIndex
public static Field.Index GetIndex(this IndexDefinition self, string name, Field.Index? defaultIndex)
{
if (self.Indexes == null)
return defaultIndex ?? Field.Index.ANALYZED_NO_NORMS;
FieldIndexing value;
if (self.Indexes.TryGetValue(name, out value) == false)
{
if (self.Indexes.TryGetValue(Constants.AllFields, out value) == false)
{
string ignored;
if (self.Analyzers.TryGetValue(name, out ignored) ||
self.Analyzers.TryGetValue(Constants.AllFields, out ignored))
{
return Field.Index.ANALYZED; // if there is a custom analyzer, the value should be analyzed
}
return defaultIndex ?? Field.Index.ANALYZED_NO_NORMS;
}
}
switch (value)
{
case FieldIndexing.No:
return Field.Index.NO;
case FieldIndexing.Analyzed:
return Field.Index.ANALYZED_NO_NORMS;
case FieldIndexing.NotAnalyzed:
return Field.Index.NOT_ANALYZED_NO_NORMS;
case FieldIndexing.Default:
return defaultIndex ?? Field.Index.ANALYZED_NO_NORMS;
default:
throw new ArgumentOutOfRangeException();
}
}
开发者ID:925coder,项目名称:ravendb,代码行数:32,代码来源:IndexingExtensions.cs
注:本文中的this类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论