本文整理汇总了C#中IType.IsKnownType方法的典型用法代码示例。如果您正苦于以下问题:C# IType.IsKnownType方法的具体用法?C# IType.IsKnownType怎么用?C# IType.IsKnownType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IType
的用法示例。
在下文中一共展示了IType.IsKnownType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDefaultFieldValue
public static object GetDefaultFieldValue(IType type)
{
if (type.IsKnownType(KnownTypeCode.Int16) ||
type.IsKnownType(KnownTypeCode.Int32) ||
type.IsKnownType(KnownTypeCode.Int64) ||
type.IsKnownType(KnownTypeCode.UInt16) ||
type.IsKnownType(KnownTypeCode.UInt32) ||
type.IsKnownType(KnownTypeCode.UInt64) ||
type.IsKnownType(KnownTypeCode.Byte) ||
type.IsKnownType(KnownTypeCode.Double) ||
type.IsKnownType(KnownTypeCode.Decimal) ||
type.IsKnownType(KnownTypeCode.SByte) ||
type.IsKnownType(KnownTypeCode.Single) ||
type.IsKnownType(KnownTypeCode.Enum))
{
return 0;
}
if (NullableType.IsNullable(type))
{
return null;
}
if (type.IsKnownType(KnownTypeCode.Boolean))
{
return false;
}
if (type.Kind == TypeKind.Struct)
{
return type;
}
return null;
}
示例2: CheckTargetedObject
void CheckTargetedObject(InvocationExpression invocationExpression, IType type, IMember member)
{
var memberExpression = invocationExpression.Target as MemberReferenceExpression;
if (memberExpression != null) {
if (type.IsKnownType(KnownTypeCode.String) && member.Name == "ToString") {
AddRedundantToStringIssue(memberExpression, invocationExpression);
}
}
}
示例3: Upcast
public JsExpression Upcast(JsExpression expression, IType sourceType, IType targetType)
{
if (sourceType.IsKnownType(KnownTypeCode.Char))
_errorReporter.Message(7700);
return expression;
}
示例4: Downcast
public JsExpression Downcast(JsExpression expression, IType sourceType, IType targetType)
{
if (_metadataImporter.OmitDowncasts)
return expression;
if (sourceType.Kind == TypeKind.Dynamic && targetType.IsKnownType(KnownTypeCode.Boolean))
return JsExpression.LogicalNot(JsExpression.LogicalNot(expression));
var jsTarget = GetCastTarget(sourceType, targetType);
if (jsTarget == null || IsSystemObjectReference(jsTarget))
return expression;
return JsExpression.Invocation(JsExpression.Member(_createTypeReferenceExpression(KnownTypeReference.Type), "cast"), expression, jsTarget);
}
示例5: ToTypeScriptName
public static string ToTypeScriptName(IType type, IEmitter emitter, bool asDefinition = false, bool excludens = false, bool ignoreDependency = false)
{
if (type.Kind == TypeKind.Delegate)
{
var method = type.GetDelegateInvokeMethod();
StringBuilder sb = new StringBuilder();
sb.Append("{");
sb.Append("(");
var last = method.Parameters.LastOrDefault();
foreach (var p in method.Parameters)
{
var ptype = BridgeTypes.ToTypeScriptName(p.Type, emitter);
if (p.IsOut || p.IsRef)
{
ptype = "{v: " + ptype + "}";
}
sb.Append(p.Name + ": " + ptype);
if (p != last)
{
sb.Append(", ");
}
}
sb.Append(")");
sb.Append(": ");
sb.Append(BridgeTypes.ToTypeScriptName(method.ReturnType, emitter));
sb.Append("}");
return sb.ToString();
}
if (type.IsKnownType(KnownTypeCode.String))
{
return "string";
}
if (type.IsKnownType(KnownTypeCode.Boolean))
{
return "boolean";
}
if (type.IsKnownType(KnownTypeCode.Void))
{
return "void";
}
if (type.IsKnownType(KnownTypeCode.Byte) ||
type.IsKnownType(KnownTypeCode.Char) ||
type.IsKnownType(KnownTypeCode.Decimal) ||
type.IsKnownType(KnownTypeCode.Double) ||
type.IsKnownType(KnownTypeCode.Int16) ||
type.IsKnownType(KnownTypeCode.Int32) ||
type.IsKnownType(KnownTypeCode.Int64) ||
type.IsKnownType(KnownTypeCode.SByte) ||
type.IsKnownType(KnownTypeCode.Single) ||
type.IsKnownType(KnownTypeCode.UInt16) ||
type.IsKnownType(KnownTypeCode.UInt32) ||
type.IsKnownType(KnownTypeCode.UInt64))
{
return "number";
}
if (type.Kind == TypeKind.Array)
{
ICSharpCode.NRefactory.TypeSystem.ArrayType arrayType = (ICSharpCode.NRefactory.TypeSystem.ArrayType)type;
return BridgeTypes.ToTypeScriptName(arrayType.ElementType, emitter, asDefinition, excludens) + "[]";
}
if (type.Kind == TypeKind.Dynamic)
{
return "any";
}
if (type.Kind == TypeKind.Enum && type.DeclaringType != null && !excludens)
{
return "number";
}
if (NullableType.IsNullable(type))
{
return BridgeTypes.ToTypeScriptName(NullableType.GetUnderlyingType(type), emitter, asDefinition, excludens);
}
BridgeType bridgeType = emitter.BridgeTypes.Get(type, true);
//string name = BridgeTypes.ConvertName(excludens ? type.Name : type.FullName);
var name = excludens ? "" : type.Namespace;
var hasTypeDef = bridgeType != null && bridgeType.TypeDefinition != null;
if (hasTypeDef)
{
var typeDef = bridgeType.TypeDefinition;
if (typeDef.IsNested && !excludens)
{
name = (string.IsNullOrEmpty(name) ? "" : (name + ".")) + BridgeTypes.GetParentNames(typeDef);
}
//.........这里部分代码省略.........
示例6: IsIntegerType
public static bool IsIntegerType(IType type, IMemberResolver resolver)
{
type = type.IsKnownType(KnownTypeCode.NullableOfT) ? ((ParameterizedType)type).TypeArguments[0] : type;
return type.Equals(resolver.Compilation.FindType(KnownTypeCode.Byte))
|| type.Equals(resolver.Compilation.FindType(KnownTypeCode.SByte))
|| type.Equals(resolver.Compilation.FindType(KnownTypeCode.Char))
|| type.Equals(resolver.Compilation.FindType(KnownTypeCode.Int16))
|| type.Equals(resolver.Compilation.FindType(KnownTypeCode.UInt16))
|| type.Equals(resolver.Compilation.FindType(KnownTypeCode.Int32))
|| type.Equals(resolver.Compilation.FindType(KnownTypeCode.UInt32))
|| type.Equals(resolver.Compilation.FindType(KnownTypeCode.Int64))
|| type.Equals(resolver.Compilation.FindType(KnownTypeCode.UInt64));
}
示例7: IsFloatType
public static bool IsFloatType(IType type, IMemberResolver resolver)
{
type = type.IsKnownType(KnownTypeCode.NullableOfT) ? ((ParameterizedType)type).TypeArguments[0] : type;
return type.Equals(resolver.Compilation.FindType(KnownTypeCode.Decimal))
|| type.Equals(resolver.Compilation.FindType(KnownTypeCode.Double))
|| type.Equals(resolver.Compilation.FindType(KnownTypeCode.Single));
}
示例8: TryConvertEnum
/// <summary>
///
/// </summary>
/// <param name="rr">The input resolve result that should be converted.
/// If a conversion exists, it is applied to the resolve result</param>
/// <param name="targetType">The target type that we should convert to</param>
/// <param name="isNullable">Whether we are dealing with a lifted operator</param>
/// <param name="enumRR">The resolve result that is enum-typed.
/// If necessary, a nullable conversion is applied.</param>
/// <param name="allowConversionFromConstantZero">
/// Whether the conversion from the constant zero is allowed.
/// </param>
/// <returns>True if the conversion is successful; false otherwise.
/// If the conversion is not successful, the ref parameters will not be modified.</returns>
bool TryConvertEnum(ref ResolveResult rr, IType targetType, ref bool isNullable, ref ResolveResult enumRR, bool allowConversionFromConstantZero = true)
{
Conversion c;
if (!isNullable) {
// Try non-nullable
c = conversions.ImplicitConversion(rr, targetType);
if (c.IsValid && (allowConversionFromConstantZero || !c.IsEnumerationConversion)) {
rr = Convert(rr, targetType, c);
return true;
}
}
// make targetType nullable if it isn't already:
if (!targetType.IsKnownType(KnownTypeCode.NullableOfT))
targetType = NullableType.Create(compilation, targetType);
c = conversions.ImplicitConversion(rr, targetType);
if (c.IsValid && (allowConversionFromConstantZero || !c.IsEnumerationConversion)) {
rr = Convert(rr, targetType, c);
isNullable = true;
// Also convert the enum-typed RR to nullable, if it isn't already
if (!enumRR.Type.IsKnownType(KnownTypeCode.NullableOfT)) {
var nullableType = NullableType.Create(compilation, enumRR.Type);
enumRR = new ConversionResolveResult(nullableType, enumRR, Conversion.ImplicitNullableConversion);
}
return true;
}
return false;
}
示例9: ToJavascriptName
public static string ToJavascriptName(IType type, IEmitter emitter)
{
if (type.Kind == TypeKind.Delegate)
{
var delegateName = BridgeTypes.ConvertName(type.FullName);
if (!emitter.JsDoc.Callbacks.Contains(delegateName))
{
var method = type.GetDelegateInvokeMethod();
JsDocComment comment = new JsDocComment();
var parameters = method.Parameters;
if (parameters != null && parameters.Count > 0)
{
foreach (var param in parameters)
{
var jsParam = new JsDocParam();
jsParam.Name = param.Name;
jsParam.Type = XmlToJsDoc.ToJavascriptName(param.Type, emitter);
comment.Parameters.Add(jsParam);
}
}
comment.Returns.Add(new JsDocParam
{
Type = XmlToJsDoc.ToJavascriptName(method.ReturnType, emitter)
});
comment.Callback = delegateName;
comment.MemberOf = type.Namespace;
if (!emitter.JsDoc.Namespaces.Contains(type.Namespace))
{
emitter.JsDoc.Namespaces.Add(type.Namespace);
comment.Namespace = type.Namespace;
}
emitter.JsDoc.Callbacks.Add(delegateName);
emitter.Output.Insert(0, comment.ToString() + newLine + newLine);
}
return delegateName;
}
if (type.IsKnownType(KnownTypeCode.String))
{
return "string";
}
if (type.IsKnownType(KnownTypeCode.Boolean))
{
return "boolean";
}
if (type.IsKnownType(KnownTypeCode.Void))
{
return "void";
}
if (type.IsKnownType(KnownTypeCode.Byte) ||
type.IsKnownType(KnownTypeCode.Char) ||
type.IsKnownType(KnownTypeCode.Decimal) ||
type.IsKnownType(KnownTypeCode.Double) ||
type.IsKnownType(KnownTypeCode.Int16) ||
type.IsKnownType(KnownTypeCode.Int32) ||
type.IsKnownType(KnownTypeCode.Int64) ||
type.IsKnownType(KnownTypeCode.SByte) ||
type.IsKnownType(KnownTypeCode.Single) ||
type.IsKnownType(KnownTypeCode.UInt16) ||
type.IsKnownType(KnownTypeCode.UInt32) ||
type.IsKnownType(KnownTypeCode.UInt64))
{
return "number";
}
if (type.Kind == TypeKind.Array)
{
ICSharpCode.NRefactory.TypeSystem.ArrayType arrayType = (ICSharpCode.NRefactory.TypeSystem.ArrayType)type;
return "Array.<" + XmlToJsDoc.ToJavascriptName(arrayType.ElementType, emitter) + ">";
}
if (type.Kind == TypeKind.Dynamic)
{
return "object";
}
if (type.Kind == TypeKind.Enum && type.DeclaringType != null)
{
return "number";
}
if (NullableType.IsNullable(type))
{
return "?" + XmlToJsDoc.ToJavascriptName(NullableType.GetUnderlyingType(type), emitter);
}
BridgeType bridgeType = emitter.BridgeTypes.Get(type, true);
//string name = BridgeTypes.ConvertName(type.FullName);
//.........这里部分代码省略.........
示例10: Default
public JsExpression Default(IType type, IRuntimeContext context) {
if (type.IsReferenceType == true || type.Kind == TypeKind.Dynamic || type.IsKnownType(KnownTypeCode.NullableOfT)) {
return JsExpression.Null;
}
else if (type.Kind == TypeKind.Enum) {
return MetadataUtils.IsNamedValues(type.GetDefinition(), _attributeStore) ? JsExpression.Null : JsExpression.Number(0);
}
else if (type is ITypeDefinition) {
switch (((ITypeDefinition)type).KnownTypeCode) {
case KnownTypeCode.Boolean:
return JsExpression.False;
case KnownTypeCode.NullableOfT:
return JsExpression.Null;
case KnownTypeCode.DateTime:
return JsExpression.New(CreateTypeReferenceExpression(KnownTypeReference.DateTime), JsExpression.Number(0));
case KnownTypeCode.Byte:
case KnownTypeCode.SByte:
case KnownTypeCode.Char:
case KnownTypeCode.Int16:
case KnownTypeCode.UInt16:
case KnownTypeCode.Int32:
case KnownTypeCode.UInt32:
case KnownTypeCode.Int64:
case KnownTypeCode.UInt64:
case KnownTypeCode.Decimal:
case KnownTypeCode.Single:
case KnownTypeCode.Double:
return JsExpression.Number(0);
}
}
return JsExpression.Invocation(JsExpression.Member(CreateTypeReferenceExpression(_systemScript), "getDefaultValue"), GetScriptType(type, TypeContext.GetScriptType, context));
}
示例11: Downcast
public JsExpression Downcast(JsExpression expression, IType sourceType, IType targetType, IRuntimeContext context) {
if (_omitDowncasts)
return expression;
if (sourceType.Kind == TypeKind.Dynamic && targetType.IsKnownType(KnownTypeCode.Boolean))
return JsExpression.LogicalNot(JsExpression.LogicalNot(expression));
JsExpression jsTarget = CompileImportedTypeCheckCode(targetType, ref expression, context, false);
if (jsTarget == null)
jsTarget = GetCastTarget(sourceType, targetType, context);
if (jsTarget == null || IsSystemObjectReference(jsTarget))
return expression;
return JsExpression.Invocation(JsExpression.Member(CreateTypeReferenceExpression(_systemScript), "cast"), expression, jsTarget);
}
示例12: IsDecimalType
public static bool IsDecimalType(IType type, IMemberResolver resolver, bool allowArray = false)
{
if (allowArray && type.Kind == TypeKind.Array)
{
var elements = (TypeWithElementType)type;
type = elements.ElementType;
}
type = type.IsKnownType(KnownTypeCode.NullableOfT) ? ((ParameterizedType)type).TypeArguments[0] : type;
return type.Equals(resolver.Compilation.FindType(KnownTypeCode.Decimal));
}
示例13: CompileMethod
public JsFunctionDefinitionExpression CompileMethod(IList<IParameter> parameters, IDictionary<IVariable, VariableData> variables, Expression body, IType returnType, bool staticMethodWithThisAsFirstArgument, bool expandParams, StateMachineType stateMachineType, IType iteratorBlockYieldTypeOrAsyncTaskGenericArgument = null) {
SetRegion(body.Region);
return CompileMethod(parameters, variables, staticMethodWithThisAsFirstArgument, expandParams, stateMachineType, iteratorBlockYieldTypeOrAsyncTaskGenericArgument, () => {
bool hasReturnValue = !returnType.IsKnownType(KnownTypeCode.Void);
var rr = _resolver.Resolve(body);
if (hasReturnValue) {
var conversion = CSharpConversions.Get(_compilation).ImplicitConversion(rr, returnType);
if (!conversion.IsValid)
_errorReporter.InternalError("No implicit conversion found from " + rr.Type + " to " + returnType);
else if (!conversion.IsIdentityConversion)
rr = new ConversionResolveResult(returnType, rr, conversion);
}
if (!IsInvocationOfRemovedMethod(rr)) {
var compiled = _expressionCompiler.Compile(rr, hasReturnValue);
_result.AddRange(compiled.AdditionalStatements);
if (hasReturnValue) {
JsExpression result = compiled.Expression;
if (IsMutableValueType(returnType)) {
result = MaybeCloneValueType(result, rr, rr.Type);
}
_result.Add(JsStatement.Return(result));
}
else if (compiled.Expression.NodeType != ExpressionNodeType.Null) // The statement "null;" is illegal in C#, so it must have appeared because there was no suitable expression to return.
_result.Add(compiled.Expression);
}
});
}
示例14: GetClassType
global::EnvDTE.vsCMTypeRef GetClassType(IType type)
{
if (type.IsKnownType(KnownTypeCode.String)) {
return global::EnvDTE.vsCMTypeRef.vsCMTypeRefString;
} else if (type.IsKnownType(KnownTypeCode.Object)) {
return global::EnvDTE.vsCMTypeRef.vsCMTypeRefObject;
} else {
return global::EnvDTE.vsCMTypeRef.vsCMTypeRefCodeType;
}
}
示例15: GetStructDefaultValue
public static string GetStructDefaultValue(IType type, IEmitter emitter)
{
if (type.IsKnownType(KnownTypeCode.DateTime))
{
return "new Date(-864e13)";
}
return "new " + BridgeTypes.ToJsName(type, emitter) + "()";
}